mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Legger til korrekt kopiering av roboter for å forhindre Game i å direkte endre en robot
This commit is contained in:
parent
9101731c86
commit
1c1bbc6a79
@ -66,7 +66,9 @@ public class Board {
|
|||||||
* @return A list of alive robots
|
* @return A list of alive robots
|
||||||
*/
|
*/
|
||||||
public List<Robot> getAliveRobots() {
|
public List<Robot> getAliveRobots() {
|
||||||
return new ArrayList<>(robots.values());
|
List<Robot> robotsCopy = new ArrayList<>(robots.values());
|
||||||
|
robotsCopy.replaceAll(Robot::copy);
|
||||||
|
return robotsCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,4 +145,19 @@ public class Robot {
|
|||||||
* @return amount of life left
|
* @return amount of life left
|
||||||
*/
|
*/
|
||||||
public int getAmountOfLives() { return this.amountOfLives; }
|
public int getAmountOfLives() { return this.amountOfLives; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a copy of this robot with the same properties as this robot
|
||||||
|
* @return A copy of this robot
|
||||||
|
*/
|
||||||
|
public Robot copy() {
|
||||||
|
Robot copy = new Robot(this.robotId, this.currentPosition);
|
||||||
|
copy.facingDirection = this.facingDirection;
|
||||||
|
copy.lastFlagVisited = this.lastFlagVisited;
|
||||||
|
copy.amountOfLives = this.amountOfLives;
|
||||||
|
copy.backupPosition = this.backupPosition;
|
||||||
|
copy.inPowerDown = this.inPowerDown;
|
||||||
|
copy.robotDamageTaken = this.robotDamageTaken;
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user