From c846adcb14e359d9ace770d1f9c4d9dda39aa628 Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Tue, 17 Mar 2020 12:54:44 +0100 Subject: [PATCH 1/6] =?UTF-8?q?referat=20fra=20m=C3=B8te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/team/referater/referat_17_03_2020.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/team/referater/referat_17_03_2020.md diff --git a/docs/team/referater/referat_17_03_2020.md b/docs/team/referater/referat_17_03_2020.md new file mode 100644 index 0000000..5968561 --- /dev/null +++ b/docs/team/referater/referat_17_03_2020.md @@ -0,0 +1,17 @@ +## Oppmøte +Tilstede: Steinar, Gabriel, Kristian, Torbjørn, Petter +Ikke tilstede: + +## Agenda +- Design valg + +- Brukerhistorier + +- Fordele Oppgaver + +## Møte +- Diskuterer spørmsål vi vil sende inn the "kunden" angående innlevering/vurdering. + +- Sett på og reflektert rundt multiplayer finksjonaliteten. + +- Prøvd å få gruppen på samme nivå abgående forståelse rundt utfordringer med nettverk. \ No newline at end of file From fbd7bef642f1ab5e7b71fa0ad0bc5595836d66f7 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 17 Mar 2020 12:57:50 +0100 Subject: [PATCH 2/6] Korrigerer feil konvertering av koordinater i CardChoiceScreen --- .../game_wrapper/CardChoiceScreen.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java b/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java index 0028d7b..1546ca2 100644 --- a/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java +++ b/src/main/java/inf112/fiasko/roborally/game_wrapper/CardChoiceScreen.java @@ -6,6 +6,9 @@ import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.viewport.FitViewport; +import com.badlogic.gdx.utils.viewport.Viewport; import java.awt.*; @@ -18,14 +21,18 @@ public class CardChoiceScreen extends InputAdapter implements Screen { private final OrthographicCamera camera; private final CardRectangle cardRectangle; private final ShapeRenderer shapeRenderer; + private final Viewport viewport; public CardChoiceScreen(final RoboRallyWrapper roboRallyWrapper) { this.roboRallyWrapper = roboRallyWrapper; camera = new OrthographicCamera(); - camera.setToOrtho(true, 1200, 1200); + int applicationWidth = 600; + int applicationHeight = 800; + camera.setToOrtho(true, applicationWidth, applicationHeight); + viewport = new FitViewport(applicationWidth, applicationHeight, camera); Rectangle card1 = new Rectangle(); - card1.x = 1200/2; - card1.y = 1200/2; + card1.x = 10; + card1.y = 10; card1.width = 100; card1.height = 100; cardRectangle = new CardRectangle(card1); @@ -60,8 +67,8 @@ public class CardChoiceScreen extends InputAdapter implements Screen { } @Override - public void resize(int i, int i1) { - //Nothing to do + public void resize(int width, int height) { + viewport.update(width, height); } @Override @@ -86,12 +93,9 @@ public class CardChoiceScreen extends InputAdapter implements Screen { @Override public boolean touchUp(int screenX, int screenY, int pointer, int button) { - System.out.println(screenX + " " + screenY); - System.out.println(cardRectangle.rectangle.x + " " + cardRectangle.rectangle.y + " " + - cardRectangle.rectangle.width + " " + cardRectangle.rectangle.height); - if (cardRectangle.rectangle.contains(screenX, screenY)) { - cardRectangle.selected = true; - System.out.println("Card touched"); + Vector3 transformed = viewport.unproject(new Vector3(screenX, screenY, 0)); + if (cardRectangle.rectangle.contains(transformed.x, transformed.y)) { + cardRectangle.selected = !cardRectangle.selected; return true; } return false; From 875363708cf7369db071b0d6a7cc2af808bf1d4f Mon Sep 17 00:00:00 2001 From: GabrielMagnus Date: Tue, 17 Mar 2020 14:02:04 +0100 Subject: [PATCH 3/6] =?UTF-8?q?La=20til=20test=20for=20=C3=A5=20sjekke=20a?= =?UTF-8?q?t=20getPositionsOfWallOnBoard=20har=20rett=20type=20og=20antall?= =?UTF-8?q?=20med=20flere=20argumenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La til hjelpefunksjoner for å sjekke at alle elementer er av rett type --- .../fiasko/roborally/objects/BoardTest.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 7f10db1..ac9eb72 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -221,10 +221,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getTileType(), TileType.COGWHEEL_LEFT); - } + assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.COGWHEEL_LEFT)); } @Test @@ -236,10 +233,7 @@ public class BoardTest { @Test public void getPositionsOfTileOnBoardHasTypeTile() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getTileType(), TileType.TILE); - } + assertTrue(checkIfAllElementsAreOfSpecificTileType(boardElemList, TileType.TILE)); } @Test @@ -251,10 +245,7 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardHasTypeWallNormal() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getWallType(), WallType.WALL_NORMAL); - } + assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_NORMAL)); } @Test @@ -266,17 +257,32 @@ public class BoardTest { @Test public void getPositionsOfWallOnBoardHasTypeWallCorner() { List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); - - for (BoardElementContainer elem : boardElemList) { - assertEquals(elem.getElement().getWallType(), WallType.WALL_CORNER); - } + assertTrue(checkIfAllElementsAreOfSpecificWallType(boardElemList, WallType.WALL_CORNER)); } @Test - public void getPositionsOfWallOnBoardHasCorrect() { - List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); - Predicate> pred = (element) -> element.getElement().getWallType() == WallType.WALL_CORNER; - boardElemList.removeIf(pred); - assertEquals(0, boardElemList.size()); + public void getPositionsOfWallOnBoardHasCorrectTypesWithMultipleParameters() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT, TileType.COGWHEEL_RIGHT); + List tileTypeList = new ArrayList<>(); + List tileTypeListResult = new ArrayList<>(); + tileTypeList.add(TileType.COGWHEEL_LEFT); + tileTypeList.add(TileType.COGWHEEL_RIGHT); + + for (BoardElementContainer elem : boardElemList) { + tileTypeListResult.add(elem.getElement().getTileType()); + } + + assertTrue(tileTypeList.containsAll(tileTypeListResult) && tileTypeListResult.containsAll(tileTypeList)); + } + + public boolean checkIfAllElementsAreOfSpecificWallType(List> elemList, K WallType) { + Predicate> pred = (element) -> element.getElement().getWallType() == WallType; + elemList.removeIf(pred); + return 0 == elemList.size(); + } + public boolean checkIfAllElementsAreOfSpecificTileType(List> elemList, K TileType) { + Predicate> pred = (element) -> element.getElement().getTileType() == TileType; + elemList.removeIf(pred); + return 0 == elemList.size(); } } From 7da60bcc91adaa45b383984140056c2093c1d1fa Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 17 Mar 2020 14:24:46 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Legger=20til=20en=20metode=20for=20=C3=A5?= =?UTF-8?q?=20hente=20ut=20en=20spesifikk=20vegg=20p=C3=A5=20brettet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiasko/roborally/objects/Board.java | 125 ++++++++++-------- 1 file changed, 71 insertions(+), 54 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index cfbca4c..acb43aa 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -208,6 +208,77 @@ public class Board { } } + /** + * Gets the position 1 unit in a specific direction from another position + * @param oldPosition The old/current position of the element + * @param direction The direction to move the element + * @return The new position of the element + */ + public Position getNewPosition(Position oldPosition, Direction direction) { + switch (direction) { + case NORTH: + return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() - 1); + case SOUTH: + return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() + 1); + case EAST: + return new Position(oldPosition.getXCoordinate() + 1, oldPosition.getYCoordinate()); + case WEST: + return new Position(oldPosition.getXCoordinate() - 1, oldPosition.getYCoordinate()); + default: + throw new IllegalArgumentException("It's not possible to move in that direction."); + } + } + + /** + * Gets the tile on a specific position + * @param position The position to get a tile from + * @return The tile on the given position + */ + public Tile getTileOnPosition(Position position) { + if (!isValidPosition(position)) { + throw new IllegalArgumentException("Position is not on the board!"); + } + return tiles.getElement(position.getXCoordinate(), position.getYCoordinate()); + } + + /** + * Gets the wall on a specific position + * @param position The position to get a wall from + * @return The wall on the given position + */ + public Wall getWallOnPosition(Position position) { + if (!isValidPosition(position)) { + throw new IllegalArgumentException("Position is not on the board!"); + } + return walls.getElement(position.getXCoordinate(), position.getYCoordinate()); + } + + /** + * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types + * @param tiles The tiles you want all positions for + * @return A list of BoardElementContainers + */ + public List> getPositionsOfTileOnBoard(TileType ... tiles) { + List> combinedList = new ArrayList<>(); + for (TileType tile : tiles) { + combinedList.addAll(makeTileList(tile, this.tiles)); + } + return combinedList; + } + + /** + * Gets a list of BoardElementContainers, containing all tiles and positions of given wall types + * @param walls The walls you want all positions for + * @return A list of BoardElementContainers + */ + public List> getPositionsOfWallOnBoard(WallType... walls) { + List> combinedList = new ArrayList<>(); + for (WallType wall : walls) { + combinedList.addAll(makeTileList(wall, this.walls)); + } + return combinedList; + } + /** * Checks if a potential robot move would be blocked by a wall * @param robotPosition The current position of the robot @@ -305,27 +376,6 @@ public class Board { } } - /** - * Gets the position 1 unit in a specific direction from another position - * @param oldPosition The old/current position of the element - * @param direction The direction to move the element - * @return The new position of the element - */ - public Position getNewPosition(Position oldPosition, Direction direction) { - switch (direction) { - case NORTH: - return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() - 1); - case SOUTH: - return new Position(oldPosition.getXCoordinate(), oldPosition.getYCoordinate() + 1); - case EAST: - return new Position(oldPosition.getXCoordinate() + 1, oldPosition.getYCoordinate()); - case WEST: - return new Position(oldPosition.getXCoordinate() - 1, oldPosition.getYCoordinate()); - default: - throw new IllegalArgumentException("It's not possible to move in that direction."); - } - } - /** * Gets all elements on a grid * @param grid The grid to get elements from @@ -342,39 +392,6 @@ public class Board { return elements; } - public Tile getTileOnPosition(Position position) { - if (!isValidPosition(position)) { - throw new IllegalArgumentException("Position is not on the board!"); - } - return tiles.getElement(position.getXCoordinate(), position.getYCoordinate()); - } - - /** - * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types - * @param tiles The tiles you want all positions for - * @return A list of BoardElementContainers - */ - public List> getPositionsOfTileOnBoard(TileType ... tiles) { - List> combinedList = new ArrayList<>(); - for (TileType tile : tiles) { - combinedList.addAll(makeTileList(tile, this.tiles)); - } - return combinedList; - } - - /** - * Gets a list of BoardElementContainers, containing all tiles and positions of given wall types - * @param walls The walls you want all positions for - * @return A list of BoardElementContainers - */ - public List> getPositionsOfWallOnBoard(WallType... walls) { - List> combinedList = new ArrayList<>(); - for (WallType wall : walls) { - combinedList.addAll(makeTileList(wall, this.walls)); - } - return combinedList; - } - /** * Finds all position of an obj and makes a list of BoardElementContainers * @param type Type of obj From 3b7a5c6899cf1ac6329cd9f9d33ccb061f2b42fe Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 17 Mar 2020 14:37:49 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Gj=C3=B8r=20metoden=20for=20=C3=A5=20sjekke?= =?UTF-8?q?=20om=20et=20trekk=20blir=20stoppet=20av=20en=20vegg=20offentli?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bytter navn fra robotMove til move --- .../fiasko/roborally/objects/Board.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index acb43aa..049b394 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -135,7 +135,7 @@ public class Board { Position robotPosition = robot.getPosition(); Position newPosition = getNewPosition(robotPosition, direction); //There is a wall blocking the robot. It can't proceed. - if (robotMoveIsStoppedByWall(robotPosition, newPosition, direction)) { + if (moveIsStoppedByWall(robotPosition, newPosition, direction)) { return false; } //Robot tried to go outside of the map. Kill it. @@ -241,18 +241,6 @@ public class Board { return tiles.getElement(position.getXCoordinate(), position.getYCoordinate()); } - /** - * Gets the wall on a specific position - * @param position The position to get a wall from - * @return The wall on the given position - */ - public Wall getWallOnPosition(Position position) { - if (!isValidPosition(position)) { - throw new IllegalArgumentException("Position is not on the board!"); - } - return walls.getElement(position.getXCoordinate(), position.getYCoordinate()); - } - /** * Gets a list of BoardElementContainers, containing all tiles and positions of given tile types * @param tiles The tiles you want all positions for @@ -280,13 +268,13 @@ public class Board { } /** - * Checks if a potential robot move would be blocked by a wall - * @param robotPosition The current position of the robot - * @param newPosition The position the robot is trying to move to - * @param direction The direction the robot is going + * Checks if a potential move would be blocked by a wall + * @param robotPosition The current position of whatever is trying to move + * @param newPosition The position something is trying to move to + * @param direction The direction something is going * @return True if a wall would stop its path */ - private boolean robotMoveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { + public boolean moveIsStoppedByWall(Position robotPosition, Position newPosition, Direction direction) { return hasWallFacing(robotPosition, direction) || (isValidPosition(newPosition) && hasWallFacing(newPosition, Direction.getReverseDirection(direction))); } From 1647d84e9531b49fde48dde9658bf6db1c71d24f Mon Sep 17 00:00:00 2001 From: torlunjen Date: Tue, 17 Mar 2020 16:22:11 +0100 Subject: [PATCH 6/6] Adds checks for collisions on conveyor belts. Parprogrammering med Gabriel --- .../roborally/objects/RoboRallyGame.java | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 2eee13c..d3fb305 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -256,22 +256,68 @@ public class RoboRallyGame implements IDrawableGame { * @throws InterruptedException If disturbed during sleep */ private void moveConveyorBelts(List> conveyorBelts) throws InterruptedException { + List> conveyorBeltsWithRobotsThatShouldMove = + conveyorBeltsThatCanMoveWithoutConflict(conveyorBelts); + for (BoardElementContainer conveyorBelt : conveyorBeltsWithRobotsThatShouldMove) { + Direction currentDirection = conveyorBelt.getElement().getDirection(); + RobotID robot = gameBoard.getRobotOnPosition(conveyorBelt.getPosition()); + Position newPosition = gameBoard.getNewPosition(conveyorBelt.getPosition(), currentDirection); + Tile nextTile = gameBoard.getTileOnPosition(newPosition); + + doConveyorBeltMovement(robot, currentDirection, nextTile); + } + } + + private List> conveyorBeltsThatCanMoveWithoutConflict( + List> conveyorBelts) { + + List> nonConflictConveyorBelts = new ArrayList<>(); for (BoardElementContainer conveyorBelt : conveyorBelts) { - if (!gameBoard.hasRobotOnPosition(conveyorBelt.getPosition())) { - continue; + if (gameBoard.hasRobotOnPosition(conveyorBelt.getPosition())) { + nonConflictConveyorBelts.add(conveyorBelt); } - Position conveyorBeltPosition = conveyorBelt.getPosition(); - Tile conveyorBeltTile = conveyorBelt.getElement(); + } + for (BoardElementContainer conveyorBeltWithRobot : nonConflictConveyorBelts) { + Position conveyorBeltPosition = conveyorBeltWithRobot.getPosition(); + Tile conveyorBeltTile = conveyorBeltWithRobot.getElement(); + Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltTile.getDirection()); Tile nextTile = gameBoard.getTileOnPosition(newPosition); - Direction currentDirection = conveyorBeltTile.getDirection(); - RobotID robot = gameBoard.getRobotOnPosition(conveyorBeltPosition); + Position beyondNextPositionStraight = gameBoard.getNewPosition(newPosition, conveyorBeltTile.getDirection()); + Tile beyondNextTileStraight = gameBoard.getTileOnPosition(beyondNextPositionStraight); - //TODO: Check whether the robot is able to move before moving. Alternatively: Save position and direction - // of each robot and revert if a collision is found. - doConveyorBeltMovement(robot, currentDirection, nextTile); + Position beyondNextPositionLeft = gameBoard.getNewPosition(newPosition, + Direction.getLeftRotatedDirection(conveyorBeltTile.getDirection())); + Tile beyondNextTileLeft = gameBoard.getTileOnPosition(beyondNextPositionLeft); + + Position beyondNextPositionRight = gameBoard.getNewPosition(newPosition, + Direction.getRightRotatedDirection(conveyorBeltTile.getDirection())); + Tile beyondNextTileRight = gameBoard.getTileOnPosition(beyondNextPositionRight); + + + + if (conveyorBeltTile.getDirection() == Direction.getReverseDirection(nextTile.getDirection()) && + nonConflictConveyorBelts.contains(new BoardElementContainer<>(nextTile, newPosition))) { + nonConflictConveyorBelts.remove(conveyorBeltWithRobot); + } + else if (conveyorBeltTile.getDirection() == Direction.getReverseDirection( + beyondNextTileStraight.getDirection()) && nonConflictConveyorBelts.contains( + new BoardElementContainer<>(beyondNextTileStraight, beyondNextPositionStraight))) { + nonConflictConveyorBelts.remove(conveyorBeltWithRobot); + } + else if (conveyorBeltTile.getDirection() == Direction.getLeftRotatedDirection( + beyondNextTileLeft.getDirection()) && nonConflictConveyorBelts.contains( + new BoardElementContainer<>(beyondNextTileLeft, beyondNextPositionLeft))) { + nonConflictConveyorBelts.remove(conveyorBeltWithRobot); + } + else if (conveyorBeltTile.getDirection() == Direction.getRightRotatedDirection( + beyondNextTileRight.getDirection()) && nonConflictConveyorBelts.contains( + new BoardElementContainer<>(beyondNextTileRight, beyondNextPositionRight))) { + nonConflictConveyorBelts.remove(conveyorBeltWithRobot); + } } + return nonConflictConveyorBelts; } /**