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