diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ActiveState.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ActiveState.java new file mode 100644 index 0000000..78dfed1 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ActiveState.java @@ -0,0 +1,8 @@ +package pp.monopoly.game.client; + +public class ActiveState extends ClientState{ + + ActiveState(ClientGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index f972be6..2cb6ca8 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -21,6 +21,7 @@ import pp.monopoly.message.server.EventDrawCard; import pp.monopoly.message.server.GameOver; import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.JailEvent; +import pp.monopoly.message.server.NextPlayerTurn; import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.message.server.ServerInterpreter; import pp.monopoly.message.server.TimeOutWarning; @@ -54,9 +55,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { private final List listeners = new ArrayList<>(); private Board board; - private ClientState state = new ClientState(this) { - - }; + private ClientState state = new LobbyState(this); /** * Constructs a ClientGameLogic with the specified sender object. @@ -256,5 +255,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { @Override public void received(TradeRequest msg) { } + + @Override + public void received(NextPlayerTurn msg) { + state = new ActiveState(this); + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/LobbyState.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/LobbyState.java new file mode 100644 index 0000000..5fc6bd0 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/LobbyState.java @@ -0,0 +1,8 @@ +package pp.monopoly.game.client; + +public class LobbyState extends ClientState{ + + LobbyState(ClientGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/WaitForTurnState.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/WaitForTurnState.java new file mode 100644 index 0000000..d6c6407 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/WaitForTurnState.java @@ -0,0 +1,8 @@ +package pp.monopoly.game.client; + +public class WaitForTurnState extends ClientState{ + + WaitForTurnState(ClientGameLogic logic) { + super(logic); + } +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index 3cbe272..b92d4e7 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -2,6 +2,7 @@ package pp.monopoly.game.server; import java.util.LinkedList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.NoSuchElementException; @@ -142,4 +143,11 @@ public class PlayerHandler { } throw new NoSuchElementException("Player mit id "+id+" existiert nicht"); } + + /** + * Arranges the players turns in a random order + */ + void randomOrder() { + Collections.shuffle(players); + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index a1f61e8..2f13f59 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -13,6 +13,8 @@ import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.ViewAssetsRequest; import pp.monopoly.message.server.GameStart; +import pp.monopoly.message.server.NextPlayerTurn; +import pp.monopoly.message.server.PlayerStatusUpdate; import pp.monopoly.message.server.ServerMessage; import pp.monopoly.message.server.TradeReply; import pp.monopoly.message.server.TradeRequest; @@ -164,7 +166,8 @@ public class ServerGameLogic implements ClientInterpreter { Player player = playerHandler.getPlayerById(from); if (player != null && state == ServerState.INGAME) { LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName()); - playerHandler.nextPlayer(); + Player next = playerHandler.nextPlayer(); + send(next, new NextPlayerTurn(next)); } } @@ -187,6 +190,8 @@ public class ServerGameLogic implements ClientInterpreter { for (Player p : playerHandler.getPlayers()) { send(p, new GameStart(playerHandler.getPlayers())); } + playerHandler.randomOrder(); + send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0))); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java new file mode 100644 index 0000000..f047f90 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/NextPlayerTurn.java @@ -0,0 +1,28 @@ +package pp.monopoly.message.server; + +import pp.monopoly.game.server.Player; + +public class NextPlayerTurn extends ServerMessage{ + + private final Player player; + + public NextPlayerTurn(Player player) { + this.player = player; + } + + @Override + public void accept(ServerInterpreter interpreter) { + interpreter.received(this); + } + + @Override + public String getInfoTextKey() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'"); + } + + public Player getPlayer() { + return player; + } + +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java index 1f78ba7..4817e2a 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/ServerInterpreter.java @@ -89,4 +89,11 @@ public interface ServerInterpreter { * @param msg the TradeRequest message received */ void received(TradeRequest msg); + + /** + * Handles a NextPlayerTurn message received from the server. + * + * @param msg the NextPlayerTurn message received + */ + void received(NextPlayerTurn msg); }