mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Gjør en del kodeforbedringer
Genererer liste av repairtiles en gang for å øke effektivitet Fjerner linjer som ikke gjør noe Forenkler kode der det er mulig Legger til kommentarer inne i kodeblokker for å øke leselighet Forbedrer variabelnavn og metodenavn
This commit is contained in:
parent
93664473e0
commit
1d2887af28
@ -24,6 +24,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
private List<BoardElementContainer<Tile>> cogwheels;
|
private List<BoardElementContainer<Tile>> cogwheels;
|
||||||
private List<BoardElementContainer<Tile>> conveyorBelts;
|
private List<BoardElementContainer<Tile>> conveyorBelts;
|
||||||
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
private List<BoardElementContainer<Tile>> fastConveyorBelts;
|
||||||
|
private List<BoardElementContainer<Tile>> repairTiles;
|
||||||
private final List<Player> playerList;
|
private final List<Player> playerList;
|
||||||
private final boolean host;
|
private final boolean host;
|
||||||
private Deck<ProgrammingCard> mainDeck;
|
private Deck<ProgrammingCard> mainDeck;
|
||||||
@ -161,6 +162,8 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT,
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_RIGHT,
|
||||||
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT,
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCE_LEFT,
|
||||||
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
TileType.CONVEYOR_BELT_SLOW_SIDE_ENTRANCES));
|
||||||
|
repairTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1, TileType.FLAG_2, TileType.FLAG_3,
|
||||||
|
TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -265,9 +268,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
*/
|
*/
|
||||||
private void removeNonLockedProgrammingCardsFromPlayers() {
|
private void removeNonLockedProgrammingCardsFromPlayers() {
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
|
player.getPlayerDeck().emptyInto(mainDeck);
|
||||||
playerDeck.emptyInto(mainDeck);
|
|
||||||
player.setPlayerDeck(playerDeck);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,23 +276,20 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* Deals correct amount of cards to active players, based on their robots damage
|
* Deals correct amount of cards to active players, based on their robots damage
|
||||||
*/
|
*/
|
||||||
private void distributeProgrammingCardsToPlayers() {
|
private void distributeProgrammingCardsToPlayers() {
|
||||||
int robotDamage;
|
|
||||||
ProgrammingCardDeck playerDeck;
|
|
||||||
mainDeck.shuffle();
|
mainDeck.shuffle();
|
||||||
|
|
||||||
for (Player player : playerList) {
|
for (Player player : playerList) {
|
||||||
RobotID robot = player.getRobotID();
|
RobotID robot = player.getRobotID();
|
||||||
playerDeck = player.getPlayerDeck();
|
ProgrammingCardDeck playerDeck = player.getPlayerDeck();
|
||||||
if (gameBoard.getPowerDown(robot)) {
|
int robotDamage = gameBoard.getRobotDamage(robot);
|
||||||
|
//Powered down or heavily damaged robots don't get any cards
|
||||||
|
if (gameBoard.getPowerDown(robot) || robotDamage >= 9) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
robotDamage = gameBoard.getRobotDamage(robot);
|
if (!playerDeck.isEmpty()) {
|
||||||
if (robotDamage >= 9) {
|
throw new IllegalStateException("Player deck must be empty when dealing new cards!");
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (playerDeck.isEmpty()) {
|
//Gives the player the correct amount of cards
|
||||||
playerDeck.draw(mainDeck,9-robotDamage);
|
playerDeck.draw(mainDeck,9 - robotDamage);
|
||||||
} else throw new IllegalStateException("Player deck must be empty!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +299,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* @throws InterruptedException If interrupted wile trying to sleep
|
* @throws InterruptedException If interrupted wile trying to sleep
|
||||||
*/
|
*/
|
||||||
private void runPhase(int phaseNumber) throws InterruptedException {
|
private void runPhase(int phaseNumber) throws InterruptedException {
|
||||||
runProgramCards(phaseNumber);
|
runProgrammingCards(phaseNumber);
|
||||||
|
|
||||||
moveAllConveyorBelts();
|
moveAllConveyorBelts();
|
||||||
rotateCogwheels();
|
rotateCogwheels();
|
||||||
@ -484,7 +482,7 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
* @param phase The number of the phase to run cards for
|
* @param phase The number of the phase to run cards for
|
||||||
* @throws InterruptedException If it gets interrupted while trying to sleep
|
* @throws InterruptedException If it gets interrupted while trying to sleep
|
||||||
*/
|
*/
|
||||||
private void runProgramCards(int phase) throws InterruptedException {
|
private void runProgrammingCards(int phase) throws InterruptedException {
|
||||||
List<RobotID> robotsToDoAction = new ArrayList<>();
|
List<RobotID> robotsToDoAction = new ArrayList<>();
|
||||||
List<ProgrammingCard> programToBeRun = new ArrayList<>();
|
List<ProgrammingCard> programToBeRun = new ArrayList<>();
|
||||||
List<Integer> originalPriority = new ArrayList<>();
|
List<Integer> originalPriority = new ArrayList<>();
|
||||||
@ -508,19 +506,17 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
/**
|
/**
|
||||||
* Respawn all the dead robots with more lives and places them on the game board
|
* Respawn all the dead robots with more lives and places them on the game board
|
||||||
*/
|
*/
|
||||||
private void respawnRobots(){
|
private void respawnRobots() {
|
||||||
gameBoard.respawnRobots();
|
gameBoard.respawnRobots();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* repair all robots standing on a repair tile
|
* repair all robots standing on a repair tile
|
||||||
*/
|
*/
|
||||||
private void repairAllRobotsOnRepairTiles(){
|
private void repairAllRobotsOnRepairTiles() {
|
||||||
List<BoardElementContainer<Tile>> listOfRepareTiles = gameBoard.getPositionsOfTileOnBoard(TileType.FLAG_1,
|
for (BoardElementContainer<Tile> repairTile : repairTiles) {
|
||||||
TileType.FLAG_2, TileType.FLAG_3, TileType.FLAG_4, TileType.WRENCH, TileType.WRENCH_AND_HAMMER);
|
Position robotOnTilePosition = repairTile.getPosition();
|
||||||
for (BoardElementContainer<Tile> repareTile:listOfRepareTiles) {
|
if (!gameBoard.hasRobotOnPosition(robotOnTilePosition)) {
|
||||||
Position robotOnTilePosition = repareTile.getPosition();
|
|
||||||
if (!gameBoard.hasRobotOnPosition(robotOnTilePosition)){
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
gameBoard.repairRobotOnTile(gameBoard.getRobotOnPosition(robotOnTilePosition));
|
gameBoard.repairRobotOnTile(gameBoard.getRobotOnPosition(robotOnTilePosition));
|
||||||
@ -528,21 +524,21 @@ public class RoboRallyGame implements IDrawableGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the robots powerdown status too the players powerdown next round status and sets the players status to false
|
* Sets the robot's power down status to the player's "power down next round" status and sets the players status to false
|
||||||
*/
|
*/
|
||||||
private void updateRobotPowerDown(){
|
private void updateRobotPowerDown() {
|
||||||
for (Player player:playerList) {
|
for (Player player : playerList) {
|
||||||
gameBoard.setPowerDown(player.getRobotID(),player.getPowerDownNextRound());
|
setRobotPowerDown(player, player.getPowerDownNextRound());
|
||||||
player.setPowerDownNextRound(false);
|
player.setPowerDownNextRound(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets the powerdown status of a robots
|
* Sets the power down status of a robot
|
||||||
* @param player the player that owns the robot
|
* @param player The player that owns the robot
|
||||||
* @param powerdownStatus the powerdown status
|
* @param powerDownStatus The new power down status
|
||||||
*/
|
*/
|
||||||
private void setRobotPowerDown(Player player,Boolean powerdownStatus){
|
private void setRobotPowerDown(Player player, Boolean powerDownStatus) {
|
||||||
gameBoard.setPowerDown(player.getRobotID(),powerdownStatus);
|
gameBoard.setPowerDown(player.getRobotID(), powerDownStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user