Utfører litt kodeopprydding

This commit is contained in:
Kristian Knarvik 2020-04-24 22:46:16 +02:00
parent 55aeab48a5
commit ddc0adc552
2 changed files with 23 additions and 13 deletions

View File

@ -24,6 +24,7 @@ public class Board {
private Map<RobotID, Robot> robots; private Map<RobotID, Robot> robots;
private List<Robot> deadRobots; private List<Robot> deadRobots;
private List<RobotID> realDeadRobots; private List<RobotID> realDeadRobots;
private List<TileType> dangerousTiles;
/** /**
* Initializes the board * Initializes the board
@ -50,6 +51,20 @@ public class Board {
this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight()); this.particles = new ListGrid<>(tiles.getWidth(), tiles.getHeight());
this.deadRobots = new ArrayList<>(); this.deadRobots = new ArrayList<>();
this.realDeadRobots = 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,6 +392,7 @@ public class Board {
/** /**
* Checks whether a conveyor belt movement is stopped by either a wall or a robot * 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 positionInFront The position in front of the conveyor belt
* @param conveyorBeltPosition The position of the conveyor belt * @param conveyorBeltPosition The position of the conveyor belt
* @param conveyorBeltDirection The direction of the conveyor belt * @param conveyorBeltDirection The direction of the conveyor belt
@ -427,7 +443,8 @@ public class Board {
} }
/** /**
* Checks whether a poosible conflict position has a conflict * Checks whether a possible conflict position has a conflict
*
* @param conflictPosition The position with a potential conflict * @param conflictPosition The position with a potential conflict
* @param conflictDirection The direction necessary to count as a conflict * @param conflictDirection The direction necessary to count as a conflict
* @return True if the position has 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."); throw new IllegalArgumentException("The game board is missing a tile. This should not happen.");
} }
TileType tileTypeRobotStepsOn = tileRobotStepsOn.getTileType(); TileType tileTypeRobotStepsOn = tileRobotStepsOn.getTileType();
List<TileType> 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)) { if (dangerousTiles.contains(tileTypeRobotStepsOn)) {
killRobot(robot); killRobot(robot);
} }

View File

@ -53,7 +53,7 @@ public class RoboRallyGameTest {
assertEquals(16, game.getHeight()); assertEquals(16, game.getHeight());
} }
@Test (expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void invalidProgramThrowsError() { public void invalidProgramThrowsError() {
List<ProgrammingCard> programmingCardList = new ArrayList<>(); List<ProgrammingCard> programmingCardList = new ArrayList<>();
programmingCardList.add(new ProgrammingCard(10, Action.MOVE_1)); programmingCardList.add(new ProgrammingCard(10, Action.MOVE_1));