mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 23:59:44 +01:00
added NextPlayerTurn
This commit is contained in:
parent
15f5f91ddb
commit
559afcaffd
@ -0,0 +1,8 @@
|
|||||||
|
package pp.monopoly.game.client;
|
||||||
|
|
||||||
|
public class ActiveState extends ClientState{
|
||||||
|
|
||||||
|
ActiveState(ClientGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ import pp.monopoly.message.server.EventDrawCard;
|
|||||||
import pp.monopoly.message.server.GameOver;
|
import pp.monopoly.message.server.GameOver;
|
||||||
import pp.monopoly.message.server.GameStart;
|
import pp.monopoly.message.server.GameStart;
|
||||||
import pp.monopoly.message.server.JailEvent;
|
import pp.monopoly.message.server.JailEvent;
|
||||||
|
import pp.monopoly.message.server.NextPlayerTurn;
|
||||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||||
import pp.monopoly.message.server.ServerInterpreter;
|
import pp.monopoly.message.server.ServerInterpreter;
|
||||||
import pp.monopoly.message.server.TimeOutWarning;
|
import pp.monopoly.message.server.TimeOutWarning;
|
||||||
@ -54,9 +55,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
private final List<GameEventListener> listeners = new ArrayList<>();
|
private final List<GameEventListener> listeners = new ArrayList<>();
|
||||||
private Board board;
|
private Board board;
|
||||||
|
|
||||||
private ClientState state = new ClientState(this) {
|
private ClientState state = new LobbyState(this);
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a ClientGameLogic with the specified sender object.
|
* Constructs a ClientGameLogic with the specified sender object.
|
||||||
@ -257,4 +256,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
|||||||
public void received(TradeRequest msg) {
|
public void received(TradeRequest msg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(NextPlayerTurn msg) {
|
||||||
|
state = new ActiveState(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package pp.monopoly.game.client;
|
||||||
|
|
||||||
|
public class LobbyState extends ClientState{
|
||||||
|
|
||||||
|
LobbyState(ClientGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package pp.monopoly.game.client;
|
||||||
|
|
||||||
|
public class WaitForTurnState extends ClientState{
|
||||||
|
|
||||||
|
WaitForTurnState(ClientGameLogic logic) {
|
||||||
|
super(logic);
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package pp.monopoly.game.server;
|
|||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
@ -142,4 +143,11 @@ public class PlayerHandler {
|
|||||||
}
|
}
|
||||||
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arranges the players turns in a random order
|
||||||
|
*/
|
||||||
|
void randomOrder() {
|
||||||
|
Collections.shuffle(players);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import pp.monopoly.message.client.TradeOffer;
|
|||||||
import pp.monopoly.message.client.TradeResponse;
|
import pp.monopoly.message.client.TradeResponse;
|
||||||
import pp.monopoly.message.client.ViewAssetsRequest;
|
import pp.monopoly.message.client.ViewAssetsRequest;
|
||||||
import pp.monopoly.message.server.GameStart;
|
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.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;
|
||||||
@ -164,7 +166,8 @@ public class ServerGameLogic implements ClientInterpreter {
|
|||||||
Player player = playerHandler.getPlayerById(from);
|
Player player = playerHandler.getPlayerById(from);
|
||||||
if (player != null && state == ServerState.INGAME) {
|
if (player != null && state == ServerState.INGAME) {
|
||||||
LOGGER.log(Level.DEBUG, "Ending turn for player {0}", player.getName());
|
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()) {
|
for (Player p : playerHandler.getPlayers()) {
|
||||||
send(p, new GameStart(playerHandler.getPlayers()));
|
send(p, new GameStart(playerHandler.getPlayers()));
|
||||||
}
|
}
|
||||||
|
playerHandler.randomOrder();
|
||||||
|
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -89,4 +89,11 @@ public interface ServerInterpreter {
|
|||||||
* @param msg the TradeRequest message received
|
* @param msg the TradeRequest message received
|
||||||
*/
|
*/
|
||||||
void received(TradeRequest msg);
|
void received(TradeRequest msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles a NextPlayerTurn message received from the server.
|
||||||
|
*
|
||||||
|
* @param msg the NextPlayerTurn message received
|
||||||
|
*/
|
||||||
|
void received(NextPlayerTurn msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user