Endret små feil i Board og Robot

Laget også test for board
This commit is contained in:
Steinar Aalstad Lillesund 2020-02-25 15:48:34 +01:00
parent bac6645342
commit b7e349eb3f
3 changed files with 25 additions and 2 deletions

View File

@ -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);
}

View File

@ -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; }
}

View File

@ -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());
}
}