la til en metode for å sette respawn position til roboten

This commit is contained in:
Tobydrama 2020-04-20 18:03:47 +02:00
parent d8acbc661d
commit 597215910e
2 changed files with 31 additions and 2 deletions

View File

@ -164,7 +164,15 @@ public class Board {
* @param powerDown The status of the power down
*/
public void setPowerDown(RobotID robotID, Boolean powerDown) {
robots.get(robotID).setPowerDown(powerDown);
if(robots.containsKey(robotID)){
robots.get(robotID).setPowerDown(powerDown);
}
else {
getRobotFromDeadRobots(robotID).setPowerDown(powerDown);
}
}
public void setBackupPositionOfRobot(RobotID robotID, Position pos){
robots.get(robotID).setBackupPosition(pos);
}
/**
@ -173,7 +181,20 @@ public class Board {
* @return The power down status of the robot
*/
public boolean getPowerDown(RobotID robotID) {
return robots.get(robotID).isInPowerDown();
if(robots.containsKey(robotID)){
return robots.get(robotID).isInPowerDown();
}
else {
return getRobotFromDeadRobots(robotID).isInPowerDown();
}
}
private Robot getRobotFromDeadRobots(RobotID robotID){
for (Robot robot:deadRobots) {
if (robot.getRobotId()==robotID){
return robot;
}
}
return null;
}
/**

View File

@ -31,6 +31,14 @@ public class Robot {
this.facingDirection = Direction.NORTH;
}
/**
* setBackupPosition
* @param backupPosition
*/
public void setBackupPosition(Position backupPosition) {
this.backupPosition = backupPosition;
}
/**
* True if the robot has touched a flag in the current turn
*