From 57291efadd5e3ce5448f3fa6818f3b8118936360 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Wed, 22 Apr 2020 12:39:53 +0200 Subject: [PATCH] =?UTF-8?q?Gj=C3=B8r=20det=20mulig=20=C3=A5=20hente=20ut?= =?UTF-8?q?=20alle=20roboter=20fra=20spillet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fiasko/roborally/objects/Board.java | 12 +++++ .../roborally/objects/DrawableGame.java | 7 +++ .../roborally/objects/InteractableGame.java | 2 +- .../roborally/objects/RoboRallyGame.java | 49 ++++++------------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 0b633f2..c4a83af 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -90,6 +90,18 @@ public class Board { return robotsCopy; } + /** + * Gets all robots from the board + * + * @return A list of robots + */ + public List getAllRobots() { + List robotsCopy = new ArrayList<>(robots.values()); + robotsCopy.addAll(deadRobots); + robotsCopy.replaceAll(Robot::copy); + return robotsCopy; + } + /** * Gets all the tiles from the board * diff --git a/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java b/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java index 2faf1be..f8cef82 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/DrawableGame.java @@ -58,6 +58,13 @@ public interface DrawableGame { */ List getRobotsToDraw(); + /** + * Gets a list of all robots still participating + * + * @return A list of all robots + */ + List getAllRobots(); + /** * Gets a list of active players to receive information about player names * diff --git a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java index ca72e22..4856669 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/InteractableGame.java @@ -11,7 +11,7 @@ import java.util.List; */ 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 */ diff --git a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java index 53bd5ef..63f3f77 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java +++ b/src/main/java/inf112/fiasko/roborally/objects/RoboRallyGame.java @@ -34,37 +34,6 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { private ProgrammingCardDeck playerHand; 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 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 * @@ -84,6 +53,13 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { 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 public int getWidth() { return gameBoard.getBoardWidth(); @@ -114,6 +90,11 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { return gameBoard.getAliveRobots(); } + @Override + public List getAllRobots() { + return gameBoard.getAllRobots(); + } + @Override public List getPlayers() { return new ArrayList<>(this.playerList); @@ -186,17 +167,17 @@ public class RoboRallyGame implements DrawableGame, InteractableGame { 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); } else { - setGameState(GameState.LOADING); + setGameState(GameState.SKIP_STAY_IN_POWER_DOWN); } } @Override public void receiveStayInPowerDown(PowerDownContainer powerDowns) { for (Player player : playerList) { - if(gameBoard.getPowerDown(player.getRobotID())) { + if (gameBoard.getPowerDown(player.getRobotID())) { player.setPowerDownNextRound(powerDowns.getPowerDown().get(player.getName())); } }