mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 15:19:35 +01:00
Gjør spillet sin tilstand synkronisert for å forhindre problemer med samtidig endring
This commit is contained in:
parent
cf8fabbd72
commit
ef1a5e0e46
@ -105,12 +105,16 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameState getGameState() {
|
||||
public synchronized GameState getGameState() {
|
||||
return gameState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGameState(GameState gameState) {
|
||||
public synchronized void setGameState(GameState gameState) {
|
||||
if (gameState == GameState.WAITING_FOR_CARDS_FROM_SERVER && this.gameState != GameState.BEGINNING_OF_GAME) {
|
||||
System.out.println("Unexpected game state " + gameState + " encountered.");
|
||||
return;
|
||||
}
|
||||
this.gameState = gameState;
|
||||
}
|
||||
|
||||
@ -266,9 +270,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
||||
// Set damage of robots in power down to 0
|
||||
gameBoard.executePowerDown();
|
||||
//This check prevents the state from being overwritten if the client has already received the cards
|
||||
if (gameState == GameState.BEGINNING_OF_GAME) {
|
||||
setGameState(GameState.WAITING_FOR_CARDS_FROM_SERVER);
|
||||
}
|
||||
setGameState(GameState.WAITING_FOR_CARDS_FROM_SERVER);
|
||||
if (host) {
|
||||
//Distributes programming cards for all players, and sends a deck to each player
|
||||
distributeProgrammingCardsToPlayers();
|
||||
|
Loading…
x
Reference in New Issue
Block a user