send GameStart message with a list of all Players

This commit is contained in:
Johannes Schmelz 2024-11-20 01:45:34 +01:00
parent f11f4a59f1
commit cdce478d77
3 changed files with 29 additions and 0 deletions

View File

@ -50,6 +50,14 @@ public class PlayerHandler {
return players.size(); return players.size();
} }
/**
* Retuns all players
* @return List of all players
*/
public List<Player> getPlayers() {
return players;
}
/** /**
* Chechs if all players are ready to start the game * Chechs if all players are ready to start the game
* @return {@code true} if all players are ready, otherwise {@code false} * @return {@code true} if all players are ready, otherwise {@code false}

View File

@ -2,6 +2,7 @@ package pp.monopoly.game.server;
import pp.monopoly.MonopolyConfig; import pp.monopoly.MonopolyConfig;
import pp.monopoly.message.client.*; import pp.monopoly.message.client.*;
import pp.monopoly.message.server.GameStart;
import pp.monopoly.message.server.ServerMessage; import pp.monopoly.message.server.ServerMessage;
import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeReply;
import pp.monopoly.message.server.TradeRequest; import pp.monopoly.message.server.TradeRequest;
@ -177,6 +178,12 @@ public class ServerGameLogic implements ClientInterpreter {
playerHandler.setPlayerReady(player, true); playerHandler.setPlayerReady(player, true);
LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName()); LOGGER.log(Level.DEBUG, "Player {0} is ready", player.getName());
} }
if(playerHandler.allPlayersReady()) {
for (Player p : playerHandler.getPlayers()) {
send(p, new GameStart(playerHandler.getPlayers()));
}
}
} }
/** /**

View File

@ -1,7 +1,21 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import java.util.List;
import pp.monopoly.game.server.Player;
public class GameStart extends ServerMessage{ public class GameStart extends ServerMessage{
private final List<Player> players;
public GameStart(List<Player> players) {
this.players = players;
}
public List<Player> getPlayers() {
return players;
}
@Override @Override
public void accept(ServerInterpreter interpreter) { public void accept(ServerInterpreter interpreter) {
interpreter.received(this); interpreter.received(this);