merge to dev/client_beck from development
This commit is contained in:
@@ -28,9 +28,10 @@ public class ClientGameLogic implements ServerInterpreter {
|
||||
private final InterruptState interruptState = new InterruptState(null, this);
|
||||
private final SettingsState settingsState = new SettingsState(null, this);
|
||||
|
||||
public ClientGameLogic(Game game, ClientSender clientSender) {
|
||||
this.game = game;
|
||||
public ClientGameLogic(ClientSender clientSender) {
|
||||
this.game = new Game();
|
||||
this.clientSender = clientSender;
|
||||
dialogsState.enter();
|
||||
state = dialogsState;
|
||||
}
|
||||
|
||||
@@ -244,7 +245,11 @@ public void selectName(String name){
|
||||
}
|
||||
|
||||
public void selectReady(boolean ready){
|
||||
state.selectReady(ready);
|
||||
if(ready){
|
||||
state.selectReady();
|
||||
} else {
|
||||
state.selectUnready();
|
||||
}
|
||||
}
|
||||
|
||||
public void selectHost(String name){
|
||||
@@ -304,7 +309,11 @@ public SettingsState getSettings(){
|
||||
}
|
||||
|
||||
public Notification getNotification(){
|
||||
return notifications.remove(0);
|
||||
if(!notifications.isEmpty()){
|
||||
return notifications.remove(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addNotification(Notification notification){
|
||||
|
||||
@@ -200,7 +200,7 @@ public void setName(String name) {
|
||||
LOGGER.log(Level.DEBUG, "Setting name not allowed.");
|
||||
}
|
||||
|
||||
public void selectReady(boolean ready) {
|
||||
public void selectReady() {
|
||||
LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public void enter(){
|
||||
|
||||
public void setState(DialogStates newState){
|
||||
currentState.exit();
|
||||
currentState.enter();
|
||||
newState.enter();
|
||||
currentState = newState;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,11 @@ public void selectLeave(){
|
||||
currentState.selectLeave();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name){
|
||||
currentState.setName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectTSK(Color color){
|
||||
currentState.selectTSK(color);
|
||||
@@ -86,8 +91,8 @@ public void deselectTSK(Color color){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectReady(boolean ready){
|
||||
currentState.selectReady(ready);
|
||||
public void selectReady(){
|
||||
currentState.selectReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,10 +8,19 @@ public class InterruptState extends ClientState {
|
||||
|
||||
private ClientState previousState;
|
||||
|
||||
/**
|
||||
* Creates a new InterruptState
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public InterruptState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the new state machine
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
previousState = null;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package pp.mdga.client;
|
||||
|
||||
public interface ServerConnection extends ClientSender {
|
||||
boolean isConnected();
|
||||
|
||||
void connect();
|
||||
|
||||
void disconnect();
|
||||
}
|
||||
@@ -7,26 +7,44 @@
|
||||
|
||||
public class SettingsState extends ClientState {
|
||||
|
||||
/**
|
||||
* The current state of the settings
|
||||
*/
|
||||
private SettingStates currentState;
|
||||
|
||||
private final MainSettingsState mainSettingsState = new MainSettingsState(this, logic);
|
||||
private final AudioSettingsState audioSettingsState = new AudioSettingsState(this, logic);
|
||||
private final VideoSettingsState videoSettingsState = new VideoSettingsState(this, logic);
|
||||
|
||||
/**
|
||||
* Creates a new SettingsState
|
||||
*
|
||||
* @param parent the parent state
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public SettingsState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the current state
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
currentState = mainSettingsState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits the current state
|
||||
*/
|
||||
@Override
|
||||
public void exit() {
|
||||
currentState.exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the current state
|
||||
*/
|
||||
public SettingStates getState(){
|
||||
return currentState;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
import pp.mdga.message.server.ServerStartGameMessage;
|
||||
import pp.mdga.message.server.UpdateReadyMessage;
|
||||
import pp.mdga.message.server.UpdateTSKMessage;
|
||||
import pp.mdga.notification.LobbyReadyNotification;
|
||||
import pp.mdga.notification.TskSelectNotification;
|
||||
import pp.mdga.notification.TskUnselectNotification;
|
||||
|
||||
@@ -35,6 +36,7 @@ public void exit() {
|
||||
@Override
|
||||
public void selectLeave() {
|
||||
parent.setState(parent.getStartDialog());
|
||||
logic.send(new LeaveGameMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +50,7 @@ public void deselectTSK(Color color) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectReady(boolean ready) {
|
||||
public void selectReady() {
|
||||
logic.send(new LobbyReadyMessage());
|
||||
}
|
||||
|
||||
@@ -75,6 +77,7 @@ public void received(ServerStartGameMessage msg){
|
||||
|
||||
@Override
|
||||
public void received(LobbyPlayerJoinedMessage msg){
|
||||
logic.addNotification(new TskSelectNotification(msg.getPlayer().getColor(), msg.getPlayer().getName(), parent.getOwnPlayerId()== msg.getId()));
|
||||
logic.getGame().getPlayers().put(msg.getId(), msg.getPlayer());
|
||||
}
|
||||
|
||||
@@ -93,6 +96,7 @@ public void received(LobbyPlayerLeaveMessage msg){
|
||||
|
||||
@Override
|
||||
public void received(UpdateReadyMessage msg){
|
||||
logic.addNotification(new LobbyReadyNotification(logic.getGame().getPlayers().get(msg.getPlayerId()).getColor(), msg.isReady()));
|
||||
logic.getGame().getPlayers().get(msg.getPlayerId()).setReady(msg.isReady());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.DialogsState;
|
||||
import pp.mdga.notification.LobbyDialogNotification;
|
||||
|
||||
public class NetworkDialogState extends DialogStates {
|
||||
|
||||
@@ -55,9 +56,7 @@ public void selectLeave() {
|
||||
}
|
||||
|
||||
public void selectJoin(String IP) {
|
||||
if(checkIP(IP)){
|
||||
parent.setState(parent.getLobby());
|
||||
}
|
||||
|
||||
parent.setState(parent.getLobby());
|
||||
logic.addNotification(new LobbyDialogNotification());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ public void selectHost(String name) {
|
||||
logic.setHost(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
parent.setState(parent.getNetworkDialog());
|
||||
parent.setOwnPlayerName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectLeave() {
|
||||
parent.exit();
|
||||
|
||||
@@ -3,15 +3,9 @@
|
||||
import pp.mdga.client.ClientGameLogic;
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gameState.TurnState;
|
||||
import pp.mdga.game.BonusCard;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.ShieldState;
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.notification.PlayCardNotification;
|
||||
import pp.mdga.notification.ShieldActiveNotification;
|
||||
import pp.mdga.notification.ShieldSuppressedNotification;
|
||||
import pp.mdga.notification.SwapPieceNotification;
|
||||
|
||||
public class PlayPowerCardState extends TurnStates {
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
import pp.mdga.notification.WaitMoveNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NoPieceState extends ChoosePieceStates {
|
||||
@@ -49,7 +51,13 @@ public void received(WaitPieceMessage msg){
|
||||
@Override
|
||||
public void received(StartPieceMessage msg){
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier());
|
||||
//TODO: logic.addNotification(null);
|
||||
List<UUID> listPiece = new ArrayList<>();
|
||||
List<Integer> listIndex = new ArrayList<>();
|
||||
List<Boolean> homeMove = new ArrayList<>();
|
||||
listPiece.add(piece.getUuid());
|
||||
listIndex.add(msg.getTargetIndex());
|
||||
homeMove.add(false);
|
||||
logic.addNotification(new SelectableMoveNotification(listPiece, listIndex, homeMove));
|
||||
parent.setState(parent.getStartPiece());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class will be used to handle general PlayerData
|
||||
*/
|
||||
@Serializable
|
||||
public class Player {
|
||||
/**
|
||||
* The name of the player.
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package pp.mdga.game;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
/**
|
||||
* This class will be used to store Statistics during the Game;
|
||||
*/
|
||||
@Serializable
|
||||
public class Statistic {
|
||||
/**
|
||||
* The number of cards played.
|
||||
|
||||
@@ -18,7 +18,7 @@ public StartGameMessage(boolean forceStartGame){
|
||||
/**
|
||||
* Constructs a new ForceStartGame message.
|
||||
*/
|
||||
public StartGameMessage() {
|
||||
private StartGameMessage() {
|
||||
super();
|
||||
forceStartGame = false;
|
||||
}
|
||||
|
||||
@@ -6,12 +6,16 @@
|
||||
* Notification that the active player has changed
|
||||
*/
|
||||
public class ActivePlayerNotification extends Notification {
|
||||
|
||||
/**
|
||||
* The color of the active player
|
||||
*/
|
||||
private Color color;
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color the color of the active player
|
||||
*/
|
||||
public ActivePlayerNotification(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
/**
|
||||
* Class CeremonyNotification
|
||||
* Represents a notification for a ceremony in the game.
|
||||
*
|
||||
* <p>
|
||||
* Index mapping:
|
||||
* index = 0 ==> winner
|
||||
* index = 1 ==> 2nd
|
||||
@@ -16,6 +16,9 @@
|
||||
* index = 4 ==> total
|
||||
*/
|
||||
public class CeremonyNotification extends Notification {
|
||||
/**
|
||||
* Attributes.
|
||||
*/
|
||||
private ArrayList<Color> colors;
|
||||
private ArrayList<String> names;
|
||||
private ArrayList<Integer> piecesThrown;
|
||||
@@ -40,8 +43,6 @@ public CeremonyNotification() {
|
||||
this.bonusNodes = new ArrayList<>();
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
/**
|
||||
* @return the list of colors
|
||||
*/
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* Notification that the dice is now.
|
||||
*/
|
||||
public class DiceNowNotification extends Notification {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
/**
|
||||
* Notification that is sent when a player has diced.
|
||||
*/
|
||||
public class DicingNotification extends Notification{
|
||||
|
||||
private Color color;
|
||||
public class DicingNotification extends Notification {
|
||||
/**
|
||||
* The color of the player that diced.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color The color of the player that diced.
|
||||
*/
|
||||
public DicingNotification(Color color) {
|
||||
@@ -19,6 +22,7 @@ public DicingNotification(Color color) {
|
||||
|
||||
/**
|
||||
* Get the color of the player that diced.
|
||||
*
|
||||
* @return The color of the player that diced.
|
||||
*/
|
||||
public Color getColor() {
|
||||
|
||||
@@ -6,14 +6,20 @@
|
||||
/**
|
||||
* Notification that a card has been drawn
|
||||
*/
|
||||
public class DrawCardNotification extends Notification {
|
||||
public class DrawCardNotification extends Notification {
|
||||
/**
|
||||
* The color of the player who drew the card
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
private Color color;
|
||||
private BonusCard card;
|
||||
/**
|
||||
* The card that was drawn
|
||||
*/
|
||||
private final BonusCard card;
|
||||
|
||||
/**
|
||||
* @param color the color of the player who drew the card
|
||||
* @param card the card that was drawn
|
||||
* @param card the card that was drawn
|
||||
*/
|
||||
public DrawCardNotification(Color color, BonusCard card) {
|
||||
this.color = color;
|
||||
|
||||
@@ -6,14 +6,20 @@
|
||||
* Notification that a piece has moved to a home.
|
||||
*/
|
||||
public class HomeMoveNotification extends Notification {
|
||||
/**
|
||||
* The unique identifier of the piece.
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
private UUID pieceId;
|
||||
private int homeIndex;
|
||||
/**
|
||||
* The index of the home position.
|
||||
*/
|
||||
private final int homeIndex;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pieceId the piece id
|
||||
* @param pieceId the piece id
|
||||
* @param homeIndex the home index
|
||||
*/
|
||||
public HomeMoveNotification(UUID pieceId, int homeIndex) {
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
* Notification that a card has been drawn
|
||||
*/
|
||||
public class InterruptNotification extends Notification {
|
||||
|
||||
private Color color;
|
||||
/**
|
||||
* The color of the player who disconnected
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* @param color the color of the player who disconnected
|
||||
|
||||
@@ -3,10 +3,5 @@
|
||||
/**
|
||||
* Notification that a dialog has been started
|
||||
*/
|
||||
public class LobbyDialogNotification extends Notification{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public LobbyDialogNotification() {
|
||||
}
|
||||
public class LobbyDialogNotification extends Notification {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class LobbyReadyNotification extends Notification{
|
||||
|
||||
/**
|
||||
* The color of the player.
|
||||
*/
|
||||
private Color color;
|
||||
|
||||
/**
|
||||
* Indicates if the player is ready.
|
||||
*/
|
||||
private boolean ready;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public LobbyReadyNotification(Color color, boolean ready) {
|
||||
this.color = color;
|
||||
this.ready = ready;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the color of the player
|
||||
*
|
||||
* @return the color of the player
|
||||
*/
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used to get the ready state of the player
|
||||
*
|
||||
* @return the ready state of the player
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return ready;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Notification that a piece has been moved.
|
||||
*/
|
||||
public class MovePieceNotification extends Notification {
|
||||
|
||||
/**
|
||||
* The unique identifier of the piece being moved.
|
||||
*/
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
* Notification that a piece has no shield.
|
||||
*/
|
||||
public class NoShieldNotification extends Notification{
|
||||
|
||||
private UUID pieceId;
|
||||
/**
|
||||
* The id of the piece that has no shield.
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
/**
|
||||
* Represents a notification that can be sent to a player.
|
||||
*/
|
||||
public abstract class Notification {
|
||||
}
|
||||
|
||||
@@ -7,14 +7,21 @@
|
||||
* Notification that a card has been played.
|
||||
*/
|
||||
public class PlayCardNotification extends Notification {
|
||||
/**
|
||||
* The color of the player that played the card.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
private Color color;
|
||||
private BonusCard card;
|
||||
/**
|
||||
* The card that was played.
|
||||
*/
|
||||
private final BonusCard card;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color the color of the player that played the card.
|
||||
* @param card the card that was played.
|
||||
* @param card the card that was played.
|
||||
*/
|
||||
public PlayCardNotification(Color color, BonusCard card) {
|
||||
this.color = color;
|
||||
@@ -23,6 +30,7 @@ public PlayCardNotification(Color color, BonusCard card) {
|
||||
|
||||
/**
|
||||
* Get the color of the player that played the card.
|
||||
*
|
||||
* @return the color of the player that played the card.
|
||||
*/
|
||||
public Color getColor() {
|
||||
@@ -31,6 +39,7 @@ public Color getColor() {
|
||||
|
||||
/**
|
||||
* Get the card that was played.
|
||||
*
|
||||
* @return the card that was played.
|
||||
*/
|
||||
public BonusCard getCard() {
|
||||
|
||||
@@ -9,17 +9,28 @@
|
||||
* Notification that a player is in the game.
|
||||
*/
|
||||
public class PlayerInGameNotification extends Notification {
|
||||
/**
|
||||
* The color of the player that is in the game.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
private Color color;
|
||||
private String name;
|
||||
private List<UUID> piecesList;
|
||||
/**
|
||||
* The name of the player that is in the game.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The list of piece IDs associated with the player.
|
||||
*/
|
||||
private final List<UUID> piecesList;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color the color of the player that is in the game.
|
||||
* @param name the name of the player that is in the game.
|
||||
* @param name the name of the player that is in the game.
|
||||
*/
|
||||
public PlayerInGameNotification(Color color, List<UUID> piecesList, String name) {
|
||||
public PlayerInGameNotification(Color color, List<UUID> piecesList, String name) {
|
||||
this.color = color;
|
||||
this.name = name;
|
||||
this.piecesList = piecesList;
|
||||
@@ -27,6 +38,7 @@ public PlayerInGameNotification(Color color, List<UUID> piecesList, String name
|
||||
|
||||
/**
|
||||
* Get the color of the player that is in the game.
|
||||
*
|
||||
* @return the color of the player that is in the game.
|
||||
*/
|
||||
public Color getColor() {
|
||||
@@ -35,12 +47,18 @@ public Color getColor() {
|
||||
|
||||
/**
|
||||
* Get the name of the player that is in the game.
|
||||
*
|
||||
* @return the name of the player that is in the game.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of piece IDs associated with the player.
|
||||
*
|
||||
* @return the list of piece IDs associated with the player.
|
||||
*/
|
||||
public List<UUID> getPiecesList() {
|
||||
return piecesList;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
* Notification that a player is in the game.
|
||||
*/
|
||||
public class ResumeNotification extends Notification {
|
||||
|
||||
private Color color;
|
||||
/**
|
||||
* The color of the player that is in the game.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color the color of the player that is in the game.
|
||||
*/
|
||||
public ResumeNotification(Color color) {
|
||||
@@ -19,6 +22,7 @@ public ResumeNotification(Color color) {
|
||||
|
||||
/**
|
||||
* Get the color of the player that is in the game.
|
||||
*
|
||||
* @return the color of the player that is in the game.
|
||||
*/
|
||||
public Color getColor() {
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
* Notification that contains a list of cards that the player can choose from.
|
||||
*/
|
||||
public class SelectableCardsNotification extends Notification {
|
||||
|
||||
private List<BonusCard> cards;
|
||||
/**
|
||||
* The list of cards that the player can choose from.
|
||||
*/
|
||||
private final List<BonusCard> cards;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
/**
|
||||
* Notification for selecting pieces and their possible moves.
|
||||
*/
|
||||
public class SelectableMoveNotification extends Notification{
|
||||
|
||||
public class SelectableMoveNotification extends Notification {
|
||||
/**
|
||||
* List of UUIDs representing the pieces that can be moved based on the dice roll.
|
||||
*/
|
||||
@@ -16,7 +15,7 @@ public class SelectableMoveNotification extends Notification{
|
||||
/**
|
||||
* List of integers representing the target nodes the pieces can move to.
|
||||
*/
|
||||
private final List<Integer> moveIndexe;
|
||||
private final List<Integer> moveIndices;
|
||||
|
||||
/**
|
||||
* List of booleans indicating whether the corresponding target nodes are in the home area.
|
||||
@@ -28,12 +27,12 @@ public class SelectableMoveNotification extends Notification{
|
||||
* Constructs a notification for selectable piece moves.
|
||||
*
|
||||
* @param pieces the list of pieces that can be moved
|
||||
* @param moveIndexe the list of target nodes for the moves
|
||||
* @param moveIndices the list of target nodes for the moves
|
||||
* @param homeMoves the list indicating if the target nodes are in the home area
|
||||
*/
|
||||
public SelectableMoveNotification(List<UUID> pieces, List<Integer> moveIndexe, List<Boolean> homeMoves) {
|
||||
public SelectableMoveNotification(List<UUID> pieces, List<Integer> moveIndices, List<Boolean> homeMoves) {
|
||||
this.pieces = pieces;
|
||||
this.moveIndexe = moveIndexe;
|
||||
this.moveIndices = moveIndices;
|
||||
this.homeMoves = homeMoves;
|
||||
}
|
||||
|
||||
@@ -51,8 +50,8 @@ public List<UUID> getPieces() {
|
||||
*
|
||||
* @return a list of integers representing the target nodes
|
||||
*/
|
||||
public List<Integer> getMoveIndexe() {
|
||||
return moveIndexe;
|
||||
public List<Integer> getMoveIndices() {
|
||||
return moveIndices;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
/**
|
||||
* Notification for selecting pieces for swapcard.
|
||||
*/
|
||||
public class SelectableSwapNotification extends Notification{
|
||||
|
||||
public class SelectableSwapNotification extends Notification {
|
||||
/**
|
||||
* List of UUIDs representing the player's own pieces available for selection.
|
||||
*/
|
||||
|
||||
@@ -5,9 +5,11 @@
|
||||
/**
|
||||
* This class will be used to hold all ShieldActiveNotification relevant data.
|
||||
*/
|
||||
public class ShieldActiveNotification extends Notification{
|
||||
|
||||
private UUID pieceId;
|
||||
public class ShieldActiveNotification extends Notification {
|
||||
/**
|
||||
* The pieceId
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new ShieldActiveNotification
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
* This class will be used to hold all ShieldSuppressedNotification relevant data.
|
||||
*/
|
||||
public class ShieldSuppressedNotification extends Notification {
|
||||
|
||||
private UUID pieceId;
|
||||
/**
|
||||
* The pieceId
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new ShieldSuppressedNotification
|
||||
|
||||
@@ -3,10 +3,5 @@
|
||||
/**
|
||||
* Notification that a dialog has been started
|
||||
*/
|
||||
public class StartDialogNotification extends Notification{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public StartDialogNotification() {
|
||||
}
|
||||
public class StartDialogNotification extends Notification {
|
||||
}
|
||||
|
||||
@@ -6,23 +6,31 @@
|
||||
* Notification that two pieces have been swapped.
|
||||
*/
|
||||
public class SwapPieceNotification extends Notification {
|
||||
/**
|
||||
* The UUID of the first piece that has been swapped.
|
||||
*/
|
||||
private final UUID firstPiece;
|
||||
|
||||
private UUID firstPiece;
|
||||
private UUID secondPiece;
|
||||
/**
|
||||
* The UUID of the second piece that has been swapped.
|
||||
*/
|
||||
private final UUID secondPiece;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param firstPiece the UUID of the first piece that has been swapped.
|
||||
*
|
||||
* @param firstPiece the UUID of the first piece that has been swapped.
|
||||
* @param secondPiece the UUID of the second piece that has been swapped.
|
||||
*/
|
||||
public SwapPieceNotification(UUID firstPiece, UUID secondPiece) {
|
||||
assert(!firstPiece.equals(secondPiece));
|
||||
assert (!firstPiece.equals(secondPiece));
|
||||
this.firstPiece = firstPiece;
|
||||
this.secondPiece = secondPiece;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UUID of the first piece that has been swapped.
|
||||
*
|
||||
* @return the UUID of the first piece that has been swapped.
|
||||
*/
|
||||
public UUID getFirstPiece() {
|
||||
@@ -31,6 +39,7 @@ public UUID getFirstPiece() {
|
||||
|
||||
/**
|
||||
* Get the UUID of the second piece that has been swapped.
|
||||
*
|
||||
* @return the UUID of the second piece that has been swapped.
|
||||
*/
|
||||
public UUID getSecondPiece() {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package pp.mdga.notification;
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ThrowPieceNotification extends Notification{
|
||||
|
||||
private UUID pieceId;
|
||||
/**
|
||||
* Notification that is sent when a piece is thrown.
|
||||
*/
|
||||
public class ThrowPieceNotification extends Notification {
|
||||
/**
|
||||
* The id of the piece that was thrown.
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
/**
|
||||
* This constructor is used to create a new ThrowPieceNotification
|
||||
@@ -15,6 +18,11 @@ public ThrowPieceNotification(UUID pieceId) {
|
||||
this.pieceId = pieceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the id of the piece that was thrown.
|
||||
*
|
||||
* @return The id of the piece that was thrown.
|
||||
*/
|
||||
public UUID getPieceId() {
|
||||
return pieceId;
|
||||
}
|
||||
|
||||
@@ -5,16 +5,27 @@
|
||||
/**
|
||||
* Class TskSelectNotification
|
||||
*/
|
||||
public class TskSelectNotification extends Notification{
|
||||
|
||||
public class TskSelectNotification extends Notification {
|
||||
/**
|
||||
* The color of the player that is in the game.
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* The name of the player that is in the game.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Indicates if the select notification affects the own user.
|
||||
*/
|
||||
private final boolean isSelf;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param color the color of the player that is in the game.
|
||||
* @param name the name of the player that is in the game.
|
||||
* @param name the name of the player that is in the game.
|
||||
*/
|
||||
public TskSelectNotification(Color color, String name, boolean isSelf) {
|
||||
this.color = color;
|
||||
@@ -24,6 +35,7 @@ public TskSelectNotification(Color color, String name, boolean isSelf) {
|
||||
|
||||
/**
|
||||
* Get the color of the player that is in the game.
|
||||
*
|
||||
* @return the color of the player that is in the game.
|
||||
*/
|
||||
public Color getColor() {
|
||||
@@ -32,6 +44,7 @@ public Color getColor() {
|
||||
|
||||
/**
|
||||
* Get the name of the player that is in the game.
|
||||
*
|
||||
* @return the name of the player that is in the game.
|
||||
*/
|
||||
public String getName() {
|
||||
|
||||
@@ -2,20 +2,27 @@
|
||||
|
||||
import pp.mdga.game.Color;
|
||||
|
||||
public class TskUnselectNotification extends Notification{
|
||||
|
||||
private Color color;
|
||||
/**
|
||||
* Notification for unselecting a player
|
||||
*/
|
||||
public class TskUnselectNotification extends Notification {
|
||||
/**
|
||||
* The color of the player
|
||||
*/
|
||||
private final Color color;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param color
|
||||
*
|
||||
* @param color the color of the player
|
||||
*/
|
||||
public TskUnselectNotification(Color color){
|
||||
public TskUnselectNotification(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color
|
||||
*
|
||||
* @return color
|
||||
*/
|
||||
public Color getColor() {
|
||||
|
||||
@@ -5,12 +5,15 @@
|
||||
/**
|
||||
* Notification to inform the player that he has to wait for the other player to move.
|
||||
*/
|
||||
public class WaitMoveNotification extends Notification{
|
||||
|
||||
private UUID pieceId;
|
||||
public class WaitMoveNotification extends Notification {
|
||||
/**
|
||||
* The id of the piece that has to move.
|
||||
*/
|
||||
private final UUID pieceId;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pieceId the id of the piece that has to move.
|
||||
*/
|
||||
public WaitMoveNotification(UUID pieceId) {
|
||||
@@ -19,6 +22,7 @@ public WaitMoveNotification(UUID pieceId) {
|
||||
|
||||
/**
|
||||
* Get the id of the piece that has to move.
|
||||
*
|
||||
* @return the id of the piece that has to move.
|
||||
*/
|
||||
public UUID getPieceId() {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class ChoosePieceState extends TurnState {
|
||||
public ChoosePieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
|
||||
public class DetermineStartPlayerState extends GameState {
|
||||
public DetermineStartPlayerState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class FirstRollStateState extends RollDiceState {
|
||||
public FirstRollStateState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class MovePieceState extends TurnState {
|
||||
public MovePieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class NoPieceState extends ChoosePieceState {
|
||||
public NoPieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class NoTurnState extends ChoosePieceState {
|
||||
public NoTurnState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class PowerCardState extends TurnState {
|
||||
public PowerCardState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class RollDiceState extends TurnState {
|
||||
public RollDiceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class SecondRollState extends RollDiceState {
|
||||
public SecondRollState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class SelectPieceState extends ChoosePieceState {
|
||||
public SelectPieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,10 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
* States
|
||||
*/
|
||||
private ServerState currentState;
|
||||
private final ServerState lobbyState;
|
||||
private final ServerState gameState;
|
||||
private final ServerState interruptState;
|
||||
private final ServerState ceremonyState;
|
||||
private final LobbyState lobbyState;
|
||||
private final GameState gameState;
|
||||
private final InterruptState interruptState;
|
||||
private final CeremonyState ceremonyState;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -167,36 +167,36 @@ public ServerState getCurrentState() {
|
||||
/**
|
||||
* This method will be used to return lobbyState attribute of ServerGameLogic class.
|
||||
*
|
||||
* @return lobbyState as a ServerState object.
|
||||
* @return lobbyState as a LobbyState object.
|
||||
*/
|
||||
public ServerState getLobbyState() {
|
||||
public LobbyState getLobbyState() {
|
||||
return this.lobbyState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return gameState attribute of ServerGameLogic class.
|
||||
*
|
||||
* @return gameState as a ServerState object.
|
||||
* @return gameState as a GameState object.
|
||||
*/
|
||||
public ServerState getGameState() {
|
||||
public GameState getGameState() {
|
||||
return this.gameState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return interruptState attribute of ServerGameLogic class.
|
||||
*
|
||||
* @return interruptState as a ServerState object.
|
||||
* @return interruptState as a InterruptState object.
|
||||
*/
|
||||
public ServerState getInterruptState() {
|
||||
public InterruptState getInterruptState() {
|
||||
return this.interruptState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return ceremonyState attribute of ServerGameLogic class.
|
||||
*
|
||||
* @return ceremonyState as a ServerState object.
|
||||
* @return ceremonyState as a CeremonyState object.
|
||||
*/
|
||||
public ServerState getCeremonyState() {
|
||||
public CeremonyState getCeremonyState() {
|
||||
return this.ceremonyState;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class StartPieceState extends ChoosePieceState {
|
||||
public StartPieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class ThirdRollState extends RollDiceState {
|
||||
public ThirdRollState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
|
||||
public class TurnState extends GameState {
|
||||
public TurnState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package pp.mdga.server;
|
||||
|
||||
public class WaitingPieceState extends ChoosePieceState {
|
||||
public WaitingPieceState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,11 @@
|
||||
*
|
||||
*/
|
||||
public class CeremonyState extends ServerState {
|
||||
/**
|
||||
* Create LobbyState constants.
|
||||
*/
|
||||
private static final System.Logger LOGGER = System.getLogger(CeremonyState.class.getName());
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -20,7 +25,7 @@ public CeremonyState(ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
// ToDo: Close server.
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered CeremonyState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,14 +1,34 @@
|
||||
package pp.mdga.server.automaton;
|
||||
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.message.client.DisconnectedMessage;
|
||||
import pp.mdga.message.client.LeaveGameMessage;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.PauseGameMessage;
|
||||
import pp.mdga.server.automaton.game.AnimationState;
|
||||
import pp.mdga.server.automaton.game.DetermineStartPlayerState;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.GameAutomatonState;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class represents the game state of this application.
|
||||
* In Addition, it will be used as a state machine for the game process.
|
||||
*/
|
||||
public class GameState extends ServerState {
|
||||
/**
|
||||
* Create LobbyState constants.
|
||||
*/
|
||||
private static final System.Logger LOGGER = System.getLogger(GameState.class.getName());
|
||||
|
||||
/**
|
||||
* Create GameState states.
|
||||
*/
|
||||
private GameAutomatonState currentState;
|
||||
private final GameAutomatonState determineStartPlayerState;
|
||||
private final GameAutomatonState animationState;
|
||||
private final GameAutomatonState turnState;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -16,6 +36,10 @@ public class GameState extends ServerState {
|
||||
*/
|
||||
public GameState(ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.determineStartPlayerState = new DetermineStartPlayerState(this, logic);
|
||||
this.animationState = new AnimationState(this, logic);
|
||||
this.turnState = new TurnState(this, logic);
|
||||
this.setCurrentState(this.determineStartPlayerState);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,7 +47,7 @@ public GameState(ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered GameState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,6 +59,8 @@ public void exit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a DisconnectedMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a Disconnected object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
@@ -46,6 +72,8 @@ public void received(DisconnectedMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received an LeaveGameMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a LeaveGame object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
@@ -57,4 +85,78 @@ public void received(LeaveGameMessage msg, int from) {
|
||||
this.logic.setCurrentState(this.logic.getCeremonyState());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a RequestDieMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a RequestDieMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(RequestDieMessage msg, int from) {
|
||||
this.currentState.received(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received an AnimationEndMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a AnimationEndMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
this.currentState.received(msg, from);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return currentState attribute of GameState class.
|
||||
*
|
||||
* @return currentState as a GameAutomatonState object.
|
||||
*/
|
||||
public GameAutomatonState getCurrentState() {
|
||||
return this.currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return determineStartPlayerState attribute of GameState class.
|
||||
*
|
||||
* @return determineStartPlayerState as a GameAutomatonState object.
|
||||
*/
|
||||
public GameAutomatonState getDetermineStartPlayerState() {
|
||||
return this.determineStartPlayerState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return animationState attribute of GameState class.
|
||||
*
|
||||
* @return animationState as a GameAutomatonState object.
|
||||
*/
|
||||
public GameAutomatonState getAnimationState() {
|
||||
return this.animationState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return turnState attribute of GameState class.
|
||||
*
|
||||
* @return turnState as a GameAutomatonState object.
|
||||
*/
|
||||
public GameAutomatonState getTurnState() {
|
||||
return this.turnState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to set currentState attribute of GameState class to the given state parameter.
|
||||
* In Addition, the currentState will be exited, changed and entered.
|
||||
*
|
||||
* @param state as the new currentState attribute as a GameAutomatonState object.
|
||||
*/
|
||||
public void setCurrentState(GameAutomatonState state) {
|
||||
if (this.currentState != null) {
|
||||
this.currentState.exit();
|
||||
}
|
||||
this.currentState = state;
|
||||
this.currentState.enter();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
*
|
||||
*/
|
||||
public class InterruptState extends ServerState {
|
||||
/**
|
||||
* Create LobbyState constants.
|
||||
*/
|
||||
private static final System.Logger LOGGER = System.getLogger(InterruptState.class.getName());
|
||||
|
||||
/**
|
||||
* Attributes.
|
||||
*/
|
||||
@@ -28,7 +33,7 @@ public InterruptState(ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
// Create timer and connect signal.
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered InterruptState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,6 +44,13 @@ public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a ForceContinueGameMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a ForceContinueGameMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(ForceContinueGameMessage msg, int from) {
|
||||
this.logic.getServerSender().broadcast(new ResumeGameMessage());
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
* It will handle all join and disconnect messages, as well the selection of the color of the player.
|
||||
*/
|
||||
public class LobbyState extends ServerState {
|
||||
/**
|
||||
* Create LobbyState constants.
|
||||
*/
|
||||
private static final System.Logger LOGGER = System.getLogger(ServerState.class.getName());
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
@@ -27,7 +32,7 @@ public LobbyState(ServerGameLogic logic) {
|
||||
*/
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered LobbyState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,17 +44,24 @@ public void exit() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a JoinedLobbyMessage message.
|
||||
* It will also get the client id of the player who send this messag
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a JoinedLobbyMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(JoinedLobbyMessage msg, int from) {
|
||||
Player player = new Player(msg.getName());
|
||||
player.setColor(Color.getColorByIndex(this.logic.getGame().getPlayers().size()));
|
||||
this.logic.getGame().addPlayer(from, player);
|
||||
this.logic.getServerSender().broadcast(new LobbyPlayerJoinedMessage(from, player));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a SelectTSKMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a SelectTSK object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@@ -65,6 +77,9 @@ public void received(SelectTSKMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a DeselectTSKMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a DeselectTSK object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@@ -75,6 +90,9 @@ public void received(DeselectTSKMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a LobbyReadyMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a LobbyReady object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@@ -92,6 +110,9 @@ public void received(LobbyReadyMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a LobbyNotReadyMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a LobbyNotReady object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@@ -103,6 +124,8 @@ public void received(LobbyNotReadyMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received an LeaveGameMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a LeaveGameMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
@@ -115,6 +138,9 @@ public void received(LeaveGameMessage msg, int from) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a StartGame message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a ForceStartGame object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package pp.mdga.server.automaton.game;
|
||||
|
||||
import pp.mdga.message.client.AnimationEndMessage;
|
||||
import pp.mdga.message.server.DiceNowMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
|
||||
/**
|
||||
* This class represents the animation state of the game state.
|
||||
*
|
||||
*/
|
||||
public class AnimationState extends GameAutomatonState {
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public AnimationState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||
super(gameAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received an AnimationEndMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a AnimationEndMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(AnimationEndMessage msg, int from) {
|
||||
this.logic.getServerSender().send(from, new DiceNowMessage());
|
||||
this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package pp.mdga.server.automaton.game;
|
||||
|
||||
import pp.mdga.game.Player;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DetermineStartPlayerState extends GameAutomatonState {
|
||||
/**
|
||||
* Create DetermineStartPlayerState attributes.
|
||||
*/
|
||||
private Map<Player, Integer> diceResults = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public DetermineStartPlayerState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||
super(gameAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be called whenever the server received a RequestDieMessage message.
|
||||
* It will also get the client id of the player who send this message.
|
||||
*
|
||||
* @param msg as the message which was sent by the player as a RequestDieMessage object.
|
||||
* @param from as the client id of the player as an Integer.
|
||||
*/
|
||||
@Override
|
||||
public void received(RequestDieMessage msg, int from) {
|
||||
int roll = this.logic.getGame().getDie().shuffle();
|
||||
this.diceResults.put(this.logic.getGame().getPlayerById(from), roll);
|
||||
if (this.diceResults.size() == this.logic.getGame().getPlayers().size()) {
|
||||
Map<Integer, Long> frequencyMap = diceResults.values().stream()
|
||||
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
|
||||
Map.Entry<Integer, Long> result = frequencyMap.entrySet().stream()
|
||||
.max(Map.Entry.comparingByKey())
|
||||
.orElseThrow(() -> new IllegalStateException("Die Map ist leer"));
|
||||
}
|
||||
this.logic.getServerSender().send(from, new DieMessage(roll));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return diceResults attribute of DetermineStartPlayerState class.
|
||||
*
|
||||
* @return diceResults as a Map combing Player objects and Integers.
|
||||
*/
|
||||
public Map<Player, Integer> getDiceResults() {
|
||||
return this.diceResults;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package pp.mdga.server.automaton.game;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
|
||||
/**
|
||||
* This abstract class represents the game automaton state of the game state automaton.
|
||||
*/
|
||||
public abstract class GameAutomatonState extends ServerState {
|
||||
/**
|
||||
* Create GameAutomatonState attributes.
|
||||
*/
|
||||
protected final GameState gameAutomaton;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public GameAutomatonState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.gameAutomaton = gameAutomaton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package pp.mdga.server.automaton.game;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.GameState;
|
||||
import pp.mdga.server.automaton.game.turn.*;
|
||||
|
||||
/**
|
||||
* This class represents the turn state of the server state automaton.
|
||||
* It will also be used as the turn automaton.
|
||||
*/
|
||||
public class TurnState extends GameAutomatonState {
|
||||
/**
|
||||
* Create TurnState states.
|
||||
*/
|
||||
private TurnAutomatonState currentState;
|
||||
private final PowerCardState powerCardState;
|
||||
private final PlayPowerCardState playPowerCardState;
|
||||
private final RollDiceState rollDiceState;
|
||||
private final ChoosePieceState choosePieceState;
|
||||
private final MovePieceState movePieceState;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param gameAutomaton as the automaton of the game state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public TurnState(GameState gameAutomaton, ServerGameLogic logic) {
|
||||
super(gameAutomaton, logic);
|
||||
this.powerCardState = new PowerCardState(this, logic);
|
||||
this.playPowerCardState = new PlayPowerCardState(this, logic);
|
||||
this.rollDiceState = new RollDiceState(this, logic);
|
||||
this.choosePieceState = new ChoosePieceState(this, logic);
|
||||
this.movePieceState = new MovePieceState(this, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return currentState attribute of TurnState class.
|
||||
*
|
||||
* @return currentState as a TurnAutomatonState object.
|
||||
*/
|
||||
public TurnAutomatonState getCurrentState() {
|
||||
return this.currentState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return powerCardState attribute of TurnState class.
|
||||
*
|
||||
* @return powerCardState as a PowerCardState object.
|
||||
*/
|
||||
public PowerCardState getPowerCardState() {
|
||||
return this.powerCardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return playPowerCardState attribute of TurnState class.
|
||||
*
|
||||
* @return playPowerState as a PlayPowerCardState object.
|
||||
*/
|
||||
public PlayPowerCardState getPlayPowerCardState() {
|
||||
return this.playPowerCardState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return rollDiceState attribute of TurnState class.
|
||||
*
|
||||
* @return rollDiceState as a RollDiceState object.
|
||||
*/
|
||||
public RollDiceState getRollDiceState() {
|
||||
return this.rollDiceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return choosePieceState attribute of TurnState class.
|
||||
*
|
||||
* @return choosePieceState as a ChoosePieceState object.
|
||||
*/
|
||||
public ChoosePieceState getChoosePieceState() {
|
||||
return this.choosePieceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to return movePieceState attribute of TurnState class.
|
||||
*
|
||||
* @return movePieceState as a MovePieceState object.
|
||||
*/
|
||||
public MovePieceState getMovePieceState() {
|
||||
return this.movePieceState;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will be used to set currentState attribute of TurnState class to the given state parameter.
|
||||
* In Addition, the currentState will be exited, changed and entered.
|
||||
*
|
||||
* @param state as the new currentState attribute as a TurnAutomatonState object.
|
||||
*/
|
||||
public void setCurrentState(TurnAutomatonState state) {
|
||||
if (this.currentState != null) {
|
||||
this.currentState.exit();
|
||||
}
|
||||
this.currentState = state;
|
||||
this.currentState.enter();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public class ChoosePieceState extends TurnAutomatonState {
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public ChoosePieceState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(turnAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public class MovePieceState extends TurnAutomatonState {
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public MovePieceState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(turnAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public class PlayPowerCardState extends TurnAutomatonState {
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public PlayPowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(turnAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public class PowerCardState extends TurnAutomatonState {
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(turnAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public class RollDiceState extends TurnAutomatonState {
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(turnAutomaton, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package pp.mdga.server.automaton.game.turn;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
import pp.mdga.server.automaton.game.TurnState;
|
||||
|
||||
public abstract class TurnAutomatonState extends ServerState {
|
||||
/**
|
||||
* Create TurnAutomatonState attributes.
|
||||
*/
|
||||
protected final TurnState turnAutomaton;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param turnAutomaton as the automaton of the turn state as a GameState object.
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public TurnAutomatonState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.turnAutomaton = turnAutomaton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public abstract class ChoosePieceAutomatonState extends ServerState {
|
||||
/**
|
||||
* Create ChoosePieceAutomatonState attributes.
|
||||
*/
|
||||
protected final ChoosePieceState choosePieceAutomaton;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public ChoosePieceAutomatonState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.choosePieceAutomaton = choosePieceAutomaton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public class NoPieceState {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public class NoTurnState {
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public class SelectPieceState {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public class StartPieceState {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||
|
||||
public class WaitingPieceState {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
public class FirstRollStateState {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.ServerState;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
public abstract class RollDiceAutomatonState extends ServerState {
|
||||
/**
|
||||
* Create RollDiceAutomatonState attributes.
|
||||
*/
|
||||
protected final RollDiceState rollDiceAutomaton;
|
||||
|
||||
/**
|
||||
* Constructs a server state of the specified game logic.
|
||||
*
|
||||
* @param logic the game logic
|
||||
*/
|
||||
public RollDiceAutomatonState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
||||
super(logic);
|
||||
this.rollDiceAutomaton = rollDiceAutomaton;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
public class SecondRollState {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
public class ThirdRollState {
|
||||
}
|
||||
Reference in New Issue
Block a user