From b7e349eb3f8b77a7959b040af5ae8446e0bcc9cb Mon Sep 17 00:00:00 2001 From: Steinar Aalstad Lillesund Date: Tue, 25 Feb 2020 15:48:34 +0100 Subject: [PATCH] =?UTF-8?q?Endret=20sm=C3=A5=20feil=20i=20Board=20og=20Rob?= =?UTF-8?q?ot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Laget også test for board --- .../inf112/fiasko/roborally/objects/Board.java | 4 ++-- .../inf112/fiasko/roborally/objects/Robot.java | 15 +++++++++++++++ .../fiasko/roborally/objects/BoardTest.java | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/inf112/fiasko/roborally/objects/Board.java b/src/main/java/inf112/fiasko/roborally/objects/Board.java index cb51edf..26721bb 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Board.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Board.java @@ -65,9 +65,9 @@ public class Board { * Moves all dead robots to their backups and makes them part of the board again */ public void respawnRobots() { - //TODO: Account for several robots re-spawning at same backup for (Robot robot : deadRobots) { robot.setPosition(robot.getBackupPosition()); + robot.setFacingDirection(Direction.NORTH); robots.put(robot.getRobotId(), robot); } deadRobots = new ArrayList<>(); @@ -212,7 +212,7 @@ public class Board { * @param robot The robot to kill */ private void killRobot(Robot robot) { - //TODO: Must remove a life from the robot/player + robot.setAmountOfLives(robot.getAmountOfLives() - 1); removeDeadRobotFromBoard(robot); } diff --git a/src/main/java/inf112/fiasko/roborally/objects/Robot.java b/src/main/java/inf112/fiasko/roborally/objects/Robot.java index be9ef0a..596ea0a 100644 --- a/src/main/java/inf112/fiasko/roborally/objects/Robot.java +++ b/src/main/java/inf112/fiasko/roborally/objects/Robot.java @@ -8,6 +8,7 @@ import inf112.fiasko.roborally.element_properties.RobotID; * This class represents a robot */ public class Robot { + private int amountOfLives = 3; private int robotDamageTaken = 0; private final RobotID robotId; private boolean inPowerDown = false; @@ -128,4 +129,18 @@ public class Robot { } this.facingDirection = newFacingDirection; } + + /** + * Sets the amount if life the robot has left + * @param amountOfLives the new amount if lives the robot has left + */ + public void setAmountOfLives(int amountOfLives) { + this.amountOfLives = amountOfLives; + } + + /** + * Gets the amount of life a robot has left. + * @return amount of life left + */ + public int getAmountOfLives() { return this.amountOfLives; } } diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index 05b1c72..51ab146 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -94,4 +94,12 @@ public class BoardTest { robotList.add(robot); new Board(tileGrid, wallGrid, robotList); } + @Test + public void killRobotReducesAmountOfLivesByOne () { + Robot robot = board.getAliveRobots().get(0); + for (int i = 0; i < 3; i++) { + board.moveRobot(robot.getRobotId(), Direction.SOUTH); + } + assertEquals(2, robot.getAmountOfLives()); + } }