mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 13:59:45 +01:00
added serialisables
This commit is contained in:
parent
ed105f1b70
commit
362c0e5679
@ -5,7 +5,7 @@ import java.lang.System.Logger.Level;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.message.client.ClientMessage;
|
||||
import pp.monopoly.message.server.BuyPropertyResponse;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
@ -52,7 +52,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
/** The current state of the client game logic. */
|
||||
private ClientState state = new LobbyState(this);
|
||||
|
||||
private PlayerHandler playerHandler;
|
||||
private List<Player> players;
|
||||
|
||||
private BoardManager boardManager = new BoardManager();
|
||||
|
||||
@ -94,8 +94,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
state.entry();
|
||||
}
|
||||
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return playerHandler;
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -255,7 +255,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(GameStart msg) {
|
||||
playerHandler = msg.getPlayerHandler();
|
||||
players = msg.getPlayers();
|
||||
setInfoText("The game has started! Good luck!");
|
||||
setState(new WaitForTurnState(this));
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ package pp.monopoly.game.server;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
@ -28,6 +30,7 @@ import pp.monopoly.model.fields.WacheField;
|
||||
/**
|
||||
* Class representing a player
|
||||
*/
|
||||
@Serializable
|
||||
public class Player implements FieldVisitor<Void>{
|
||||
private final int id;
|
||||
private String name;
|
||||
@ -40,6 +43,14 @@ public class Player implements FieldVisitor<Void>{
|
||||
private final PlayerHandler handler;
|
||||
private PlayerState state = new LobbyState();
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private Player(){
|
||||
id = 0;
|
||||
handler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a player with the speciefied params
|
||||
* @param id the id of the player
|
||||
|
@ -8,10 +8,13 @@ import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.model.LimitedLinkedList;
|
||||
/**
|
||||
* A class for helping with player actions and managing thier turns
|
||||
*/
|
||||
@Serializable
|
||||
public class PlayerHandler {
|
||||
private List<Player> players = new LimitedLinkedList<>(6);
|
||||
private Set<Player> readyPlayers = new HashSet<>();
|
||||
@ -19,6 +22,11 @@ public class PlayerHandler {
|
||||
private Player hostPlayer;
|
||||
private Player extra = null;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private PlayerHandler() {}
|
||||
|
||||
/**
|
||||
* Contructs a PlayerHandler
|
||||
* @param logic the {@link ServerGameLogic} this PlayerHandler is a part of
|
||||
|
@ -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));
|
||||
send(p, new GameStart(playerHandler.getPlayers()));
|
||||
}
|
||||
playerHandler.randomOrder();
|
||||
send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn(playerHandler.getPlayerAtIndex(0)));
|
||||
|
@ -1,25 +1,27 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.Player;
|
||||
|
||||
@Serializable
|
||||
public class GameStart extends ServerMessage{
|
||||
|
||||
private PlayerHandler ph;
|
||||
private List<Player> players;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private GameStart() { /* empty */ }
|
||||
|
||||
public GameStart(PlayerHandler ph) {
|
||||
this.ph = ph;
|
||||
public GameStart(List<Player> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
public PlayerHandler getPlayerHandler() {
|
||||
return ph;
|
||||
public List<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,9 +4,12 @@ import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
import static java.lang.Math.min;
|
||||
|
||||
@Serializable
|
||||
public class Figure implements Item{
|
||||
private final String type;
|
||||
private final int length; // The length of the Figure
|
||||
|
@ -2,14 +2,22 @@ package pp.monopoly.model;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A LinkedList with a maximum size limit.
|
||||
*
|
||||
* @param <E> the type of elements held in this collection
|
||||
*/
|
||||
@Serializable
|
||||
public class LimitedLinkedList<E> extends LinkedList<E> {
|
||||
|
||||
private final int maxSize;
|
||||
private int maxSize;
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private LimitedLinkedList() {}
|
||||
|
||||
/**
|
||||
* Constructs a LimitedLinkedList with the specified maximum size.
|
||||
|
@ -26,6 +26,7 @@ import com.jme3.network.serializing.Serializer;
|
||||
|
||||
import pp.monopoly.MonopolyConfig;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.game.server.ServerGameLogic;
|
||||
import pp.monopoly.game.server.ServerSender;
|
||||
import pp.monopoly.message.client.BuyPropertyRequest;
|
||||
@ -36,8 +37,12 @@ import pp.monopoly.message.client.RollDice;
|
||||
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.ServerMessage;
|
||||
import pp.monopoly.model.Figure;
|
||||
import pp.monopoly.model.IntPoint;
|
||||
import pp.monopoly.model.LimitedLinkedList;
|
||||
|
||||
/**
|
||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||
@ -119,6 +124,12 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeOffer.class);
|
||||
Serializer.registerClass(TradeResponse.class);
|
||||
Serializer.registerClass(ViewAssetsRequest.class);
|
||||
Serializer.registerClass(GameStart.class);
|
||||
Serializer.registerClass(LimitedLinkedList.class);
|
||||
Serializer.registerClass(NextPlayerTurn.class);
|
||||
Serializer.registerClass(Player.class);
|
||||
Serializer.registerClass(Figure.class);
|
||||
Serializer.registerClass(PlayerHandler.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
Loading…
Reference in New Issue
Block a user