This commit is contained in:
Steinar Aalstad Lillesund 2020-04-23 12:07:07 +02:00
commit a5f76092d9
4 changed files with 43 additions and 16 deletions

View File

@ -50,18 +50,17 @@ public class WinnerScreen extends AbstractScreen {
@Override @Override
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0.2f, 1f, 0.2f, 1); Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update(); camera.update();
roboRallyWrapper.batch.setProjectionMatrix(camera.combined); roboRallyWrapper.batch.setProjectionMatrix(camera.combined);
roboRallyWrapper.batch.begin(); roboRallyWrapper.batch.begin();
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: " + roboRallyWrapper.font.draw(roboRallyWrapper.batch, "The winner is: ", applicationWidth / 2f - 380 / 2f,
roboRallyWrapper.roboRallyGame.getWinningPlayerName(), applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 300, 380, 1,
applicationHeight / 2f + 100, 380, 1,
true); true);
roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game", roboRallyWrapper.font.draw(roboRallyWrapper.batch, "Click the button to exit the game",
applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 100, 380, 1, applicationWidth / 2f - 380 / 2f, applicationHeight / 2f + 150, 380, 1,
true); true);
roboRallyWrapper.batch.end(); roboRallyWrapper.batch.end();
stage.draw(); stage.draw();

View File

@ -401,20 +401,20 @@ public class Board {
private boolean hasCrossingConflict(Position crossingPosition, Direction conveyorBeltDirection) { private boolean hasCrossingConflict(Position crossingPosition, Direction conveyorBeltDirection) {
Position frontLeftPosition = getNewPosition(crossingPosition, Position frontLeftPosition = getNewPosition(crossingPosition,
Direction.getLeftRotatedDirection(conveyorBeltDirection)); Direction.getLeftRotatedDirection(conveyorBeltDirection));
Tile frontLeftTile = getTileOnPosition(frontLeftPosition);
Position frontRightPosition = getNewPosition(crossingPosition, Position frontRightPosition = getNewPosition(crossingPosition,
Direction.getRightRotatedDirection(conveyorBeltDirection)); Direction.getRightRotatedDirection(conveyorBeltDirection));
Tile frontRightTile = getTileOnPosition(frontRightPosition);
Position twoForwardPosition = getNewPosition(crossingPosition, conveyorBeltDirection); Position twoForwardPosition = getNewPosition(crossingPosition, conveyorBeltDirection);
Tile twoForwardTile = getTileOnPosition(twoForwardPosition);
//If another robot is standing on a conveyor belt pointing to the tile in front, a conflict happens //If another robot is standing on a conveyor belt pointing to the tile in front, a conflict happens
return (isValidPosition(frontLeftPosition) && isConveyorBelt(frontLeftTile) && frontLeftTile.getDirection() == return (isValidPosition(frontLeftPosition) && isConveyorBelt(getTileOnPosition(frontLeftPosition)) &&
getTileOnPosition(frontLeftPosition).getDirection() ==
Direction.getRightRotatedDirection(conveyorBeltDirection) && hasRobotOnPosition(frontLeftPosition)) || Direction.getRightRotatedDirection(conveyorBeltDirection) && hasRobotOnPosition(frontLeftPosition)) ||
(isValidPosition(frontRightPosition) && isConveyorBelt(frontRightTile) (isValidPosition(frontRightPosition) && isConveyorBelt(getTileOnPosition(frontRightPosition))
&& frontRightTile.getDirection() == Direction.getLeftRotatedDirection(conveyorBeltDirection) && getTileOnPosition(frontRightPosition).getDirection() ==
Direction.getLeftRotatedDirection(conveyorBeltDirection)
&& hasRobotOnPosition(frontRightPosition)) || && hasRobotOnPosition(frontRightPosition)) ||
(isValidPosition(twoForwardPosition) && isConveyorBelt(twoForwardTile) (isValidPosition(twoForwardPosition) && isConveyorBelt(getTileOnPosition(twoForwardPosition))
&& twoForwardTile.getDirection() == Direction.getReverseDirection(conveyorBeltDirection) && getTileOnPosition(twoForwardPosition).getDirection() ==
Direction.getReverseDirection(conveyorBeltDirection)
&& hasRobotOnPosition(twoForwardPosition)); && hasRobotOnPosition(twoForwardPosition));
} }

View File

@ -461,4 +461,32 @@ public class PhaseTest {
assertFalse(board.isRobotAlive(RobotID.ROBOT_1)); assertFalse(board.isRobotAlive(RobotID.ROBOT_1));
assertNull(board.getRobotOnPosition(new Position(7, 0))); assertNull(board.getRobotOnPosition(new Position(7, 0)));
} }
@Test
public void robotOnConveyorBeltFacingOutOfMapMovesIntoWallIsBlocked() throws IOException, InterruptedException {
List<Robot> robots = new ArrayList<>();
List<Player> players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 0)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
Phase testPhase = createPhaseAndLoadBoard(players, robots);
testPhase.moveAllConveyorBelts();
assertTrue(board.isRobotAlive(RobotID.ROBOT_1));
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(0, 0)));
}
@Test
public void robotOnConveyorBeltFacingOutOfMapWithOneTileBetweenCanBeMoved() throws IOException, InterruptedException {
List<Robot> robots = new ArrayList<>();
List<Player> players = new ArrayList<>();
robots.add(new Robot(RobotID.ROBOT_1, new Position(10, 10)));
players.add(new Player(RobotID.ROBOT_1, "Player 1"));
Phase testPhase = createPhaseAndLoadBoard(players, robots);
testPhase.moveAllConveyorBelts();
assertTrue(board.isRobotAlive(RobotID.ROBOT_1));
assertEquals(RobotID.ROBOT_1, board.getRobotOnPosition(new Position(10, 11)));
}
} }

View File

@ -1,5 +1,5 @@
12 12 12 12
01;01 01;01 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 01;01
01;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 02;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 02;01 01;01 01;01
01;01 05;01 01;01 05;07 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 05;01 01;01 05;07 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01
01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01
@ -9,9 +9,9 @@
01;01 01;01 01;01 01;01 11;01 05;01 05;03 02;01 01;01 03;01 01;01 01;01 01;01 01;01 01;01 01;01 11;01 05;01 05;03 02;01 01;01 03;01 01;01 01;01
01;01 07;05 07;07 01;01 11;01 05;01 01;01 05;01 01;01 01;01 01;01 01;01 01;01 07;05 07;07 01;01 11;01 05;01 01;01 05;01 01;01 01;01 01;01 01;01
01;01 07;03 07;01 01;01 11;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 07;03 07;01 01;01 11;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01
01;01 01;01 01;01 01;01 11;01 05;01 01;01 05;03 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 11;01 05;01 01;01 05;03 01;01 01;01 05;05 01;01
01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 01;01 05;01 01;01 01;01 01;01
0 1;5 0 0 0 0 0 0 0 0 0 0 1;1 1;5 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0