mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
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:
parent
4f47e7e809
commit
35fccac794
@ -890,7 +890,13 @@ public class Board {
|
||||
* @param hasTouched If the robot has touched a flag this turn
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +131,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
||||
|
||||
@Override
|
||||
public void setProgram(List<ProgrammingCard> program) {
|
||||
if (program.size() != 5) {
|
||||
if (program.size() != 5 && program.size() != 0) {
|
||||
throw new IllegalArgumentException("Invalid program chosen.");
|
||||
}
|
||||
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.
|
||||
*/
|
||||
private void resetHasTouchedFlagThisTurnForAllRobots() {
|
||||
for (Robot robot : gameBoard.getAliveRobots()) {
|
||||
robot.setHasTouchedFlagThisTurn(false);
|
||||
for (RobotID robotID : RobotID.values()) {
|
||||
gameBoard.setHasTouchedFlagThisTurn(robotID, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
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 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 21;1 03;1 11;1 01;1 01;1 11;1 22;1 03;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;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 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
|
||||
|
@ -71,21 +71,41 @@ public class PhaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void playerWinsAfterTouchingAllFlagsInCorrectOrder() {
|
||||
public void playerWinsAfterTouchingAllFlagsInCorrectOrder() throws IOException {
|
||||
FakeGame testGame = new FakeGame();
|
||||
List<Robot> robot = new ArrayList<>();
|
||||
List<Robot> robots = new ArrayList<>();
|
||||
List<Player> player = new ArrayList<>();
|
||||
robot.add(new Robot(RobotID.ROBOT_1, new Position(0, 0)));
|
||||
player.add(new Player(RobotID.ROBOT_1, "Player 1"));
|
||||
|
||||
try {
|
||||
board = BoardLoaderUtil.loadBoard("boards/win_test_board.txt", robot);
|
||||
RobotID robotID = RobotID.ROBOT_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);
|
||||
|
||||
assertEquals(0, robot.getLastFlagVisited());
|
||||
assertFalse(robot.hasTouchedFlagThisTurn());
|
||||
testPhase.checkAllFlags();
|
||||
assertEquals(1, robot.getLastFlagVisited());
|
||||
assertTrue(robot.hasTouchedFlagThisTurn());
|
||||
robot.setHasTouchedFlagThisTurn(false);
|
||||
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());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -98,11 +118,11 @@ public class PhaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void robotDoesNotRegistersWrongFlag() {
|
||||
assertEquals(robot4.getLastFlagVisited(), 0);
|
||||
public void robotDoesNotRegisterWrongFlag() {
|
||||
assertEquals(0, robot4.getLastFlagVisited());
|
||||
assertFalse(robot4.hasTouchedFlagThisTurn());
|
||||
phase.checkAllFlags();
|
||||
assertEquals(robot4.getLastFlagVisited(), 0);
|
||||
assertEquals(0, robot4.getLastFlagVisited());
|
||||
assertFalse(robot4.hasTouchedFlagThisTurn());
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
1 1
|
||||
17;1
|
||||
0
|
||||
4 1
|
||||
17;1 18;1 19;1 20;1
|
||||
0 0 0 0
|
Loading…
x
Reference in New Issue
Block a user