deleted server state automaton
This commit is contained in:
@@ -2,34 +2,6 @@
|
||||
|
||||
import pp.mdga.game.Game;
|
||||
import pp.mdga.message.client.ClientMessage;
|
||||
import pp.mdga.message.server.ActivePlayer;
|
||||
import pp.mdga.message.server.AnyPiece;
|
||||
import pp.mdga.message.server.Briefing;
|
||||
import pp.mdga.message.server.CeremonyMessage;
|
||||
import pp.mdga.message.server.Dice;
|
||||
import pp.mdga.message.server.DiceAgain;
|
||||
import pp.mdga.message.server.DiceNow;
|
||||
import pp.mdga.message.server.EndOfTurn;
|
||||
import pp.mdga.message.server.LobbyAccept;
|
||||
import pp.mdga.message.server.LobbyDeny;
|
||||
import pp.mdga.message.server.LobbyPlayerJoin;
|
||||
import pp.mdga.message.server.LobbyPlayerLeave;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.message.server.NoTurn;
|
||||
import pp.mdga.message.server.PauseGame;
|
||||
import pp.mdga.message.server.PlayCard;
|
||||
import pp.mdga.message.server.PossibleCard;
|
||||
import pp.mdga.message.server.PossiblePiece;
|
||||
import pp.mdga.message.server.RankingResponse;
|
||||
import pp.mdga.message.server.RankingRollAgain;
|
||||
import pp.mdga.message.server.ReconnectBriefing;
|
||||
import pp.mdga.message.server.ResumeGame;
|
||||
import pp.mdga.message.server.ServerInterpreter;
|
||||
import pp.mdga.message.server.ServerStartGame;
|
||||
import pp.mdga.message.server.StartPiece;
|
||||
import pp.mdga.message.server.UpdateReady;
|
||||
import pp.mdga.message.server.UpdateTSK;
|
||||
import pp.mdga.message.server.WaitPiece;
|
||||
|
||||
public class ClientGameLogic implements ServerInterpreter {
|
||||
static final System.Logger LOGGER = System.getLogger(ClientGameLogic.class.getName());
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import pp.mdga.server.Observer;
|
||||
|
||||
/**
|
||||
* The Game class represents the game state of the Ludo game.
|
||||
* It contains all the information needed to play the game.
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
/**
|
||||
* A message sent by the server to inform the clients about the active player.
|
||||
*/
|
||||
@Serializable
|
||||
public class ActivePlayer extends ServerMessage {
|
||||
/**
|
||||
* The color of the active player.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor for ActivePlayer
|
||||
*
|
||||
* @param color the color of the active player
|
||||
*/
|
||||
public ActivePlayer(Color color) {
|
||||
super();
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private ActivePlayer() {
|
||||
color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the color of the active player
|
||||
*
|
||||
* @return the color of the active player
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ActivePlayer{color=" + color + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the informational text associated with this message.
|
||||
*
|
||||
* @return the key for the informational text
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player containing a list of pieces that the player can move any piece of the list on the board.
|
||||
*/
|
||||
@Serializable
|
||||
public class AnyPiece extends ServerMessage {
|
||||
/**
|
||||
* The list of pieces
|
||||
*/
|
||||
private final ArrayList<String> piece;
|
||||
|
||||
/**
|
||||
* Constructor for AnyPiece
|
||||
*/
|
||||
public AnyPiece() {
|
||||
super();
|
||||
piece = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a piece to the list of pieces
|
||||
*
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addPiece(String piece) {
|
||||
this.piece.add(piece);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the list of pieces
|
||||
*
|
||||
* @return the list of pieces
|
||||
*/
|
||||
public List<String> getPiece() {
|
||||
return piece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AnyPiece{piece=" + piece + '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the reconnected player to provide a briefing about the current game state.
|
||||
*/
|
||||
@Serializable
|
||||
public class Briefing extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new Briefing instance.
|
||||
*/
|
||||
public Briefing() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate the beginning of the ceremony.
|
||||
*/
|
||||
@Serializable
|
||||
public class CeremonyMessage extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new Ceremony instance.
|
||||
*/
|
||||
public CeremonyMessage() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the client to inform about the dice roll.
|
||||
*/
|
||||
@Serializable
|
||||
public class Dice extends ServerMessage {
|
||||
/**
|
||||
* The eye of the dice
|
||||
*/
|
||||
private final int diceEye;
|
||||
|
||||
/**
|
||||
* The pieces that can be moved
|
||||
*/
|
||||
private final List<String> moveablePieces;
|
||||
|
||||
/**
|
||||
* Constructor for Dice
|
||||
*
|
||||
* @param diceEye the eye of the dice
|
||||
* @param moveablePieces the pieces that can be moved
|
||||
*/
|
||||
public Dice(int diceEye, List<String> moveablePieces) {
|
||||
super();
|
||||
this.diceEye = diceEye;
|
||||
this.moveablePieces = moveablePieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private Dice() {
|
||||
diceEye = 0;
|
||||
moveablePieces = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for inactivePlayer
|
||||
*
|
||||
* @param diceEye the eye of the dice
|
||||
* @return a new Dice object
|
||||
*/
|
||||
public static Dice inactivePlayer(int diceEye) {
|
||||
return new Dice(diceEye, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for activePlayer
|
||||
*
|
||||
* @param diceEye the eye of the dice
|
||||
* @param moveablePieces the pieces that can be moved
|
||||
* @return a new Dice object
|
||||
*/
|
||||
public static Dice activePlayer(int diceEye, List<String> moveablePieces) {
|
||||
return new Dice(diceEye, moveablePieces);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the eye of the dice
|
||||
*
|
||||
* @return the eye of the dice
|
||||
*/
|
||||
public int getDiceEye() {
|
||||
return diceEye;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the pieces that can be moved
|
||||
*
|
||||
* @return the pieces that can be moved
|
||||
*/
|
||||
public List<String> getMoveablePieces() {
|
||||
return moveablePieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to indicate that they can roll the dice again.
|
||||
*/
|
||||
@Serializable
|
||||
public class DiceAgain extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new DiceAgain instance.
|
||||
*/
|
||||
public DiceAgain() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to enable the dice now button.
|
||||
*/
|
||||
@Serializable
|
||||
public class DiceNow extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new DiceNow instance.
|
||||
*/
|
||||
public DiceNow() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate the end of the turn of the active player.
|
||||
*/
|
||||
@Serializable
|
||||
public class EndOfTurn extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new EndOfTurn instance.
|
||||
*/
|
||||
public EndOfTurn() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate that the client has been accepted into the lobby.
|
||||
*/
|
||||
@Serializable
|
||||
public class LobbyAccept extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new LobbyAccept instance.
|
||||
*/
|
||||
public LobbyAccept() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to deny a client's request to join the lobby.
|
||||
*/
|
||||
@Serializable
|
||||
public class LobbyDeny extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new LobbyDeny instance.
|
||||
*/
|
||||
public LobbyDeny() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent from the server to the client indicating that a player has joined the lobby.
|
||||
*/
|
||||
@Serializable
|
||||
public class LobbyPlayerJoin extends ServerMessage {
|
||||
|
||||
/**
|
||||
* The name of the player joining the lobby.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructs a new LobbyPlayerJoin instance with the specified player name.
|
||||
*
|
||||
* @param name the name of the player joining the lobby
|
||||
*/
|
||||
public LobbyPlayerJoin(String name) {
|
||||
super();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private LobbyPlayerJoin() {
|
||||
name = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the player joining the lobby.
|
||||
*
|
||||
* @return the name of the player joining the lobby
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate that a player has left the lobby.
|
||||
*/
|
||||
@Serializable
|
||||
public class LobbyPlayerLeave extends ServerMessage {
|
||||
/**
|
||||
* The name of the player leaving the lobby.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The color associated with the player leaving the lobby.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructs a new LobbyPlayerLeave instance with the specified player name and color.
|
||||
*
|
||||
* @param name the name of the player leaving the lobby
|
||||
* @param color the color associated with the player leaving the lobby
|
||||
*/
|
||||
public LobbyPlayerLeave(String name, Color color) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private LobbyPlayerLeave() {
|
||||
name = null;
|
||||
color = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the player leaving the lobby.
|
||||
*
|
||||
* @return the name of the player leaving the lobby
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the color associated with the player leaving the lobby.
|
||||
*
|
||||
* @return the color associated with the player leaving the lobby
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the client to move a piece on the board.
|
||||
*/
|
||||
@Serializable
|
||||
public class MoveMessage extends ServerMessage {
|
||||
/**
|
||||
* The identifier of the piece that should be moved.
|
||||
*/
|
||||
private final String pieceIdentifier;
|
||||
|
||||
/**
|
||||
* Constructs a new MoveMessage instance.
|
||||
*
|
||||
* @param identifier the identifier of the piece that should be moved
|
||||
*/
|
||||
public MoveMessage(String identifier) {
|
||||
super();
|
||||
this.pieceIdentifier = identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private MoveMessage() {
|
||||
pieceIdentifier = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the piece that should be moved.
|
||||
*
|
||||
* @return the identifier of the piece that should be moved
|
||||
*/
|
||||
public String getIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to indicate that he has no valid moves.
|
||||
*/
|
||||
@Serializable
|
||||
public class NoTurn extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new NoTurn instance.
|
||||
*/
|
||||
public NoTurn() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to indicate that the game is paused.
|
||||
*/
|
||||
@Serializable
|
||||
public class PauseGame extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new PauseGame instance.
|
||||
*/
|
||||
public PauseGame() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to play a card.
|
||||
*/
|
||||
@Serializable
|
||||
public class PlayCard extends ServerMessage {
|
||||
/**
|
||||
* The card that should be played.
|
||||
*/
|
||||
private final BonusCard card;
|
||||
|
||||
/**
|
||||
* The identifier of the piece that should be moved.
|
||||
*/
|
||||
private final String pieceIdentifier;
|
||||
|
||||
private final String pieceIdentifierEnemy;
|
||||
|
||||
/**
|
||||
* Constructs a new PlayCard message.
|
||||
*
|
||||
* @param card the card that should be played
|
||||
* @param pieceIdentifier the identifier of the piece that should be moved
|
||||
*/
|
||||
public PlayCard(BonusCard card, String pieceIdentifier, String pieceIdentifierEnemy) {
|
||||
super();
|
||||
this.card = card;
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
this.pieceIdentifierEnemy = pieceIdentifierEnemy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private PlayCard() {
|
||||
this.pieceIdentifierEnemy = null;
|
||||
card = null;
|
||||
pieceIdentifier = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PlayCard message for the given card and piece identifier.
|
||||
*
|
||||
* @param pieceIdentifier the identifier of the piece of the player that should be affected
|
||||
* @param pieceIdentifierEnemy the identifier of the enemy piece that should be affected
|
||||
* @return a new PlayCard message
|
||||
*/
|
||||
public static PlayCard swap(String pieceIdentifier, String pieceIdentifierEnemy) {
|
||||
return new PlayCard(BonusCard.SWAP, pieceIdentifier, pieceIdentifierEnemy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PlayCard message for the given card and piece identifier.
|
||||
*
|
||||
* @return a new PlayCard message
|
||||
*/
|
||||
public static PlayCard turbo() {
|
||||
return new PlayCard(BonusCard.TURBO, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new PlayCard message for the given card and piece identifier.
|
||||
*
|
||||
* @param pieceIdentifier the identifier of the piece of the player that should be affected
|
||||
* @return a new PlayCard message
|
||||
*/
|
||||
public static PlayCard shield(String pieceIdentifier) {
|
||||
return new PlayCard(BonusCard.SHIELD, pieceIdentifier, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the card that should be played.
|
||||
*
|
||||
* @return the card that should be played
|
||||
*/
|
||||
public BonusCard getCard() {
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the piece that should be moved.
|
||||
*
|
||||
* @return the identifier of the piece that should be moved
|
||||
*/
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the enemy piece that should be moved.
|
||||
*
|
||||
* @return the identifier of the enemy piece that should be moved
|
||||
*/
|
||||
public String getPieceIdentifierEnemy() {
|
||||
return pieceIdentifierEnemy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.BonusCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the client to indicate the possible cards that can be chosen.
|
||||
*/
|
||||
@Serializable
|
||||
public class PossibleCard extends ServerMessage {
|
||||
/**
|
||||
* The list of possible cards.
|
||||
*/
|
||||
private final List<BonusCard> possibleCards;
|
||||
|
||||
/**
|
||||
* Constructor for a PossibleCard instance.
|
||||
*/
|
||||
public PossibleCard() {
|
||||
super();
|
||||
possibleCards = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a possible card to the list of possible cards
|
||||
*
|
||||
* @param card the possible card to add
|
||||
*/
|
||||
public void addPossibleCard(BonusCard card) {
|
||||
this.possibleCards.add(card);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the list of possible cards
|
||||
*
|
||||
* @return the list of possible cards
|
||||
*/
|
||||
public List<BonusCard> getPossibleCards() {
|
||||
return possibleCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.sql.PseudoColumnUsage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to give all possible pieces to choose from.
|
||||
*/
|
||||
@Serializable
|
||||
public class PossiblePiece extends ServerMessage {
|
||||
/**
|
||||
* The list of possible own pieces
|
||||
*/
|
||||
private final List<String> possibleOwnPieces;
|
||||
|
||||
/**
|
||||
* The list of possible enemy pieces
|
||||
*/
|
||||
private final List<String> possibleEnemyPieces;
|
||||
|
||||
/**
|
||||
* Constructor for PossiblePiece
|
||||
*/
|
||||
public PossiblePiece() {
|
||||
super();
|
||||
possibleOwnPieces = new ArrayList<>();
|
||||
possibleEnemyPieces = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Swap the possible pieces
|
||||
*
|
||||
* @param possibleOwnPieces the list of possible own pieces
|
||||
* @param possibleEnemyPieces the list of possible enemy pieces
|
||||
* @return the swapped possible pieces
|
||||
*/
|
||||
public static PossiblePiece swapPossiblePieces(ArrayList<String> possibleOwnPieces, ArrayList<String> possibleEnemyPieces) {
|
||||
PossiblePiece possiblePiece = new PossiblePiece();
|
||||
possiblePiece.possibleOwnPieces.addAll(possibleOwnPieces);
|
||||
possiblePiece.possibleEnemyPieces.addAll(possibleEnemyPieces);
|
||||
return possiblePiece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the possible pieces for the shield
|
||||
*
|
||||
* @param possibleOwnPieces the list of possible own pieces
|
||||
* @return the possible pieces for the shield
|
||||
*/
|
||||
public static PossiblePiece shieldPossiblePieces(ArrayList<String> possibleOwnPieces){
|
||||
PossiblePiece possiblePiece = new PossiblePiece();
|
||||
possiblePiece.possibleOwnPieces.addAll(possibleOwnPieces);
|
||||
return possiblePiece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a piece to the list of possible pieces
|
||||
*
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addOwnPossiblePiece(String piece) {
|
||||
this.possibleOwnPieces.add(piece);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a piece to the list of possible enemy pieces
|
||||
*
|
||||
* @param piece the piece to add
|
||||
*/
|
||||
public void addEnemyPossiblePiece(String piece) {
|
||||
this.possibleEnemyPieces.add(piece);
|
||||
}
|
||||
|
||||
/** Getter for the list of possible pieces
|
||||
* @return the list of possible pieces
|
||||
*/
|
||||
public List<String> getOwnPossiblePieces() {
|
||||
return possibleOwnPieces;
|
||||
}
|
||||
|
||||
/** Getter for the list of possible enemy pieces
|
||||
* @return the list of possible enemy pieces
|
||||
*/
|
||||
public List<String> getEnemyPossiblePieces() {
|
||||
return possibleEnemyPieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to all client to inform them about the current ranking. (only in DetermineStartPlayer)
|
||||
*/
|
||||
@Serializable
|
||||
public class RankingResponse extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new RankingResponse instance.
|
||||
*/
|
||||
public RankingResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the clients to indicate that the ranking shall be rolled again. (only in DetermineStartPlayer)
|
||||
*/
|
||||
@Serializable
|
||||
public class RankingRollAgain extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new RankingRollAgain instance.
|
||||
*/
|
||||
public RankingRollAgain() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Game;
|
||||
|
||||
/**
|
||||
* A message sent by the server to a client that has reconnected to the game. (give the last saved model)
|
||||
*/
|
||||
@Serializable
|
||||
public class ReconnectBriefing extends ServerMessage {
|
||||
/**
|
||||
* The game.
|
||||
*/
|
||||
private final Game game;
|
||||
|
||||
/**
|
||||
* Constructs a new ReconnectBriefing message.
|
||||
*/
|
||||
public ReconnectBriefing(Game game) {
|
||||
super();
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private ReconnectBriefing() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the game.
|
||||
*
|
||||
* @return the game
|
||||
*/
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to resume the game.
|
||||
*/
|
||||
@Serializable
|
||||
public class ResumeGame extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new ResumeGame instance.
|
||||
*/
|
||||
public ResumeGame() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
/**
|
||||
* An interface for processing server messages.
|
||||
* Implementations of this interface can be used to handle different types of server messages.
|
||||
*/
|
||||
public interface ServerInterpreter {
|
||||
/**
|
||||
* Handles an ActivePlayer message received from the server.
|
||||
*
|
||||
* @param msg the ActivePlayer message received
|
||||
*/
|
||||
void received(ActivePlayer msg);
|
||||
|
||||
/**
|
||||
* Handles an AnyPiece message received from the server.
|
||||
*
|
||||
* @param msg the AnyPiece message received
|
||||
*/
|
||||
void received(AnyPiece msg);
|
||||
|
||||
/**
|
||||
* Handles a Briefing message received from the server.
|
||||
*
|
||||
* @param msg the Briefing message received
|
||||
*/
|
||||
void received(Briefing msg);
|
||||
|
||||
/**
|
||||
* Handles a Ceremony message received from the server.
|
||||
*
|
||||
* @param msg the Ceremony message received
|
||||
*/
|
||||
void received(CeremonyMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a Dice message received from the server.
|
||||
*
|
||||
* @param msg the Dice message received
|
||||
*/
|
||||
void received(Dice msg);
|
||||
|
||||
/**
|
||||
* Handles a DiceAgain message received from the server.
|
||||
*
|
||||
* @param msg the DiceAgain message received
|
||||
*/
|
||||
void received(DiceAgain msg);
|
||||
|
||||
/**
|
||||
* Handles a DiceNow message received from the server.
|
||||
*
|
||||
* @param msg the DiceNow message received
|
||||
*/
|
||||
void received(DiceNow msg);
|
||||
|
||||
/**
|
||||
* Handles an EndOfGame message received from the server.
|
||||
*
|
||||
* @param msg the EndOfGame message received
|
||||
*/
|
||||
void received(EndOfTurn msg);
|
||||
|
||||
/**
|
||||
* Handles a GameOver message received from the server.
|
||||
*
|
||||
* @param msg the GameOver message received
|
||||
*/
|
||||
void received(LobbyAccept msg);
|
||||
|
||||
/**
|
||||
* Handles a LobbyDeny message received from the server.
|
||||
*
|
||||
* @param msg the LobbyDeny message received
|
||||
*/
|
||||
void received(LobbyDeny msg);
|
||||
|
||||
/**
|
||||
* Handles a LobbyPlayerJoin message received from the server.
|
||||
*
|
||||
* @param msg the LobbyPlayerJoin message received
|
||||
*/
|
||||
void received(LobbyPlayerJoin msg);
|
||||
|
||||
/**
|
||||
* Handles a LobbyPlayerLeave message received from the server.
|
||||
*
|
||||
* @param msg the LobbyPlayerLeave message received
|
||||
*/
|
||||
void received(LobbyPlayerLeave msg);
|
||||
|
||||
/**
|
||||
* Handles a MoveMessage message received from the server.
|
||||
*
|
||||
* @param msg the MoveMessage message received
|
||||
*/
|
||||
void received(MoveMessage msg);
|
||||
|
||||
/**
|
||||
* Handles a NoTurn message received from the server.
|
||||
*
|
||||
* @param msg the NoTurn message received
|
||||
*/
|
||||
void received(NoTurn msg);
|
||||
|
||||
/**
|
||||
* Handles a PauseGame message received from the server.
|
||||
*
|
||||
* @param msg the PauseGame message received
|
||||
*/
|
||||
void received(PauseGame msg);
|
||||
|
||||
/**
|
||||
* Handles a PlayCard message received from the server.
|
||||
*
|
||||
* @param msg the PlayCard message received
|
||||
*/
|
||||
void received(PlayCard msg);
|
||||
|
||||
/**
|
||||
* Handles a PossibleCard message received from the server.
|
||||
*
|
||||
* @param msg the PossibleCard message received
|
||||
*/
|
||||
void received(PossibleCard msg);
|
||||
|
||||
/**
|
||||
* Handles a PossiblePiece message received from the server.
|
||||
*
|
||||
* @param msg the PossiblePiece message received
|
||||
*/
|
||||
void received(PossiblePiece msg);
|
||||
|
||||
/**
|
||||
* Handles a RankingResponce message received from the server.
|
||||
*
|
||||
* @param msg the RankingResponce message received
|
||||
*/
|
||||
void received(RankingResponse msg);
|
||||
|
||||
/**
|
||||
* Handles a RankingRollAgain message received from the server.
|
||||
*
|
||||
* @param msg the RankingRollAgain message received
|
||||
*/
|
||||
void received(RankingRollAgain msg);
|
||||
|
||||
/**
|
||||
* Handles a ReconnectBriefing message received from the server.
|
||||
*
|
||||
* @param msg the ReconnectBriefing message received
|
||||
*/
|
||||
void received(ReconnectBriefing msg);
|
||||
|
||||
/**
|
||||
* Handles a ResumeGame message received from the server.
|
||||
*
|
||||
* @param msg the ResumeGame message received
|
||||
*/
|
||||
void received(ResumeGame msg);
|
||||
|
||||
/**
|
||||
* Handles a ServerStartGame message received from the server.
|
||||
*
|
||||
* @param msg the ServerStartGame message received
|
||||
*/
|
||||
void received(ServerStartGame msg);
|
||||
|
||||
/**
|
||||
* Handles a StartPiece message received from the server.
|
||||
*
|
||||
* @param msg the StartPiece message received
|
||||
*/
|
||||
void received(StartPiece msg);
|
||||
|
||||
/**
|
||||
* Handles a UpdateReady message received from the server.
|
||||
*
|
||||
* @param msg the UpdateReady message received
|
||||
*/
|
||||
void received(UpdateReady msg);
|
||||
|
||||
/**
|
||||
* Handles a UpdateTSK message received from the server.
|
||||
*
|
||||
* @param msg the UpdateTSK message received
|
||||
*/
|
||||
void received(UpdateTSK msg);
|
||||
|
||||
/**
|
||||
* Handles a WaitPiece message received from the server.
|
||||
*
|
||||
* @param msg the WaitPiece message received
|
||||
*/
|
||||
void received(WaitPiece msg);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.AbstractMessage;
|
||||
|
||||
/**
|
||||
* An abstract base class for server messages used in network transfer.
|
||||
* It extends the AbstractMessage class provided by the jme3-network library.
|
||||
*/
|
||||
public abstract class ServerMessage extends AbstractMessage {
|
||||
/**
|
||||
* Constructs a new ServerMessage instance.
|
||||
*/
|
||||
protected ServerMessage() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
public abstract void accept(ServerInterpreter interpreter);
|
||||
|
||||
/**
|
||||
* Gets the bundle key of the informational text to be shown at the client.
|
||||
* This key is used to retrieve the appropriate localized text for display.
|
||||
*
|
||||
* @return the bundle key of the informational text
|
||||
*/
|
||||
public abstract String getInfoTextKey();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message indicating that the game shall start.
|
||||
*/
|
||||
@Serializable
|
||||
public class ServerStartGame extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new ServerStartGame instance.
|
||||
*/
|
||||
public ServerStartGame() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player that he has to move a start piece.
|
||||
*/
|
||||
@Serializable
|
||||
public class StartPiece extends ServerMessage {
|
||||
/**
|
||||
* The identifier for the piece.
|
||||
*/
|
||||
private final String pieceIdentifier;
|
||||
|
||||
/**
|
||||
* Constructs a new StartPiece instance with the specified piece identifier.
|
||||
*
|
||||
* @param pieceIdentifier the identifier for the piece
|
||||
*/
|
||||
public StartPiece(String pieceIdentifier) {
|
||||
super();
|
||||
this.pieceIdentifier = pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private StartPiece() {
|
||||
super();
|
||||
this.pieceIdentifier = "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier for the piece.
|
||||
*
|
||||
* @return the piece identifier
|
||||
*/
|
||||
public String getPieceIdentifier() {
|
||||
return pieceIdentifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
/**
|
||||
* A message sent by the server to every client to update the readiness status of a player.
|
||||
*/
|
||||
@Serializable
|
||||
public class UpdateReady extends ServerMessage {
|
||||
/**
|
||||
* The color associated with the update.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Indicates whether the player is ready.
|
||||
*/
|
||||
private final boolean ready;
|
||||
|
||||
/**
|
||||
* Constructs a new UpdateReady instance with the specified color and readiness status.
|
||||
*
|
||||
* @param color the color associated with the update
|
||||
* @param ready the readiness status
|
||||
*/
|
||||
public UpdateReady(Color color, boolean ready) {
|
||||
super();
|
||||
this.color = color;
|
||||
this.ready = ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private UpdateReady() {
|
||||
super();
|
||||
this.color = null;
|
||||
this.ready = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color associated with the update.
|
||||
*
|
||||
* @return the color
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is ready.
|
||||
*
|
||||
* @return true if the player is ready, false otherwise
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
/**
|
||||
* A message sent by the server to every client to update the TSK.
|
||||
*/
|
||||
@Serializable
|
||||
public class UpdateTSK extends ServerMessage {
|
||||
/**
|
||||
* The name associated with the update.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The color associated with the update.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructs a new UpdateTSK instance with the specified name and color.
|
||||
*
|
||||
* @param name the name associated with the update
|
||||
* @param color the color associated with the update
|
||||
*/
|
||||
public UpdateTSK(String name, Color color) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for serialization purposes.
|
||||
*/
|
||||
private UpdateTSK() {
|
||||
this("", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name associated with the update.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color associated with the update.
|
||||
*
|
||||
* @return the color
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package pp.mdga.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* A message sent by the server to the active player to choose a piece from the waiting area.
|
||||
*/
|
||||
@Serializable
|
||||
public class WaitPiece extends ServerMessage {
|
||||
/**
|
||||
* Constructs a new WaitPiece instance.
|
||||
*/
|
||||
public WaitPiece() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts a visitor to process this message.
|
||||
*
|
||||
* @param interpreter the visitor to process this message
|
||||
*/
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this message.
|
||||
*
|
||||
* @return a string representation of this message
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key for the info text of this message.
|
||||
*
|
||||
* @return the key for the info text of this message
|
||||
*/
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.client.AnimationEnd;
|
||||
import pp.mdga.message.server.DiceNow;
|
||||
|
||||
public class Animation extends ServerState {
|
||||
public Animation(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedAnimationEnd(AnimationEnd msg, int from) {
|
||||
logic.send(logic.getGame().getStartPlayer(), new DiceNow());
|
||||
parent.gotoState(new Turn(parent, logic));
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class Ceremony extends ServerState {
|
||||
public Ceremony(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class ChoosePiece extends ServerState {
|
||||
private final ChoosePieceStateMachine choosePieceStateMachine = new ChoosePieceStateMachine(this, logic);
|
||||
|
||||
public ChoosePiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class ChoosePieceStateMachine extends ServerStateMachine{
|
||||
public ChoosePieceStateMachine(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NoPiece initialState() {
|
||||
return new NoPiece(this, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDice;
|
||||
import pp.mdga.message.server.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class DetermineStartPlayer extends ServerState {
|
||||
private final List<Player> player = new ArrayList<>();
|
||||
|
||||
public DetermineStartPlayer(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
logic.getGame().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
final Random random = new Random();
|
||||
final int dice = random.nextInt(6) + 1;
|
||||
broadcastUpdate(new Dice(dice, new ArrayList<>()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (Boolean.TRUE.equals(logic.getGame().allRanked())) {
|
||||
broadcastUpdate(new RankingResponse());
|
||||
if (logic.getGame().getOrder().isEmpty()) {
|
||||
// todo: save the players with the same value?
|
||||
broadcastUpdate(new RankingRollAgain());
|
||||
broadcastUpdate(new EndOfTurn());
|
||||
} else {
|
||||
// todo: set start player
|
||||
Player startPlayer = new Player(1);
|
||||
logic.getGame().setStartPlayer(startPlayer);
|
||||
logic.send(startPlayer, new DiceNow());
|
||||
broadcastUpdate(new EndOfTurn());
|
||||
parent.gotoState(new Animation(parent, logic));
|
||||
logic.getGame().removeObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.client.RequestDice;
|
||||
|
||||
public class FirstRoll extends ServerState {
|
||||
public FirstRoll(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
// todo: implement player.hasMovablePieces()
|
||||
// if (player.hasMovablePieces()) {
|
||||
// // todo: goto ChoosePiece
|
||||
// } else {
|
||||
// // todo: implement roll
|
||||
// if (roll == 6) {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new Dice());
|
||||
// // todo: goto ChoosePiece
|
||||
// } else {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new DiceAgain());
|
||||
// parent.gotoState(new SecondRoll(parent, logic));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.PauseGame;
|
||||
import pp.mdga.message.server.PossibleCard;
|
||||
import pp.mdga.message.server.RankingResponse;
|
||||
|
||||
public class GameState extends ServerState {
|
||||
private final GameStateMachine gameStateMachine = new GameStateMachine(this, logic);
|
||||
|
||||
public GameState(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
logic.getGame().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entry() {
|
||||
gameStateMachine.entry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
parent.gotoState(new Ceremony(parent, logic));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedAnimationEnd(AnimationEnd msg, int from) {
|
||||
gameStateMachine.receivedAnimationEnd(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedNoPowerCard(NoPowerCard msg, int from) {
|
||||
gameStateMachine.receivedNoPowerCard(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedSelectCard(SelectCard msg, int from) {
|
||||
gameStateMachine.receivedSelectCard(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
gameStateMachine.receivedRequestDice(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedSelectedPieces(SelectedPieces msg, int from) {
|
||||
gameStateMachine.receivedSelectedPieces(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sentPossibleCard(PossibleCard msg, int from) {
|
||||
gameStateMachine.sentPossibleCard(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sentRankingResponse(RankingResponse msg, int from) {
|
||||
gameStateMachine.sentRankingResponse(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (Boolean.TRUE.equals(logic.getGame().playerHasDisconnected())) {
|
||||
broadcastUpdate(new PauseGame());
|
||||
parent.gotoState(new Interrupt(parent, logic, this));
|
||||
logic.getGame().removeObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
/**
|
||||
* The GameStateMachine class represents the state machine for the game state.
|
||||
*/
|
||||
public class GameStateMachine extends ServerStateMachine {
|
||||
/**
|
||||
* Constructs a new GameStateMachine with the specified parent state and game logic.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the server game logic
|
||||
*/
|
||||
public GameStateMachine(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the initial state of the state machine, which is DetermineStartPlayer.
|
||||
*
|
||||
* @return the initial state
|
||||
*/
|
||||
@Override
|
||||
public DetermineStartPlayer initialState() {
|
||||
return new DetermineStartPlayer(this, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.server.ResumeGame;
|
||||
|
||||
public class Interrupt extends ServerState {
|
||||
private final GameState lastState;
|
||||
|
||||
public Interrupt(ServerState parent, ServerGameLogic logic, GameState lastState) {
|
||||
super(parent, logic);
|
||||
this.lastState = lastState;
|
||||
logic.getGame().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (Boolean.FALSE.equals(logic.getGame().gameIsInterrupted())) {
|
||||
broadcastUpdate(new ResumeGame());
|
||||
parent.gotoState(lastState);
|
||||
logic.getGame().removeObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
import pp.mdga.message.server.ServerStartGame;
|
||||
import pp.mdga.message.server.UpdateReady;
|
||||
import pp.mdga.message.server.UpdateTSK;
|
||||
|
||||
/**
|
||||
* Represents the lobby state of the server.
|
||||
*/
|
||||
public class Lobby extends ServerState {
|
||||
/**
|
||||
* Constructs a new Lobby state.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the server game logic
|
||||
*/
|
||||
public Lobby(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the DeselectTSK message.
|
||||
*
|
||||
* @param msg the DeselectTSK message
|
||||
*/
|
||||
@Override
|
||||
public void receivedDeselectTSK(DeselectTSK msg, int from) {
|
||||
broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the LobbyNotReady message.
|
||||
*
|
||||
* @param msg the LobbyNotReady message
|
||||
*/
|
||||
@Override
|
||||
public void receivedNotReady(LobbyNotReady msg, int from) {
|
||||
broadcastUpdate(new UpdateReady(getPlayerColor(from), false));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the LobbyReady message.
|
||||
*
|
||||
* @param msg the LobbyReady message
|
||||
*/
|
||||
@Override
|
||||
public void receivedReady(LobbyReady msg, int from) {
|
||||
broadcastUpdate(new UpdateReady(getPlayerColor(from), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to get the color associated with a player ID.
|
||||
*
|
||||
* @param playerId The ID of the player.
|
||||
* @return The Color associated with the player, or null if not found.
|
||||
*/
|
||||
private Color getPlayerColor(int playerId) {
|
||||
Player player = logic.getPlayerById(playerId);
|
||||
|
||||
for (var entry : logic.getGame().getPlayers().entrySet()) {
|
||||
if (entry.getValue().equals(player)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the SelectTSK message.
|
||||
*
|
||||
* @param msg the SelectTSK message
|
||||
*/
|
||||
@Override
|
||||
public void receivedSelectTSK(SelectTSK msg, int from) {
|
||||
broadcastUpdate(new UpdateTSK(logic.getPlayerById(from).getName(), msg.getColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the ClientStartGame message.
|
||||
*
|
||||
* @param msg the ClientStartGame message
|
||||
*/
|
||||
@Override
|
||||
public void receivedStartGame(ClientStartGame msg, int from) {
|
||||
if (Boolean.TRUE.equals(logic.getGame().allReady())) {
|
||||
broadcastUpdate(new ServerStartGame());
|
||||
parent.gotoState(new GameState(parent, logic));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class MovePiece extends ServerState {
|
||||
public MovePiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.server.WaitPiece;
|
||||
|
||||
public class NoPiece extends ServerState {
|
||||
public NoPiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
entry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void entry() {
|
||||
// if (hasTurbo() || turbo == 0) {
|
||||
// if (roll == 6 &&
|
||||
// logic.getGame().getBoard().getPlayerData().getWaitingArea().hasPieces() &&
|
||||
// logic.getGame().getBoard().getNodes().getStartNode(Color).isOccupied()) {
|
||||
// parent.gotoState(new WaitingPiece(parent, logic));
|
||||
// } else {
|
||||
// parent.gotoState(new NoTurn(parent, logic));
|
||||
// }
|
||||
// } else {
|
||||
// validateHasPieces();
|
||||
// }
|
||||
}
|
||||
|
||||
private void validateHasPieces() {
|
||||
// if (logic.getGame().getBoard().getPlayerData().getWaitingArea().hasPieces()) {
|
||||
// if (logic.getGame().getBoard().getNodes().getStartNode(Color).isOccupied()) {
|
||||
// if (roll == 6) {
|
||||
// logic.send(new Player(1), new WaitPiece());
|
||||
// } else {
|
||||
// validateMove();
|
||||
// }
|
||||
// } else {
|
||||
// if (logic.getGame().getBoard().getNodes().getStartNode(Color).getPiece().canMove()) {
|
||||
// logic.send(new Player(1), new WaitPiece());
|
||||
// parent.gotoState(new StartPiece(parent, logic));
|
||||
// } else {
|
||||
// validateMove();
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// validateMove();
|
||||
// }
|
||||
}
|
||||
|
||||
private void validateMove() {
|
||||
// if (player.canMove()) {
|
||||
// parent.gotoState(new NoTurn(parent, logic));
|
||||
// } else {
|
||||
// logic.send(new Player(1), new SelectPiece());
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.server.EndOfTurn;
|
||||
|
||||
public class NoTurn extends ServerState {
|
||||
public NoTurn(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sentEndOfTurn(EndOfTurn msg, int from) {
|
||||
// todo: goto end of turn
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public interface Observer {
|
||||
void update();
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class PlayPowerCard extends ServerState {
|
||||
public PlayPowerCard(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.NoPowerCard;
|
||||
import pp.mdga.message.client.SelectCard;
|
||||
import pp.mdga.message.client.SelectedPieces;
|
||||
import pp.mdga.message.server.DiceNow;
|
||||
import pp.mdga.message.server.PossibleCard;
|
||||
|
||||
public class PowerCard extends ServerState {
|
||||
public PowerCard(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
logic.getGame().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedNoPowerCard(NoPowerCard msg, int from) {
|
||||
// todo: send to everyone? or one player?
|
||||
// todo: right msg?
|
||||
logic.send(new Player(1), new DiceNow());
|
||||
parent.gotoState(new RollDice(parent, logic));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedSelectCard(SelectCard msg, int from) {
|
||||
// todo: send to everyone? or one player?
|
||||
logic.send(new Player(1), new PossibleCard());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedSelectedPieces(SelectedPieces msg, int from) {
|
||||
// if (verifySelectedPieces()) {
|
||||
// // todo: send to everyone? or one player?
|
||||
// // todo: msg PowerCardAnimation?
|
||||
// logic.send(new Player(1), new PowerCardAnimation());
|
||||
// parent.gotoState(new PlayPowerCard(parent, logic));
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sentPossibleCard(PossibleCard msg, int from) {
|
||||
// todo: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (!super.getMoveablePieces(logic.getGame().getActiveColor()).isEmpty()) {
|
||||
// todo: send to everyone? or one player?
|
||||
// todo: right msg?
|
||||
logic.send(new Player(1), new DiceNow());
|
||||
parent.gotoState(new RollDice(parent, logic));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class RollDice extends ServerState {
|
||||
private final RollDiceMachine rollDiceMachine = new RollDiceMachine(this, logic);
|
||||
|
||||
public RollDice(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class RollDiceMachine extends ServerStateMachine {
|
||||
public RollDiceMachine(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FirstRoll initialState() {
|
||||
return new FirstRoll(this, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDice;
|
||||
import pp.mdga.message.server.Dice;
|
||||
import pp.mdga.message.server.DiceAgain;
|
||||
|
||||
public class SecondRoll extends ServerState {
|
||||
public SecondRoll(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
// if (roll == 6) {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new Dice());
|
||||
// // todo: goto ChoosePiece
|
||||
// } else {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new DiceAgain());
|
||||
// parent.gotoState(new ThirdRoll(parent, logic));
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestMove;
|
||||
import pp.mdga.message.server.StartPiece;
|
||||
|
||||
public class SelectPiece extends ServerState {
|
||||
public SelectPiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestMove(RequestMove msg, int from) {
|
||||
// if (verifyPiece(p)) {
|
||||
// logic.send(new Player(1), new Animation());
|
||||
// // todo: goto state
|
||||
// } else {
|
||||
// logic.send(new Player(1), new StartPiece());
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
/**
|
||||
* The ServerAutomaton class represents the top-level state machine for the server.
|
||||
* It initializes the state machine and sets the initial state to Lobby.
|
||||
*/
|
||||
public class ServerAutomaton extends ServerStateMachine {
|
||||
/**
|
||||
* Constructs a new ServerAutomaton with the specified game logic.
|
||||
*
|
||||
* @param logic the server game logic
|
||||
*/
|
||||
public ServerAutomaton(ServerGameLogic logic) {
|
||||
super(null, logic);
|
||||
entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the initial state of the state machine, which is Lobby.
|
||||
*
|
||||
* @return the initial state
|
||||
*/
|
||||
@Override
|
||||
public Lobby initialState() {
|
||||
return new Lobby(this, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Game;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
|
||||
public class ServerGameLogic implements ClientInterpreter {
|
||||
static final Logger LOGGER = System.getLogger(ServerGameLogic.class.getName());
|
||||
|
||||
private final Game game;
|
||||
private final ServerSender serverSender;
|
||||
private ServerState state;
|
||||
|
||||
public ServerGameLogic(Game game, ServerSender serverSender) {
|
||||
this.game = game;
|
||||
this.serverSender = serverSender;
|
||||
state = new ServerAutomaton(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void received(AnimationEnd animationEnd, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(DeselectTSK deselectTSK, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ForceStartGame forceStartGame, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(JoinServer joinServer, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(LeaveGame leaveGame, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(LobbyNotReady lobbyNotReady, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(LobbyReady lobbyReady, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestBriefing requestBriefing, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestDice requestDice, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestMove requestMove, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(RequestPlayCard requestPlayCard, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(SelectCard selectCard, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(SelectTSK selectTSK, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ForceContinueGame forceContinueGame, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(ClientStartGame clientStartGame, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NoPowerCard noPowerCard, int from) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(SelectedPieces selectedPieces, int from) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the specified player.
|
||||
*
|
||||
* @param player the player to send the message to
|
||||
* @param msg the message to send
|
||||
*/
|
||||
public void send(Player player, ServerMessage msg) {
|
||||
LOGGER.log(Logger.Level.INFO, "sending to {0}: {1}", player, msg); //NON-NLS
|
||||
serverSender.send(player.getId(), msg);
|
||||
}
|
||||
|
||||
public ServerSender getServerSender() {
|
||||
return serverSender;
|
||||
}
|
||||
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the player representing the client with the specified connection ID.
|
||||
*
|
||||
* @param id the ID of the client
|
||||
* @return the player associated with the client ID, or null if not found
|
||||
*/
|
||||
public Player getPlayerById(int id) {
|
||||
for (var entry : game.getPlayers().entrySet())
|
||||
if (entry.getValue().getId() == id)
|
||||
return entry.getValue();
|
||||
LOGGER.log(Logger.Level.ERROR, "no player found with connection {0}", id); //NON-NLS
|
||||
return null;
|
||||
}
|
||||
|
||||
public ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
|
||||
public interface ServerSender {
|
||||
void send(int id, ServerMessage msg);
|
||||
}
|
||||
@@ -1,324 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
import pp.mdga.game.Node;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.game.PlayerData;
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.EndOfTurn;
|
||||
import pp.mdga.message.server.PossibleCard;
|
||||
import pp.mdga.message.server.RankingResponse;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
|
||||
import java.lang.System.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract class representing a state in the server's state machine.
|
||||
* Implements the Observer pattern to observe changes in the game state.
|
||||
*/
|
||||
public abstract class ServerState implements Observer {
|
||||
/**
|
||||
* Logger for logging messages within the application.
|
||||
*/
|
||||
protected static final Logger LOGGER = System.getLogger(ServerState.class.getName());
|
||||
|
||||
/**
|
||||
* The parent state of the current state.
|
||||
*/
|
||||
protected ServerState parent;
|
||||
|
||||
/**
|
||||
* The game logic associated with the server state.
|
||||
*/
|
||||
protected ServerGameLogic logic;
|
||||
|
||||
/**
|
||||
* Constructs a new ServerState with the specified parent state and game logic.
|
||||
*
|
||||
* @param parent the parent state of the current state
|
||||
* @param logic the game logic associated with the server state
|
||||
*/
|
||||
protected ServerState(ServerState parent, ServerGameLogic logic) {
|
||||
this.parent = parent;
|
||||
this.logic = logic;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the state is entered.
|
||||
*/
|
||||
public void entry() { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when the state is exited.
|
||||
*/
|
||||
public void exit() { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when an animation ends.
|
||||
*
|
||||
* @param msg the animation end message
|
||||
*/
|
||||
public void receivedAnimationEnd(AnimationEnd msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a TSK is deselected.
|
||||
*
|
||||
* @param msg the deselect TSK message
|
||||
*/
|
||||
public void receivedDeselectTSK(DeselectTSK msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a NoPowerCard message is received.
|
||||
*
|
||||
* @param msg the NoPowerCard message
|
||||
*/
|
||||
public void receivedNoPowerCard(NoPowerCard msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a LobbyNotReady message is received.
|
||||
*
|
||||
* @param msg the LobbyNotReady message
|
||||
*/
|
||||
public void receivedNotReady(LobbyNotReady msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a LobbyReady message is received.
|
||||
*
|
||||
* @param msg the LobbyReady message
|
||||
*/
|
||||
public void receivedReady(LobbyReady msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a RequestDice message is received.
|
||||
*
|
||||
* @param msg the RequestDice message
|
||||
*/
|
||||
public void receivedRequestDice(RequestDice msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a RequestMove message is received.
|
||||
*
|
||||
* @param msg the RequestMove message
|
||||
*/
|
||||
public void receivedRequestMove(RequestMove msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a SelectCard message is received.
|
||||
*
|
||||
* @param msg the SelectCard message
|
||||
*/
|
||||
public void receivedSelectCard(SelectCard msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a SelectTSK message is received.
|
||||
*
|
||||
* @param msg the SelectTSK message
|
||||
*/
|
||||
public void receivedSelectTSK(SelectTSK msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a SelectedPieces message is received.
|
||||
*
|
||||
* @param msg the SelectedPieces message
|
||||
*/
|
||||
public void receivedSelectedPieces(SelectedPieces msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a StartGame message is received.
|
||||
*
|
||||
* @param msg the StartGame message
|
||||
*/
|
||||
public void receivedStartGame(ClientStartGame msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when an EndOfTurn message is sent.
|
||||
*
|
||||
* @param msg the EndOfTurn message
|
||||
*/
|
||||
public void sentEndOfTurn(EndOfTurn msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a PossibleCard message is sent.
|
||||
*
|
||||
* @param msg the PossibleCard message
|
||||
*/
|
||||
public void sentPossibleCard(PossibleCard msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is called when a RankingResponce message is sent.
|
||||
*
|
||||
* @param msg the RankingResponce message
|
||||
*/
|
||||
public void sentRankingResponse(RankingResponse msg, int from) { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method transitions to a new state.
|
||||
*
|
||||
* @param state the new state to transition to
|
||||
* @throws IllegalStateException if called outside a state machine
|
||||
*/
|
||||
public void gotoState(ServerState state) {
|
||||
throw new IllegalStateException("not in a statemachine");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the parent state of the current state.
|
||||
*
|
||||
* @return the parent state
|
||||
*/
|
||||
public ServerState getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the observed object is changed.
|
||||
* It is part of the Observer pattern implementation.
|
||||
*/
|
||||
public void update() { /* do nothing */ }
|
||||
|
||||
/**
|
||||
* This method is used to calculate the steps a piece can move
|
||||
*
|
||||
* @return the steps a piece can move
|
||||
*/
|
||||
private int calculateSteps() {
|
||||
return logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to test if u can move a piece
|
||||
*
|
||||
* @param piece the piece to be moved
|
||||
* @return true if the piece can be moved, false otherwise
|
||||
*/
|
||||
protected boolean tryMove(Piece piece) {
|
||||
int steps = calculateSteps();
|
||||
if (piece.getState() == PieceState.HOME) {
|
||||
return tryHomeMove(piece, steps);
|
||||
} else {
|
||||
int homeMoves = getHomeMoves(piece, steps);
|
||||
if (homeMoves > 0) {
|
||||
return tryHomeMove(piece, homeMoves);
|
||||
} else {
|
||||
return tryInfieldMove(piece, steps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to determine if a piece would move into the home area.
|
||||
*
|
||||
* @param piece the piece to be moved
|
||||
* @param steps the steps the piece would move
|
||||
* @return the number of steps the piece would move into the home area
|
||||
*/
|
||||
protected int getHomeMoves(Piece piece, int steps) {
|
||||
int figureIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
Color col = piece.getColor();
|
||||
int startIndex = logic.getGame().getBoard().getPlayerData().get(col).getStartNodeIndex();
|
||||
int moveIndex = startIndex + steps;
|
||||
if (moveIndex > logic.getGame().getBoard().getInfield().length) {
|
||||
moveIndex %= logic.getGame().getBoard().getInfield().length;
|
||||
if (moveIndex >= startIndex) {
|
||||
return moveIndex - startIndex + 1;
|
||||
}
|
||||
} else if (figureIndex < startIndex && moveIndex >= startIndex) {
|
||||
return moveIndex - startIndex + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to determine if a piece can move in the infield
|
||||
*
|
||||
* @param piece the piece to be moved
|
||||
* @param steps the steps the piece would move
|
||||
* @return true if the piece can move in the infield, false otherwise
|
||||
*/
|
||||
protected boolean tryInfieldMove(Piece piece, int steps) {
|
||||
int figureIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
int moveIndex = (figureIndex + steps) % logic.getGame().getBoard().getInfield().length;
|
||||
Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
|
||||
if (occupant != null) {
|
||||
return occupant.getColor() != piece.getColor();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to determine if a piece can move inside the home area
|
||||
*
|
||||
* @param piece the piece to be moved
|
||||
* @param steps the steps the piece would move
|
||||
* @return true if the piece can move into the home area, false otherwise
|
||||
*/
|
||||
protected boolean tryHomeMove(Piece piece, int steps) {
|
||||
Color col = piece.getColor();
|
||||
PlayerData playerData = logic.getGame().getBoard().getPlayerData().get(col);
|
||||
Node[] homeNodes = playerData.getHomeNodes();
|
||||
int index;
|
||||
|
||||
if (playerData.homeIncludes(piece)) {
|
||||
index = playerData.getIndexInHome(piece);
|
||||
} else {
|
||||
index = 0;
|
||||
}
|
||||
|
||||
if (index + steps >= homeNodes.length) {
|
||||
return false;
|
||||
} else {
|
||||
for (int i = index; i <= index + steps; i++) {
|
||||
if (homeNodes[i].getOccupant() != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the pieces that can be moved
|
||||
*
|
||||
* @param color the color of the pieces
|
||||
* @return the pieces that can be moved
|
||||
*/
|
||||
protected List<Piece> getMoveablePieces(Color color) {
|
||||
ArrayList<Piece> moveablePieces = new ArrayList<>();
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
for (Piece piece : logic.getGame().getBoard().getPlayerData().get(color).getPieces()) {
|
||||
if (piece.getState() == PieceState.ACTIVE || piece.getState() == PieceState.HOME) {
|
||||
pieces.add(piece);
|
||||
}
|
||||
}
|
||||
for (Piece piece : pieces) {
|
||||
if (tryMove(piece)) {
|
||||
moveablePieces.add(piece);
|
||||
}
|
||||
}
|
||||
return moveablePieces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts an update message to all players.
|
||||
*
|
||||
* @param updateMessage the update message to be sent
|
||||
*/
|
||||
protected void broadcastUpdate(ServerMessage updateMessage) {
|
||||
for (var entry : logic.getGame().getPlayers().entrySet()) {
|
||||
logic.send(entry.getValue(), updateMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object.
|
||||
*
|
||||
* @return the simple name of the class
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName();
|
||||
}
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.message.client.*;
|
||||
import pp.mdga.message.server.EndOfTurn;
|
||||
import pp.mdga.message.server.PossibleCard;
|
||||
import pp.mdga.message.server.RankingResponse;
|
||||
|
||||
/**
|
||||
* Abstract class representing a state machine for the server.
|
||||
* It manages the transitions between different states and delegates
|
||||
* the handling of messages to the current state.
|
||||
*/
|
||||
public abstract class ServerStateMachine extends ServerState {
|
||||
/**
|
||||
* The current state of the state machine.
|
||||
*/
|
||||
private ServerState state;
|
||||
|
||||
/**
|
||||
* Constructs a new instance of ServerStateMachine.
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the server game logic
|
||||
*/
|
||||
protected ServerStateMachine(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the initial state of a state machine.
|
||||
*/
|
||||
public abstract ServerState initialState();
|
||||
|
||||
/**
|
||||
* Transitions to a new state.
|
||||
*
|
||||
* @param newState the new state to transition to
|
||||
*/
|
||||
@Override
|
||||
public void gotoState(ServerState newState) {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "{0}: {1} --> {2}", this, state, newState);
|
||||
enter(newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the state is entered.
|
||||
*/
|
||||
@Override
|
||||
public void entry() {
|
||||
final ServerState newState = initialState();
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "{0}: initial state={1}", this, newState);
|
||||
enter(newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters a new state.
|
||||
*
|
||||
* @param newState the new state to enter
|
||||
* @throws IllegalArgumentException if the new state does not belong to this state machine
|
||||
*/
|
||||
private void enter(ServerState newState) {
|
||||
if (newState.parent != this)
|
||||
throw new IllegalArgumentException("Wrong state: " + newState + " belongs to " + newState.parent + " instead of " + this);
|
||||
state = newState;
|
||||
state.entry();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the state is exited.
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
state.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when an animation ends.
|
||||
*
|
||||
* @param msg the animation end message
|
||||
*/
|
||||
@Override
|
||||
public void receivedAnimationEnd(AnimationEnd msg, int from) {
|
||||
state.receivedAnimationEnd(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a TSK is deselected.
|
||||
*
|
||||
* @param msg the deselect TSK message
|
||||
*/
|
||||
@Override
|
||||
public void receivedDeselectTSK(DeselectTSK msg, int from) {
|
||||
state.receivedDeselectTSK(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a NoPowerCard message is received.
|
||||
*
|
||||
* @param msg the NoPowerCard message
|
||||
*/
|
||||
@Override
|
||||
public void receivedNoPowerCard(NoPowerCard msg, int from) {
|
||||
state.receivedNoPowerCard(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a LobbyNotReady message is received.
|
||||
*
|
||||
* @param msg the LobbyNotReady message
|
||||
*/
|
||||
@Override
|
||||
public void receivedNotReady(LobbyNotReady msg, int from) {
|
||||
state.receivedNotReady(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a LobbyReady message is received.
|
||||
*
|
||||
* @param msg the LobbyReady message
|
||||
*/
|
||||
@Override
|
||||
public void receivedReady(LobbyReady msg, int from) {
|
||||
state.receivedReady(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a RequestDice message is received.
|
||||
*
|
||||
* @param msg the RequestDice message
|
||||
*/
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
state.receivedRequestDice(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a RequestMove message is received.
|
||||
*
|
||||
* @param msg the RequestMove message
|
||||
*/
|
||||
@Override
|
||||
public void receivedRequestMove(RequestMove msg, int from) {
|
||||
state.receivedRequestMove(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a SelectCard message is received.
|
||||
*
|
||||
* @param msg the SelectCard message
|
||||
*/
|
||||
@Override
|
||||
public void receivedSelectCard(SelectCard msg, int from) {
|
||||
state.receivedSelectCard(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a SelectTSK message is received.
|
||||
*
|
||||
* @param msg the SelectTSK message
|
||||
*/
|
||||
@Override
|
||||
public void receivedSelectTSK(SelectTSK msg, int from) {
|
||||
state.receivedSelectTSK(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a SelectedPieces message is received.
|
||||
*
|
||||
* @param msg the SelectedPieces message
|
||||
*/
|
||||
@Override
|
||||
public void receivedSelectedPieces(SelectedPieces msg, int from) {
|
||||
state.receivedSelectedPieces(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a StartGame message is received.
|
||||
*
|
||||
* @param msg the StartGame message
|
||||
*/
|
||||
@Override
|
||||
public void receivedStartGame(ClientStartGame msg, int from) {
|
||||
state.receivedStartGame(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when an EndOfTurn message is sent.
|
||||
*
|
||||
* @param msg the EndOfTurn message
|
||||
*/
|
||||
@Override
|
||||
public void sentEndOfTurn(EndOfTurn msg, int from) {
|
||||
state.sentEndOfTurn(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a PossibleCard message is sent.
|
||||
*
|
||||
* @param msg the PossibleCard message
|
||||
*/
|
||||
@Override
|
||||
public void sentPossibleCard(PossibleCard msg, int from) {
|
||||
state.sentPossibleCard(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a RankingResponse message is sent.
|
||||
*
|
||||
* @param msg the RankingResponse message
|
||||
*/
|
||||
@Override
|
||||
public void sentRankingResponse(RankingResponse msg, int from) {
|
||||
state.sentRankingResponse(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the object, including the current state.
|
||||
*
|
||||
* @return the string representation of the object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + "(in " + state + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current state.
|
||||
*
|
||||
* @return the current state
|
||||
*/
|
||||
public ServerState getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestMove;
|
||||
|
||||
public class StartPiece extends ServerState {
|
||||
public StartPiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestMove(RequestMove msg, int from) {
|
||||
// if (verifyPiece(p)) {
|
||||
// logic.send(new Player(1), new Animation());
|
||||
// // todo: goto state
|
||||
// } else {
|
||||
// logic.send(new Player(1), new pp.mdga.message.server.StartPiece());
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDice;
|
||||
import pp.mdga.message.server.Dice;
|
||||
import pp.mdga.message.server.DiceAgain;
|
||||
|
||||
public class ThirdRoll extends ServerState {
|
||||
public ThirdRoll(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestDice(RequestDice msg, int from) {
|
||||
// if (roll == 6) {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new Dice());
|
||||
// // todo: goto ChoosePiece
|
||||
// } else {
|
||||
// // todo: send to everyone? or one player?
|
||||
// logic.send(new Player(1), new DiceAgain());
|
||||
// // todo: goto End from Turn
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.server.ActivePlayer;
|
||||
import pp.mdga.message.server.CeremonyMessage;
|
||||
|
||||
public class Turn extends ServerState {
|
||||
private final TurnStateMachine turnStateMachine = new TurnStateMachine(this, logic);
|
||||
|
||||
public Turn(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
// todo: when TurnStateMachine is in the end state, and then?
|
||||
@Override
|
||||
public void exit() {
|
||||
Player player = logic.getGame().getStartPlayer();
|
||||
|
||||
// if (player.isFinished()) {
|
||||
// logic.send(player, new Spectator());
|
||||
// } else {
|
||||
// logic.send(player, new EndOfTurn());
|
||||
// }
|
||||
|
||||
if (logic.getGame().getPlayers().size() == 1) {
|
||||
broadcastUpdate(new CeremonyMessage());
|
||||
this.getParent().getParent().exit();
|
||||
} else {
|
||||
// todo: next player
|
||||
broadcastUpdate(new ActivePlayer(null));
|
||||
parent.gotoState(new Animation(parent, logic));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class TurnStateMachine extends ServerStateMachine {
|
||||
public TurnStateMachine(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerCard initialState() {
|
||||
return new PowerCard(this, logic);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDice;
|
||||
import pp.mdga.message.client.RequestMove;
|
||||
import pp.mdga.message.server.StartPiece;
|
||||
|
||||
public class WaitingPiece extends ServerState {
|
||||
public WaitingPiece(ServerState parent, ServerGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedRequestMove(RequestMove msg, int from) {
|
||||
// if (verifyPiece(p)) {
|
||||
// logic.send(new Player(1), new Animation());
|
||||
// // todo: goto state
|
||||
// } else {
|
||||
// logic.send(new Player(1), new StartPiece());
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user