send PlayerHandler when starting game

This commit is contained in:
Johannes Schmelz 2024-11-24 16:51:00 +01:00
parent e780513b35
commit 9b4cac4e56
3 changed files with 12 additions and 14 deletions

View File

@ -5,7 +5,7 @@ import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.List;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.message.client.ClientMessage;
import pp.monopoly.message.server.BuyPropertyResponse;
import pp.monopoly.message.server.DiceResult;
@ -51,7 +51,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
/** The current state of the client game logic. */
private ClientState state = new LobbyState(this);
private List<Player> players;
private PlayerHandler playerHandler;
/**
* Constructs a ClientGameLogic with the specified sender object.
@ -83,8 +83,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
state.entry();
}
public List<Player> getPlayers() {
return players;
public PlayerHandler getPlayerHandler() {
return playerHandler;
}
/**
@ -243,7 +243,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*/
@Override
public void received(GameStart msg) {
players = msg.getPlayers();
playerHandler = msg.getPlayerHandler();
setInfoText("The game has started! Good luck!");
setState(new WaitForTurnState(this));
}

View File

@ -204,7 +204,7 @@ public class ServerGameLogic implements ClientInterpreter {
if(playerHandler.allPlayersReady()) {
playerHandler.setStartBalance(startMoney);
for (Player p : playerHandler.getPlayers()) {
send(p, new GameStart(playerHandler.getPlayers()));
send(p, new GameStart(playerHandler));
}
playerHandler.randomOrder();
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));

View File

@ -1,19 +1,17 @@
package pp.monopoly.message.server;
import java.util.List;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
public class GameStart extends ServerMessage{
private final List<Player> players;
private final PlayerHandler ph;
public GameStart(List<Player> players) {
this.players = players;
public GameStart(PlayerHandler ph) {
this.ph = ph;
}
public List<Player> getPlayers() {
return players;
public PlayerHandler getPlayerHandler() {
return ph;
}
@Override