2020-03-02 18:46:45 +01:00
|
|
|
package inf112.fiasko.roborally.objects;
|
2020-02-04 17:52:17 +01:00
|
|
|
|
2020-03-17 17:23:57 +01:00
|
|
|
import inf112.fiasko.roborally.element_properties.*;
|
2020-02-22 23:36:01 +01:00
|
|
|
import inf112.fiasko.roborally.utility.BoardLoaderUtil;
|
2020-01-31 13:53:08 +01:00
|
|
|
|
2020-02-22 23:36:01 +01:00
|
|
|
import java.io.IOException;
|
2020-02-03 14:10:52 +01:00
|
|
|
import java.util.ArrayList;
|
2020-01-31 13:53:08 +01:00
|
|
|
import java.util.List;
|
2020-02-24 18:07:26 +01:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2020-03-16 19:37:21 +01:00
|
|
|
import java.util.function.Predicate;
|
2020-01-31 13:53:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class represent a game which is drawable using libgdx
|
|
|
|
*/
|
2020-03-02 18:46:45 +01:00
|
|
|
public class RoboRallyGame implements IDrawableGame {
|
2020-02-22 23:36:01 +01:00
|
|
|
private Board gameBoard;
|
2020-03-16 17:55:38 +01:00
|
|
|
private List<BoardElementContainer<Tile>> cogwheels;
|
|
|
|
private List<BoardElementContainer<Tile>> conveyorBelts;
|
2020-03-16 19:37:21 +01:00
|
|
|
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
2020-02-22 23:36:01 +01:00
|
|
|
|
2020-03-02 18:46:45 +01:00
|
|
|
public RoboRallyGame(boolean debug) {
|
2020-02-27 16:44:06 +01:00
|
|
|
if (debug) {
|
|
|
|
initializeDebugMode();
|
|
|
|
} else {
|
|
|
|
initializeGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 18:46:45 +01:00
|
|
|
public RoboRallyGame() {
|
2020-02-27 16:44:06 +01:00
|
|
|
initializeGame();
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:46:40 +01:00
|
|
|
@Override
|
|
|
|
public int getWidth() {
|
|
|
|
return gameBoard.getBoardWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getHeight() {
|
|
|
|
return gameBoard.getBoardHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Tile> getTilesToDraw() {
|
|
|
|
return gameBoard.getTiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<Wall> getWallsToDraw() {
|
|
|
|
return gameBoard.getWalls();
|
|
|
|
}
|
|
|
|
|
2020-03-23 13:42:48 +01:00
|
|
|
@Override
|
|
|
|
public List<Particle> getParticlesToDraw() {
|
|
|
|
return gameBoard.getParticles();
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:46:40 +01:00
|
|
|
@Override
|
|
|
|
public List<Robot> getRobotsToDraw() {
|
|
|
|
return gameBoard.getAliveRobots();
|
|
|
|
}
|
|
|
|
|
2020-03-10 17:29:36 +01:00
|
|
|
/**
|
|
|
|
* Makes the game thread wait a given time amount before continuing.
|
|
|
|
* @throws InterruptedException If interrupted while trying to sleep.
|
|
|
|
*/
|
|
|
|
private void sleep() throws InterruptedException {
|
|
|
|
long cycleDelay = 600;
|
|
|
|
TimeUnit.MILLISECONDS.sleep(cycleDelay);
|
|
|
|
}
|
2020-02-28 19:46:40 +01:00
|
|
|
/**
|
|
|
|
* Initializes the game with a debugging board
|
|
|
|
*/
|
2020-02-27 16:44:06 +01:00
|
|
|
private void initializeDebugMode() {
|
|
|
|
List<Robot> robots = new ArrayList<>();
|
2020-03-19 13:46:45 +01:00
|
|
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(0, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(2, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_4, new Position(3, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_5, new Position(4, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_6, new Position(5, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_7, new Position(6, 18)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_8, new Position(7, 18)));
|
2020-02-27 16:44:06 +01:00
|
|
|
try {
|
|
|
|
gameBoard = BoardLoaderUtil.loadBoard("boards/all_tiles_test_board.txt", robots);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-28 19:46:40 +01:00
|
|
|
/**
|
|
|
|
* Initializes the game with a playable board
|
|
|
|
*/
|
2020-02-27 16:44:06 +01:00
|
|
|
private void initializeGame() {
|
2020-02-22 23:36:01 +01:00
|
|
|
try {
|
|
|
|
List<Robot> robots = new ArrayList<>();
|
2020-02-24 18:07:26 +01:00
|
|
|
robots.add(new Robot(RobotID.ROBOT_1, new Position(1, 1)));
|
2020-02-24 23:35:58 +01:00
|
|
|
robots.add(new Robot(RobotID.ROBOT_2, new Position(1, 2)));
|
2020-02-26 19:45:39 +01:00
|
|
|
robots.add(new Robot(RobotID.ROBOT_3, new Position(1, 3)));
|
2020-03-17 22:00:56 +01:00
|
|
|
robots.add(new Robot(RobotID.ROBOT_4, new Position(4, 8)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_5, new Position(6, 6)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_6, new Position(7, 7)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_7, new Position(6, 7)));
|
|
|
|
robots.add(new Robot(RobotID.ROBOT_8, new Position(6, 8)));
|
2020-03-23 13:42:48 +01:00
|
|
|
gameBoard = BoardLoaderUtil.loadBoard("boards/Dizzy_Dash.txt", robots);
|
2020-03-12 12:21:31 +01:00
|
|
|
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
|
|
|
|
TileType.COGWHEEL_LEFT);
|
2020-03-16 19:37:21 +01:00
|
|
|
fastConveyorBelts = gameBoard.getPositionsOfTileOnBoard(TileType.CONVEYOR_BELT_FAST,
|
|
|
|
TileType.CONVEYOR_BELT_FAST_RIGHT, TileType.CONVEYOR_BELT_FAST_LEFT,
|
|
|
|
TileType.CONVEYOR_BELT_FAST_SIDE_ENTRANCE_RIGHT,
|
|
|
|
TileType.CONVEYOR_BELT_FAST_SIDE_ENTRANCE_LEFT,
|
|
|
|
TileType.CONVEYOR_BELT_FAST_SIDE_ENTRANCES);
|
|
|
|
conveyorBelts = new ArrayList<>();
|
|
|
|
conveyorBelts.addAll(fastConveyorBelts);
|
|
|
|
conveyorBelts.addAll(gameBoard.getPositionsOfTileOnBoard(TileType.CONVEYOR_BELT_SLOW,
|
|
|
|
TileType.CONVEYOR_BELT_SLOW_RIGHT, TileType.CONVEYOR_BELT_SLOW_LEFT,
|
|
|
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT,
|
|
|
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT,
|
|
|
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
2020-03-16 17:31:54 +01:00
|
|
|
|
2020-02-24 18:07:26 +01:00
|
|
|
new Thread(() -> {
|
|
|
|
try {
|
|
|
|
runGameLoop();
|
|
|
|
} catch (InterruptedException e) {
|
2020-02-26 08:10:46 +01:00
|
|
|
Thread.currentThread().interrupt();
|
2020-02-24 18:07:26 +01:00
|
|
|
}
|
|
|
|
}).start();
|
2020-02-22 23:36:01 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-01-31 13:53:08 +01:00
|
|
|
|
2020-02-24 22:27:19 +01:00
|
|
|
/**
|
|
|
|
* Does whatever the game wants to do
|
|
|
|
* @throws InterruptedException If interrupted while trying to sleep
|
|
|
|
*/
|
2020-02-24 18:07:26 +01:00
|
|
|
private void runGameLoop() throws InterruptedException {
|
2020-02-24 22:27:19 +01:00
|
|
|
TimeUnit.SECONDS.sleep(3);
|
2020-03-10 17:29:36 +01:00
|
|
|
makeMove(RobotID.ROBOT_1, Action.MOVE_1);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.MOVE_2);
|
2020-03-23 13:42:48 +01:00
|
|
|
fireAllLasers();
|
2020-03-10 17:29:36 +01:00
|
|
|
makeMove(RobotID.ROBOT_1, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.MOVE_3);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.ROTATE_LEFT);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.U_TURN);
|
|
|
|
makeMove(RobotID.ROBOT_1, Action.ROTATE_RIGHT);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.MOVE_3);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.MOVE_3);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.MOVE_3);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.BACK_UP);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.ROTATE_LEFT);
|
|
|
|
makeMove(RobotID.ROBOT_2, Action.U_TURN);
|
2020-03-10 18:18:32 +01:00
|
|
|
makeMove(RobotID.ROBOT_2, Action.MOVE_1);
|
2020-03-17 22:00:56 +01:00
|
|
|
moveAllConveyorBelts();
|
2020-03-20 17:46:49 +01:00
|
|
|
checkAllFlags();
|
|
|
|
rotateCogwheels();
|
2020-03-17 22:00:56 +01:00
|
|
|
makeMove(RobotID.ROBOT_7, Action.MOVE_1);
|
2020-03-10 17:29:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the given robot move according to to the action input.
|
|
|
|
* @param robotID The ID of the robot to move.
|
|
|
|
* @param action The specific movement the robot is to take.
|
|
|
|
* @throws InterruptedException If interrupted wile trying to sleep.
|
|
|
|
*/
|
|
|
|
private void makeMove(RobotID robotID, Action action) throws InterruptedException {
|
|
|
|
if (!gameBoard.isRobotAlive(robotID)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sleep();
|
|
|
|
switch (action) {
|
|
|
|
case MOVE_1:
|
2020-03-11 08:02:30 +01:00
|
|
|
gameBoard.moveRobotForward(robotID);
|
2020-03-10 17:29:36 +01:00
|
|
|
break;
|
|
|
|
case MOVE_2:
|
2020-03-11 08:02:30 +01:00
|
|
|
gameBoard.moveRobotForward(robotID);
|
2020-03-10 17:29:36 +01:00
|
|
|
moveForward(robotID);
|
|
|
|
break;
|
|
|
|
case MOVE_3:
|
2020-03-11 08:02:30 +01:00
|
|
|
gameBoard.moveRobotForward(robotID);
|
2020-03-10 17:29:36 +01:00
|
|
|
moveForward(robotID);
|
|
|
|
moveForward(robotID);
|
|
|
|
break;
|
|
|
|
case ROTATE_RIGHT:
|
|
|
|
gameBoard.rotateRobotRight(robotID);
|
|
|
|
break;
|
|
|
|
case ROTATE_LEFT:
|
|
|
|
gameBoard.rotateRobotLeft(robotID);
|
|
|
|
break;
|
|
|
|
case U_TURN:
|
|
|
|
gameBoard.rotateRobotLeft(robotID);
|
|
|
|
gameBoard.rotateRobotLeft(robotID);
|
|
|
|
break;
|
|
|
|
case BACK_UP:
|
|
|
|
gameBoard.reverseRobot(robotID);
|
|
|
|
break;
|
2020-03-10 18:26:16 +01:00
|
|
|
default:
|
|
|
|
throw new IllegalArgumentException("Not a recognized action.");
|
2020-03-10 17:29:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper method for makeMove. Takes care of movement forward of given robot.
|
|
|
|
* @param robotID ID of the given robot.
|
|
|
|
* @throws InterruptedException If interrupted wile sleeping.
|
|
|
|
*/
|
|
|
|
private void moveForward(RobotID robotID) throws InterruptedException {
|
|
|
|
if (!gameBoard.isRobotAlive(robotID)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sleep();
|
|
|
|
gameBoard.moveRobotForward(robotID);
|
2020-02-24 18:07:26 +01:00
|
|
|
}
|
2020-03-12 11:49:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotates all robots that are standing on cogWheel tiles on the board.
|
|
|
|
* @throws InterruptedException If interrupted while sleeping.
|
|
|
|
*/
|
|
|
|
private void rotateCogwheels() throws InterruptedException {
|
2020-03-12 12:21:31 +01:00
|
|
|
for (BoardElementContainer<Tile> cogwheel : cogwheels) {
|
|
|
|
if (!gameBoard.hasRobotOnPosition(cogwheel.getPosition())) {
|
|
|
|
continue;
|
2020-03-12 11:49:14 +01:00
|
|
|
}
|
|
|
|
sleep();
|
2020-03-16 20:06:35 +01:00
|
|
|
if (cogwheel.getElement().getTileType() == TileType.COGWHEEL_RIGHT) {
|
2020-03-12 12:21:31 +01:00
|
|
|
gameBoard.rotateRobotRight(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
|
|
|
} else {
|
|
|
|
gameBoard.rotateRobotLeft(gameBoard.getRobotOnPosition(cogwheel.getPosition()));
|
2020-03-12 11:49:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-16 17:31:54 +01:00
|
|
|
|
2020-03-16 19:37:21 +01:00
|
|
|
/**
|
|
|
|
* Checks whether a given list has at least one element as defined by the predicate
|
|
|
|
* @param list The list to check
|
|
|
|
* @param predicate The predicate to test
|
|
|
|
* @param <T> The type of the list
|
|
|
|
* @return True if the list has at least one element passing the test of the predicate
|
|
|
|
*/
|
|
|
|
private static <T> boolean testPredicate(List<T> list, Predicate<T> predicate) {
|
|
|
|
for (T object : list) {
|
|
|
|
if (predicate.test(object)) {
|
|
|
|
return true;
|
2020-03-16 17:51:06 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-16 19:37:21 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves robots standing on conveyor belts in the direction of the conveyor belt
|
|
|
|
*
|
|
|
|
* In addition, the function rotates appropriately when arriving at any non-straight conveyor belt
|
|
|
|
*
|
|
|
|
* @throws InterruptedException If disturbed during sleep
|
|
|
|
*/
|
|
|
|
private void moveAllConveyorBelts() throws InterruptedException {
|
2020-03-17 22:00:56 +01:00
|
|
|
sleep();
|
2020-03-16 19:37:21 +01:00
|
|
|
moveConveyorBelts(fastConveyorBelts);
|
2020-03-17 22:00:56 +01:00
|
|
|
sleep();
|
2020-03-16 19:37:21 +01:00
|
|
|
moveConveyorBelts(conveyorBelts);
|
2020-03-16 17:51:06 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 17:31:54 +01:00
|
|
|
/**
|
2020-03-16 19:37:21 +01:00
|
|
|
* Moves all conveyor belts in the input list
|
|
|
|
* @param conveyorBelts A list of conveyor belts to move
|
2020-03-16 17:31:54 +01:00
|
|
|
*/
|
2020-03-17 22:00:56 +01:00
|
|
|
private void moveConveyorBelts(List<BoardElementContainer<Tile>> conveyorBelts) {
|
2020-03-17 16:22:11 +01:00
|
|
|
List<BoardElementContainer<Tile>> conveyorBeltsWithRobotsThatShouldMove =
|
|
|
|
conveyorBeltsThatCanMoveWithoutConflict(conveyorBelts);
|
|
|
|
for (BoardElementContainer<Tile> conveyorBelt : conveyorBeltsWithRobotsThatShouldMove) {
|
|
|
|
Direction currentDirection = conveyorBelt.getElement().getDirection();
|
|
|
|
RobotID robot = gameBoard.getRobotOnPosition(conveyorBelt.getPosition());
|
|
|
|
Position newPosition = gameBoard.getNewPosition(conveyorBelt.getPosition(), currentDirection);
|
|
|
|
Tile nextTile = gameBoard.getTileOnPosition(newPosition);
|
|
|
|
|
|
|
|
doConveyorBeltMovement(robot, currentDirection, nextTile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<BoardElementContainer<Tile>> conveyorBeltsThatCanMoveWithoutConflict(
|
|
|
|
List<BoardElementContainer<Tile>> conveyorBelts) {
|
|
|
|
|
|
|
|
List<BoardElementContainer<Tile>> nonConflictConveyorBelts = new ArrayList<>();
|
2020-03-16 17:31:54 +01:00
|
|
|
for (BoardElementContainer<Tile> conveyorBelt : conveyorBelts) {
|
2020-03-17 16:22:11 +01:00
|
|
|
if (gameBoard.hasRobotOnPosition(conveyorBelt.getPosition())) {
|
|
|
|
nonConflictConveyorBelts.add(conveyorBelt);
|
2020-03-16 17:31:54 +01:00
|
|
|
}
|
2020-03-17 16:22:11 +01:00
|
|
|
}
|
|
|
|
for (BoardElementContainer<Tile> conveyorBeltWithRobot : nonConflictConveyorBelts) {
|
|
|
|
Position conveyorBeltPosition = conveyorBeltWithRobot.getPosition();
|
|
|
|
Tile conveyorBeltTile = conveyorBeltWithRobot.getElement();
|
|
|
|
|
2020-03-16 19:37:21 +01:00
|
|
|
Position newPosition = gameBoard.getNewPosition(conveyorBeltPosition, conveyorBeltTile.getDirection());
|
2020-03-16 17:31:54 +01:00
|
|
|
Tile nextTile = gameBoard.getTileOnPosition(newPosition);
|
2020-03-16 19:37:21 +01:00
|
|
|
|
2020-03-17 16:22:11 +01:00
|
|
|
Position beyondNextPositionStraight = gameBoard.getNewPosition(newPosition, conveyorBeltTile.getDirection());
|
|
|
|
Tile beyondNextTileStraight = gameBoard.getTileOnPosition(beyondNextPositionStraight);
|
2020-03-16 19:37:21 +01:00
|
|
|
|
2020-03-17 16:22:11 +01:00
|
|
|
Position beyondNextPositionLeft = gameBoard.getNewPosition(newPosition,
|
|
|
|
Direction.getLeftRotatedDirection(conveyorBeltTile.getDirection()));
|
|
|
|
Tile beyondNextTileLeft = gameBoard.getTileOnPosition(beyondNextPositionLeft);
|
|
|
|
|
|
|
|
Position beyondNextPositionRight = gameBoard.getNewPosition(newPosition,
|
|
|
|
Direction.getRightRotatedDirection(conveyorBeltTile.getDirection()));
|
|
|
|
Tile beyondNextTileRight = gameBoard.getTileOnPosition(beyondNextPositionRight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (conveyorBeltTile.getDirection() == Direction.getReverseDirection(nextTile.getDirection()) &&
|
|
|
|
nonConflictConveyorBelts.contains(new BoardElementContainer<>(nextTile, newPosition))) {
|
|
|
|
nonConflictConveyorBelts.remove(conveyorBeltWithRobot);
|
|
|
|
}
|
|
|
|
else if (conveyorBeltTile.getDirection() == Direction.getReverseDirection(
|
|
|
|
beyondNextTileStraight.getDirection()) && nonConflictConveyorBelts.contains(
|
|
|
|
new BoardElementContainer<>(beyondNextTileStraight, beyondNextPositionStraight))) {
|
|
|
|
nonConflictConveyorBelts.remove(conveyorBeltWithRobot);
|
|
|
|
}
|
|
|
|
else if (conveyorBeltTile.getDirection() == Direction.getLeftRotatedDirection(
|
|
|
|
beyondNextTileLeft.getDirection()) && nonConflictConveyorBelts.contains(
|
|
|
|
new BoardElementContainer<>(beyondNextTileLeft, beyondNextPositionLeft))) {
|
|
|
|
nonConflictConveyorBelts.remove(conveyorBeltWithRobot);
|
|
|
|
}
|
|
|
|
else if (conveyorBeltTile.getDirection() == Direction.getRightRotatedDirection(
|
|
|
|
beyondNextTileRight.getDirection()) && nonConflictConveyorBelts.contains(
|
|
|
|
new BoardElementContainer<>(beyondNextTileRight, beyondNextPositionRight))) {
|
|
|
|
nonConflictConveyorBelts.remove(conveyorBeltWithRobot);
|
|
|
|
}
|
2020-03-16 19:46:00 +01:00
|
|
|
}
|
2020-03-17 16:22:11 +01:00
|
|
|
return nonConflictConveyorBelts;
|
2020-03-16 19:46:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves a robot standing on a conveyor belt
|
|
|
|
* @param robot The id of the robot to move
|
|
|
|
* @param currentDirection The direction of the conveyor belt the robot is standing on
|
|
|
|
* @param nextTile The tile the robot is moving to
|
|
|
|
*/
|
2020-03-17 22:00:56 +01:00
|
|
|
private void doConveyorBeltMovement(RobotID robot, Direction currentDirection, Tile nextTile) {
|
2020-03-16 19:46:00 +01:00
|
|
|
Direction nextDirection = nextTile.getDirection();
|
|
|
|
gameBoard.moveRobot(robot, currentDirection);
|
2020-03-16 20:06:35 +01:00
|
|
|
if (testPredicate(conveyorBelts, (container) -> container.getElement() == nextTile)) {
|
2020-03-16 19:46:00 +01:00
|
|
|
if (Direction.getRightRotatedDirection(nextDirection) == currentDirection) {
|
|
|
|
gameBoard.rotateRobotLeft(robot);
|
|
|
|
} else if (Direction.getLeftRotatedDirection(nextDirection) == currentDirection) {
|
|
|
|
gameBoard.rotateRobotRight(robot);
|
2020-03-16 17:31:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-16 17:35:01 +01:00
|
|
|
|
2020-03-16 15:52:18 +01:00
|
|
|
/**
|
|
|
|
* Checks all flags for robots. Tries to update the flag of the robot.
|
|
|
|
*/
|
|
|
|
private void checkAllFlags() {
|
|
|
|
List<BoardElementContainer<Tile>> listOfFlags = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
|
|
|
|
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4);
|
|
|
|
for (BoardElementContainer<Tile> flag:listOfFlags) {
|
|
|
|
Position flagPosition = flag.getPosition();
|
|
|
|
if (gameBoard.hasRobotOnPosition(flagPosition)) {
|
|
|
|
RobotID robot = gameBoard.getRobotOnPosition(flagPosition);
|
2020-03-16 20:06:35 +01:00
|
|
|
gameBoard.updateFlagOnRobot(robot, flag.getElement().getTileType());
|
2020-03-16 15:52:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 17:23:57 +01:00
|
|
|
|
2020-03-23 13:42:48 +01:00
|
|
|
/**
|
|
|
|
* Fires all lasers on the game board
|
|
|
|
*/
|
2020-03-23 13:47:34 +01:00
|
|
|
private void fireAllLasers() throws InterruptedException {
|
2020-03-17 17:23:57 +01:00
|
|
|
gameBoard.fireAllLasers();
|
2020-03-23 13:47:34 +01:00
|
|
|
sleep();
|
|
|
|
gameBoard.doLaserCleanup();
|
2020-03-17 17:23:57 +01:00
|
|
|
}
|
2020-03-12 11:49:14 +01:00
|
|
|
}
|