From ddc0adc552185196093ac56d0a9366764b12ff58 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Fri, 24 Apr 2020 22:46:16 +0200 Subject: [PATCH] =?UTF-8?q?Utf=C3=B8rer=20litt=20kodeopprydding?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiasko/roborally/objects/Board.java | 34 ++++++++++++------- .../roborally/objects/RoboRallyGameTest.java | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 8d85106..0e889c9 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -24,6 +24,7 @@ public class Board { private Map robots; private List deadRobots; private List realDeadRobots; + private List dangerousTiles; /** * Initializes the board @@ -50,6 +51,20 @@ public class Board { this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight()); this.deadRobots = new ArrayList<>(); this.realDeadRobots = new ArrayList<>(); + this.dangerousTiles = new ArrayList<>(); + loadDangerousTileTypes(); + } + + /** + * Adds tile types which will kill the robot to the dangerousTiles list + */ + private void loadDangerousTileTypes() { + dangerousTiles.add(TileType.HOLE); + dangerousTiles.add(TileType.PIT_CORNER); + dangerousTiles.add(TileType.PIT_EMPTY); + dangerousTiles.add(TileType.PIT_FULL); + dangerousTiles.add(TileType.PIT_NORMAL); + dangerousTiles.add(TileType.PIT_U); } /** @@ -377,8 +392,9 @@ public class Board { /** * Checks whether a conveyor belt movement is stopped by either a wall or a robot - * @param positionInFront The position in front of the conveyor belt - * @param conveyorBeltPosition The position of the conveyor belt + * + * @param positionInFront The position in front of the conveyor belt + * @param conveyorBeltPosition The position of the conveyor belt * @param conveyorBeltDirection The direction of the conveyor belt * @return True if the conveyor belt cannot move */ @@ -418,7 +434,7 @@ public class Board { Direction.getRightRotatedDirection(conveyorBeltDirection)); //Checks for conflict at a conveyor belt coming in from the right boolean frontRightConflict = conveyorBeltHasConflict(getNewPosition(crossingPosition, - Direction.getRightRotatedDirection(conveyorBeltDirection)), + Direction.getRightRotatedDirection(conveyorBeltDirection)), Direction.getLeftRotatedDirection(conveyorBeltDirection)); //Checks for conflict at a conveyor belt at the opposite side of the crossing boolean frontConflict = conveyorBeltHasConflict(getNewPosition(crossingPosition, conveyorBeltDirection), @@ -427,8 +443,9 @@ public class Board { } /** - * Checks whether a poosible conflict position has a conflict - * @param conflictPosition The position with a potential conflict + * Checks whether a possible conflict position has a conflict + * + * @param conflictPosition The position with a potential conflict * @param conflictDirection The direction necessary to count as a conflict * @return True if the position has a conflict */ @@ -648,13 +665,6 @@ public class Board { throw new IllegalArgumentException("The game board is missing a tile. This should not happen."); } TileType tileTypeRobotStepsOn = tileRobotStepsOn.getTileType(); - List dangerousTiles = new ArrayList<>(); - dangerousTiles.add(TileType.HOLE); - dangerousTiles.add(TileType.PIT_CORNER); - dangerousTiles.add(TileType.PIT_EMPTY); - dangerousTiles.add(TileType.PIT_FULL); - dangerousTiles.add(TileType.PIT_NORMAL); - dangerousTiles.add(TileType.PIT_U); if (dangerousTiles.contains(tileTypeRobotStepsOn)) { killRobot(robot); } diff --git a/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java index 1a504c0..f0e0b24 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/RoboRallyGameTest.java @@ -53,7 +53,7 @@ public class RoboRallyGameTest { assertEquals(16, game.getHeight()); } - @Test (expected = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void invalidProgramThrowsError() { List programmingCardList = new ArrayList<>(); programmingCardList.add(new ProgrammingCard(10, Action.MOVE_1));