mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 15:19:35 +01:00
Erstatter Objects.requireNonNull med korrekt sjekking av variabler
This commit is contained in:
parent
d473b37252
commit
8676434326
@ -177,10 +177,11 @@ public class Board {
|
||||
* @param powerDown The status of the power down
|
||||
*/
|
||||
public void setPowerDown(RobotID robotID, Boolean powerDown) {
|
||||
Robot alternateRobot = getRobotFromDeadRobots(robotID);
|
||||
if (robots.containsKey(robotID)) {
|
||||
robots.get(robotID).setPowerDown(powerDown);
|
||||
} else if (getRobotFromDeadRobots(robotID) != null) {
|
||||
Objects.requireNonNull(getRobotFromDeadRobots(robotID)).setPowerDown(powerDown);
|
||||
} else if ( alternateRobot != null) {
|
||||
alternateRobot.setPowerDown(powerDown);
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,10 +202,11 @@ public class Board {
|
||||
* @return The power down status of the robot
|
||||
*/
|
||||
public boolean getPowerDown(RobotID robotID) {
|
||||
Robot alternateRobot = getRobotFromDeadRobots(robotID);
|
||||
if (robots.containsKey(robotID)) {
|
||||
return robots.get(robotID).isInPowerDown();
|
||||
} else if (getRobotFromDeadRobots(robotID) != null) {
|
||||
return Objects.requireNonNull(getRobotFromDeadRobots(robotID)).isInPowerDown();
|
||||
} else if (alternateRobot != null) {
|
||||
return alternateRobot.isInPowerDown();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class represent a game which is drawable using libgdx
|
||||
@ -59,8 +58,9 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
||||
* @return Whether this player's robot is in power down
|
||||
*/
|
||||
public Boolean getRobotPowerDown() {
|
||||
if (getPlayerFromName(this.playerName) != null) {
|
||||
return gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID());
|
||||
Player player = getPlayerFromName(this.playerName);
|
||||
if (player != null) {
|
||||
return gameBoard.getPowerDown(player.getRobotID());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -172,7 +172,8 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
||||
removeNonLockedProgrammingCardsFromPlayers();
|
||||
}
|
||||
|
||||
if (getPlayerFromName(this.playerName) != null && gameBoard.getPowerDown(Objects.requireNonNull(getPlayerFromName(this.playerName)).getRobotID())) {
|
||||
Player player = getPlayerFromName(this.playerName);
|
||||
if (player != null && gameBoard.getPowerDown(player.getRobotID())) {
|
||||
setGameState(GameState.CHOOSING_STAY_IN_POWER_DOWN);
|
||||
} else {
|
||||
setGameState(GameState.SKIP_STAY_IN_POWER_DOWN);
|
||||
|
Loading…
x
Reference in New Issue
Block a user