Refaktorerer initializeGame() for bedre ryddighet

This commit is contained in:
Kristian Knarvik 2020-03-26 13:07:53 +01:00
parent a4bfee6cb8
commit 200675bd2c

View File

@ -117,6 +117,28 @@ public class RoboRallyGame implements IDrawableGame {
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)));
initializePlayers();
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
generateTileLists();
new Thread(() -> {
try {
runGameLoop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}).start();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Initializes all players
* @throws IOException If interrupted while trying to sleep
*/
private void initializePlayers() throws IOException {
playerList = new ArrayList<>();
playerList.add(new Player(RobotID.ROBOT_1, "Player1"));
playerList.add(new Player(RobotID.ROBOT_2, "Player2"));
@ -136,8 +158,12 @@ public class RoboRallyGame implements IDrawableGame {
}
player.setInProgram(testProgram);
}
}
gameBoard = BoardLoaderUtil.loadBoard("boards/Checkmate.txt", robots);
/**
* Generates lists containing board element containers with all tiles of certain types
*/
private void generateTileLists() {
cogwheels = gameBoard.getPositionsOfTileOnBoard(TileType.COGWHEEL_RIGHT,
TileType.COGWHEEL_LEFT);
fastConveyorBelts = gameBoard.getPositionsOfTileOnBoard(TileType.CONVEYOR_BELT_FAST,
@ -152,17 +178,6 @@ public class RoboRallyGame implements IDrawableGame {
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT,
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT,
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
new Thread(() -> {
try {
runGameLoop();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}).start();
} catch (IOException e) {
e.printStackTrace();
}
}
/**