mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +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
|
@Override
|
||||||
public GameState getGameState() {
|
public synchronized GameState getGameState() {
|
||||||
return gameState;
|
return gameState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
this.gameState = gameState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,9 +270,7 @@ public class RoboRallyGame implements DrawableGame, InteractableGame {
|
|||||||
// Set damage of robots in power down to 0
|
// Set damage of robots in power down to 0
|
||||||
gameBoard.executePowerDown();
|
gameBoard.executePowerDown();
|
||||||
//This check prevents the state from being overwritten if the client has already received the cards
|
//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) {
|
if (host) {
|
||||||
//Distributes programming cards for all players, and sends a deck to each player
|
//Distributes programming cards for all players, and sends a deck to each player
|
||||||
distributeProgrammingCardsToPlayers();
|
distributeProgrammingCardsToPlayers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user