From 61c3a9ced64def88936b6f18a00b092d4fb1c021 Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Wed, 26 Feb 2020 20:20:46 +0100 Subject: [PATCH] =?UTF-8?q?Endret=20p=C3=A5=20Board=20slik=20at=20respawns?= =?UTF-8?q?=20fungerer.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lagt metode for respawn og for å sjekke om noe er i live. Lagt til liste for å ta vare på døde roboter. --- .../fiasko/roborally/objects/Board.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index 98ed040..775af3a 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -19,6 +19,7 @@ public class Board { private IGrid walls; private IGrid tiles; private Map robots; + private List deadRobots; /** * Initializes the board @@ -41,6 +42,7 @@ public class Board { this.boardHeight = tiles.getHeight(); this.walls = walls; this.tiles = tiles; + this.deadRobots = new ArrayList<>(); } /** @@ -207,6 +209,7 @@ public class Board { private void killRobot(Robot robot) { robot.setAmountOfLives(robot.getAmountOfLives() - 1); removeDeadRobotFromBoard(robot); + deadRobots.add(robot); } /** @@ -289,4 +292,28 @@ public class Board { } return elements; } + + /** + * Moves all dead robots to their backups and makes them part of the board again, and if a robot has no lives + * it will be removed from the game. + */ + public void respawnRobots() { + for (Robot robot : deadRobots) { + if (robot.getAmountOfLives() > 0) { + robot.setPosition(robot.getBackupPosition()); + robot.setFacingDirection(Direction.NORTH); + robots.put(robot.getRobotId(), robot); + } + else { + deadRobots.remove(robot); + } + } + } + + /** + * Checks if a specific robot is currently alive on the board + * @param robot the ID of the robot you want to check + * @return True/False based on if the robot was found. + */ + public boolean isRobotAlive(RobotID robot) { return robots.containsKey(robot); } }