Merge remote-tracking branch 'origin/connect' into connect

This commit is contained in:
Yvonne Schmidt 2024-11-25 02:12:01 +01:00
commit acc797f2ff
13 changed files with 119 additions and 16 deletions

View File

@ -1,12 +1,20 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
/** /**
* Represents the server's response to a player's request to buy a property. * Represents the server's response to a player's request to buy a property.
*/ */
@Serializable
public class BuyPropertyResponse extends ServerMessage{ public class BuyPropertyResponse extends ServerMessage{
private final boolean successful; private boolean successful;
private final String propertyName; private String propertyName;
private final String reason; // Reason for failure, if any private String reason; // Reason for failure, if any
/**
* Default constructor for serialization purposes.
*/
private BuyPropertyResponse() { /* empty */ }
public BuyPropertyResponse(boolean successful, String propertyName, String reason) { public BuyPropertyResponse(boolean successful, String propertyName, String reason) {
this.successful = successful; this.successful = successful;

View File

@ -2,10 +2,18 @@ package pp.monopoly.message.server;
import java.util.List; import java.util.List;
import com.jme3.network.serializing.Serializable;
@Serializable
public class DiceResult extends ServerMessage{ public class DiceResult extends ServerMessage{
private List<Integer> rollResult; private List<Integer> rollResult;
/**
* Default constructor for serialization purposes.
*/
private DiceResult() { /* empty */ }
public DiceResult(List<Integer> rollResult) { public DiceResult(List<Integer> rollResult) {
this.rollResult = rollResult; this.rollResult = rollResult;
} }

View File

@ -1,7 +1,15 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class EventDrawCard extends ServerMessage{ public class EventDrawCard extends ServerMessage{
private final String cardDescription; private String cardDescription;
/**
* Default constructor for serialization purposes.
*/
private EventDrawCard() { /* empty */ }
public EventDrawCard(String cardDescription) { public EventDrawCard(String cardDescription) {
this.cardDescription = cardDescription; this.cardDescription = cardDescription;

View File

@ -1,7 +1,15 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class GameOver extends ServerMessage{ public class GameOver extends ServerMessage{
private final boolean isWinner; private boolean isWinner;
/**
* Default constructor for serialization purposes.
*/
private GameOver() { /* empty */ }
public GameOver(boolean isWinner) { public GameOver(boolean isWinner) {
this.isWinner = isWinner; this.isWinner = isWinner;

View File

@ -1,10 +1,18 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.game.server.PlayerHandler;
@Serializable
public class GameStart extends ServerMessage{ public class GameStart extends ServerMessage{
private final PlayerHandler ph; private PlayerHandler ph;
/**
* Default constructor for serialization purposes.
*/
private GameStart() { /* empty */ }
public GameStart(PlayerHandler ph) { public GameStart(PlayerHandler ph) {
this.ph = ph; this.ph = ph;

View File

@ -1,8 +1,16 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class JailEvent extends ServerMessage{ public class JailEvent extends ServerMessage{
private final boolean goingToJail; private boolean goingToJail;
/**
* Default constructor for serialization purposes.
*/
private JailEvent() { /* empty */ }
public JailEvent(boolean goingToJail) { public JailEvent(boolean goingToJail) {
this.goingToJail = goingToJail; this.goingToJail = goingToJail;

View File

@ -1,10 +1,18 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.Player; import pp.monopoly.game.server.Player;
@Serializable
public class NextPlayerTurn extends ServerMessage{ public class NextPlayerTurn extends ServerMessage{
private final Player player; private Player player;
/**
* Default constructor for serialization purposes.
*/
private NextPlayerTurn() { /* empty */ }
public NextPlayerTurn(Player player) { public NextPlayerTurn(Player player) {
this.player = player; this.player = player;

View File

@ -1,12 +1,20 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.game.server.PlayerColor; import pp.monopoly.game.server.PlayerColor;
@Serializable
public class PlayerStatusUpdate extends ServerMessage{ public class PlayerStatusUpdate extends ServerMessage{
private final String playerName; private String playerName;
private final String status; private String status;
private final PlayerColor color; private PlayerColor color;
/**
* Default constructor for serialization purposes.
*/
private PlayerStatusUpdate() { /* empty */ }
public PlayerStatusUpdate(String playerName, String status, PlayerColor color) { public PlayerStatusUpdate(String playerName, String status, PlayerColor color) {
this.playerName = playerName; this.playerName = playerName;

View File

@ -1,8 +1,16 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
@Serializable
public class TimeOutWarning extends ServerMessage{ public class TimeOutWarning extends ServerMessage{
private final int remainingTime; private int remainingTime;
/**
* Default constructor for serialization purposes.
*/
private TimeOutWarning() { /* empty */ }
public TimeOutWarning(int remainingTime) { public TimeOutWarning(int remainingTime) {
this.remainingTime = remainingTime; this.remainingTime = remainingTime;

View File

@ -1,14 +1,22 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.TradeHandler; import pp.monopoly.model.TradeHandler;
/** /**
* Represents a response to a trade offer. * Represents a response to a trade offer.
*/ */
@Serializable
public class TradeReply extends ServerMessage{ public class TradeReply extends ServerMessage{
private int initiatorId; private int initiatorId;
private TradeHandler tradeHandler; private TradeHandler tradeHandler;
/**
* Default constructor for serialization purposes.
*/
private TradeReply() { /* empty */ }
/** /**
* Constructs a TradeResponse with the specified response details. * Constructs a TradeResponse with the specified response details.
* *

View File

@ -1,15 +1,23 @@
package pp.monopoly.message.server; package pp.monopoly.message.server;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.TradeHandler; import pp.monopoly.model.TradeHandler;
/** /**
* Represents a trade Request message from one player to another. * Represents a trade Request message from one player to another.
*/ */
@Serializable
public class TradeRequest extends ServerMessage{ public class TradeRequest extends ServerMessage{
private int receiverId; private int receiverId;
private TradeHandler tradehandler; private TradeHandler tradehandler;
/**
* Default constructor for serialization purposes.
*/
private TradeRequest() { /* empty */ }
/** /**
* Constructs a TradeRequest with the specified details. * Constructs a TradeRequest with the specified details.
* *

View File

@ -2,18 +2,26 @@ package pp.monopoly.message.server;
import java.util.List; import java.util.List;
import com.jme3.network.serializing.Serializable;
import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.PropertyField; import pp.monopoly.model.fields.PropertyField;
/** /**
* Represents a response containing the player's assets. * Represents a response containing the player's assets.
*/ */
@Serializable
public class ViewAssetsResponse extends ServerMessage{ public class ViewAssetsResponse extends ServerMessage{
private final List<PropertyField> properties; private List<PropertyField> properties;
private final BoardManager board; private BoardManager board;
private final int accountBalance; private int accountBalance;
private final int jailCards; private int jailCards;
/**
* Default constructor for serialization purposes.
*/
private ViewAssetsResponse() { /* empty */ }
/** /**
* Constructs a ViewAssetsResponse with the specified properties and account balance. * Constructs a ViewAssetsResponse with the specified properties and account balance.

View File

@ -122,6 +122,13 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
} }
private void registerListeners() { private void registerListeners() {
myServer.addMessageListener(this, BuyPropertyRequest.class);
myServer.addMessageListener(this, EndTurn.class);
myServer.addMessageListener(this, PlayerReady.class);
myServer.addMessageListener(this, RollDice.class);
myServer.addMessageListener(this, TradeOffer.class);
myServer.addMessageListener(this, TradeResponse.class);
myServer.addMessageListener(this, ViewAssetsRequest.class);
myServer.addConnectionListener(this); myServer.addConnectionListener(this);
} }