Fikser noen bugs rundt flagg og diverse Closes #75

Fikser noen tiles i Dizzy Dash som var feil vei
Fikser resetting av hasTouchedFlagThisTurn
Fikser at RoboRallyGame sin setProgram ikke godtar et tomt program
Utvider flaggtesten til å inkludere alle flagg
This commit is contained in:
Kristian Knarvik 2020-04-24 19:10:30 +02:00
parent 4f47e7e809
commit 35fccac794
5 changed files with 50 additions and 24 deletions

View File

@ -890,7 +890,13 @@ public class Board {
* @param hasTouched If the robot has touched a flag this turn * @param hasTouched If the robot has touched a flag this turn
*/ */
public void setHasTouchedFlagThisTurn(RobotID robotID, boolean hasTouched) { public void setHasTouchedFlagThisTurn(RobotID robotID, boolean hasTouched) {
robots.get(robotID).setHasTouchedFlagThisTurn(hasTouched); Robot aliveRobot = robots.get(robotID);
Robot deadRobot = getRobotFromDeadRobots(robotID);
if (aliveRobot != null) {
aliveRobot.setHasTouchedFlagThisTurn(hasTouched);
} else if (deadRobot != null) {
deadRobot.setHasTouchedFlagThisTurn(hasTouched);
}
} }
/** /**

View File

@ -131,7 +131,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
@Override @Override
public void setProgram(List<ProgrammingCard> program) { public void setProgram(List<ProgrammingCard> program) {
if (program.size() != 5) { if (program.size() != 5 && program.size() != 0) {
throw new IllegalArgumentException("Invalid program chosen."); throw new IllegalArgumentException("Invalid program chosen.");
} }
this.program = program; this.program = program;
@ -307,8 +307,8 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
* Resets the boolean for if the robot has touched a flag this turn, to set up the next turn. * Resets the boolean for if the robot has touched a flag this turn, to set up the next turn.
*/ */
private void resetHasTouchedFlagThisTurnForAllRobots() { private void resetHasTouchedFlagThisTurnForAllRobots() {
for (Robot robot : gameBoard.getAliveRobots()) { for (RobotID robotID : RobotID.values()) {
robot.setHasTouchedFlagThisTurn(false); gameBoard.setHasTouchedFlagThisTurn(robotID, false);
} }
} }

View File

@ -1,8 +1,8 @@
12 16 12 16
01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1 01;1
01;1 12;3 11;3 11;3 12;5 01;1 01;1 12;3 11;3 11;3 12;5 01;1 01;1 12;3 11;3 11;3 12;5 01;1 01;1 12;3 11;3 11;3 12;5 01;1
01;1 11;1 03;1 01;1 11;1 04;7 01;1 11;1 03;1 01;1 11;5 01;1 01;1 11;1 03;1 01;1 11;5 04;7 01;1 11;1 03;1 01;1 11;5 01;1
01;1 11;1 21;1 03;1 11;1 01;1 01;1 11;1 22;1 03;1 11;5 01;1 01;1 11;1 21;1 03;1 11;5 01;1 01;1 11;1 22;1 03;1 11;5 01;1
01;1 12;1 11;7 11;7 12;7 17;1 04;7 12;1 11;7 11;7 12;7 01;1 01;1 12;1 11;7 11;7 12;7 17;1 04;7 12;1 11;7 11;7 12;7 01;1
01;1 01;1 01;1 01;1 04;5 01;1 01;1 01;1 01;1 04;1 01;1 01;1 01;1 01;1 01;1 01;1 04;5 01;1 01;1 01;1 01;1 04;1 01;1 01;1
01;1 19;1 04;5 01;1 01;1 01;1 01;1 04;1 01;1 01;1 01;1 01;1 01;1 19;1 04;5 01;1 01;1 01;1 01;1 04;1 01;1 01;1 01;1 01;1

View File

@ -71,21 +71,41 @@ public class PhaseTest {
} }
@Test @Test
public void playerWinsAfterTouchingAllFlagsInCorrectOrder() { public void playerWinsAfterTouchingAllFlagsInCorrectOrder() throws IOException {
FakeGame testGame = new FakeGame(); FakeGame testGame = new FakeGame();
List<Robot> robot = new ArrayList<>(); List<Robot> robots = new ArrayList<>();
List<Player> player = new ArrayList<>(); List<Player> player = new ArrayList<>();
robot.add(new Robot(RobotID.ROBOT_1, new Position(0, 0))); RobotID robotID = RobotID.ROBOT_1;
player.add(new Player(RobotID.ROBOT_1, "Player 1")); Robot robot = new Robot(robotID, new Position(0, 0));
robots.add(robot);
player.add(new Player(robotID, "Player 1"));
board = BoardLoaderUtil.loadBoard("boards/win_test_board.txt", robots);
Phase testPhase = new Phase(board, player, 0, testGame);
try { assertEquals(0, robot.getLastFlagVisited());
board = BoardLoaderUtil.loadBoard("boards/win_test_board.txt", robot); assertFalse(robot.hasTouchedFlagThisTurn());
Phase testPhase = new Phase(board, player, 0, testGame); testPhase.checkAllFlags();
testPhase.checkAllFlags(); assertEquals(1, robot.getLastFlagVisited());
assertEquals("Player 1", testGame.getWinningPlayerName()); assertTrue(robot.hasTouchedFlagThisTurn());
} catch (IOException e) { robot.setHasTouchedFlagThisTurn(false);
e.printStackTrace(); assertNull(testGame.getWinningPlayerName());
} board.moveRobot(robotID, Direction.EAST);
testPhase.checkAllFlags();
assertEquals(2, robot.getLastFlagVisited());
assertTrue(robot.hasTouchedFlagThisTurn());
assertNull(testGame.getWinningPlayerName());
robot.setHasTouchedFlagThisTurn(false);
board.moveRobot(robotID, Direction.EAST);
testPhase.checkAllFlags();
assertEquals(3, robot.getLastFlagVisited());
assertTrue(robot.hasTouchedFlagThisTurn());
assertNull(testGame.getWinningPlayerName());
robot.setHasTouchedFlagThisTurn(false);
board.moveRobot(robotID, Direction.EAST);
testPhase.checkAllFlags();
assertEquals(4, robot.getLastFlagVisited());
assertTrue(robot.hasTouchedFlagThisTurn());
assertEquals("Player 1", testGame.getWinningPlayerName());
} }
@Test @Test
@ -98,11 +118,11 @@ public class PhaseTest {
} }
@Test @Test
public void robotDoesNotRegistersWrongFlag() { public void robotDoesNotRegisterWrongFlag() {
assertEquals(robot4.getLastFlagVisited(), 0); assertEquals(0, robot4.getLastFlagVisited());
assertFalse(robot4.hasTouchedFlagThisTurn()); assertFalse(robot4.hasTouchedFlagThisTurn());
phase.checkAllFlags(); phase.checkAllFlags();
assertEquals(robot4.getLastFlagVisited(), 0); assertEquals(0, robot4.getLastFlagVisited());
assertFalse(robot4.hasTouchedFlagThisTurn()); assertFalse(robot4.hasTouchedFlagThisTurn());
} }

View File

@ -1,3 +1,3 @@
1 1 4 1
17;1 17;1 18;1 19;1 20;1
0 0 0 0 0