Compare commits

..

4 Commits

Author SHA1 Message Date
Johannes Schmelz
559afcaffd added NextPlayerTurn 2024-11-22 01:38:48 +01:00
Johannes Schmelz
15f5f91ddb rename sound files 2024-11-22 01:02:48 +01:00
Johannes Schmelz
067a8063a5 Merge branch 'gui' of https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02 into gui 2024-11-22 00:54:13 +01:00
Johannes Schmelz
35e367ba24 added sounds 2024-11-22 00:54:09 +01:00
20 changed files with 80 additions and 4 deletions

View File

@ -0,0 +1,8 @@
package pp.monopoly.game.client;
public class ActiveState extends ClientState{
ActiveState(ClientGameLogic logic) {
super(logic);
}
}

View File

@ -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);
}
} }

View File

@ -0,0 +1,8 @@
package pp.monopoly.game.client;
public class LobbyState extends ClientState{
LobbyState(ClientGameLogic logic) {
super(logic);
}
}

View File

@ -0,0 +1,8 @@
package pp.monopoly.game.client;
public class WaitForTurnState extends ClientState{
WaitForTurnState(ClientGameLogic logic) {
super(logic);
}
}

View File

@ -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);
}
} }

View File

@ -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)));
} }
} }

View File

@ -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;
}
}

View File

@ -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);
} }