Updated 'LobbyState' class.
Updated the 'LobbyState' class by adding 'initializeGame' method to it.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import pp.mdga.game.Color;
|
import pp.mdga.game.Color;
|
||||||
import pp.mdga.game.Player;
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.game.PlayerData;
|
||||||
import pp.mdga.message.client.*;
|
import pp.mdga.message.client.*;
|
||||||
import pp.mdga.message.server.*;
|
import pp.mdga.message.server.*;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
@@ -43,6 +44,15 @@ public void exit() {
|
|||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited LobbyState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited LobbyState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will be used to initialize the game and all necessary objects.
|
||||||
|
*/
|
||||||
|
public void initializeGame() {
|
||||||
|
for (Map.Entry<Integer, Player> entry: this.logic.getGame().getPlayers().entrySet()) {
|
||||||
|
this.logic.getGame().getBoard().addPlayerData(entry.getValue().getColor(), new PlayerData(entry.getValue().getColor()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be called whenever the server received a JoinedLobbyMessage message.
|
* This method will be called whenever the server received a JoinedLobbyMessage message.
|
||||||
* It will also get the client id of the player who send this message
|
* It will also get the client id of the player who send this message
|
||||||
@@ -110,6 +120,7 @@ public void received(LobbyReadyMessage msg, int from) {
|
|||||||
|
|
||||||
this.logic.getGame().setAllReady(true);
|
this.logic.getGame().setAllReady(true);
|
||||||
if (this.logic.getGame().allReady()) {
|
if (this.logic.getGame().allReady()) {
|
||||||
|
this.initializeGame();
|
||||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,6 +163,7 @@ public void received(LeaveGameMessage msg, int from) {
|
|||||||
@Override
|
@Override
|
||||||
public void received(StartGameMessage msg, int from) {
|
public void received(StartGameMessage msg, int from) {
|
||||||
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
|
if (msg.isForceStartGame() || this.logic.getGame().allReady()) {
|
||||||
|
this.initializeGame();
|
||||||
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
this.logic.getServerSender().broadcast(new ServerStartGameMessage(this.logic.getGame().getBoard()));
|
||||||
this.logic.setCurrentState(this.logic.getGameState());
|
this.logic.setCurrentState(this.logic.getGameState());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user