Gjør det mulig å hente ut alle roboter fra spillet

This commit is contained in:
Kristian Knarvik 2020-04-22 12:39:53 +02:00
parent 339bec8edd
commit 57291efadd
4 changed files with 35 additions and 35 deletions

View File

@ -90,6 +90,18 @@ public class Board {
return robotsCopy; return robotsCopy;
} }
/**
* Gets all robots from the board
*
* @return A list of robots
*/
public List<Robot> getAllRobots() {
List<Robot> robotsCopy = new ArrayList<>(robots.values());
robotsCopy.addAll(deadRobots);
robotsCopy.replaceAll(Robot::copy);
return robotsCopy;
}
/** /**
* Gets all the tiles from the board * Gets all the tiles from the board
* *

View File

@ -58,6 +58,13 @@ public interface DrawableGame {
*/ */
List<Robot> getRobotsToDraw(); List<Robot> getRobotsToDraw();
/**
* Gets a list of all robots still participating
*
* @return A list of all robots
*/
List<Robot> getAllRobots();
/** /**
* Gets a list of active players to receive information about player names * Gets a list of active players to receive information about player names
* *

View File

@ -11,7 +11,7 @@ import java.util.List;
*/ */
public interface InteractableGame { public interface InteractableGame {
/** /**
* Gets the current state og the game * Gets the current state of the game
* *
* @return The state the game is currently in * @return The state the game is currently in
*/ */

View File

@ -34,37 +34,6 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
private ProgrammingCardDeck playerHand; private ProgrammingCardDeck playerHand;
private Phase phase; private Phase phase;
public Boolean getRobotPowerdown(){
if(getPlayerFromName(this.playerName)!=null){
return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID());
}
return false;
}
/**
* Instantiates a new Robo Rally game
*
* @param playerList A list of all the players participating in the game
* @param boardName The playerName of the board to use
* @param host Whether this player is the host
* @param playerName The name of the player of this instance of the game
* @param server The server if this player is host. Should be null otherwise
* @param debug Whether this game is to use the debugging board
*/
public RoboRallyGame(List<Player> playerList, String boardName, boolean host, String playerName,
RoboRallyServer server, boolean debug) {
this.playerName = playerName;
this.host = host;
this.playerList = playerList;
this.server = server;
if (debug) {
initializeDebugMode();
} else {
initializeGame(boardName);
}
this.phase = new Phase(gameBoard, playerList, 600, this);
}
/** /**
* Instantiates a new Robo Rally game * Instantiates a new Robo Rally game
* *
@ -84,6 +53,13 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
this.phase = new Phase(gameBoard, playerList, 600, this); this.phase = new Phase(gameBoard, playerList, 600, this);
} }
public Boolean getRobotPowerdown() {
if (getPlayerFromName(this.playerName) != null) {
return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID());
}
return false;
}
@Override @Override
public int getWidth() { public int getWidth() {
return gameBoard.getBoardWidth(); return gameBoard.getBoardWidth();
@ -114,6 +90,11 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
return gameBoard.getAliveRobots(); return gameBoard.getAliveRobots();
} }
@Override
public List<Robot> getAllRobots() {
return gameBoard.getAllRobots();
}
@Override @Override
public List<Player> getPlayers() { public List<Player> getPlayers() {
return new ArrayList<>(this.playerList); return new ArrayList<>(this.playerList);
@ -186,17 +167,17 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
removeNonLockedProgrammingCardsFromPlayers(); removeNonLockedProgrammingCardsFromPlayers();
} }
if (getPlayerFromName(this.playerName)!=null&& gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID())) { if (getPlayerFromName(this.playerName) != null && gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID())) {
setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN); setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN);
} else { } else {
setGameState(GameState.LOADING); setGameState(GameState.SKIP_STAY_IN_POWER_DOWN);
} }
} }
@Override @Override
public void receiveStayInPowerDown(PowerDownContainer powerDowns) { public void receiveStayInPowerDown(PowerDownContainer powerDowns) {
for (Player player : playerList) { for (Player player : playerList) {
if(gameBoard.getPowerDown(player.getRobotID())) { if (gameBoard.getPowerDown(player.getRobotID())) {
player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName()));
} }
} }