created the first part of the cliejnt state machine with its corresponding logic
This commit is contained in:
		@@ -1,12 +1,14 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.BonusCard;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Game;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PlayerData;
 | 
			
		||||
import pp.mdga.message.client.ClientMessage;
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
import pp.mdga.notification.*;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@@ -16,13 +18,12 @@ public class ClientGameLogic implements ServerInterpreter {
 | 
			
		||||
    private Game game;
 | 
			
		||||
    private final ClientSender clientSender;
 | 
			
		||||
    private ClientState state;
 | 
			
		||||
    private Map<UUID, Piece> pieces;
 | 
			
		||||
    private Map<UUID, BonusCard> cards;
 | 
			
		||||
    private final ArrayList<Notification> notifications = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    private Dialogs dialogs = new Dialogs(null, this);
 | 
			
		||||
    private GameState gameState = new GameState(null, this);
 | 
			
		||||
    private Ceremony ceremony = new Ceremony(null, this);
 | 
			
		||||
    private Interrupt interrupt = new Interrupt(null, this);
 | 
			
		||||
    private final Dialogs dialogs = new Dialogs(null, this);
 | 
			
		||||
    private final GameState gameState = new GameState(null, this);
 | 
			
		||||
    private final Ceremony ceremony = new Ceremony(null, this);
 | 
			
		||||
    private final Interrupt interrupt = new Interrupt(null, this);
 | 
			
		||||
 | 
			
		||||
    public ClientGameLogic(Game game, ClientSender clientSender) {
 | 
			
		||||
        this.game = game;
 | 
			
		||||
@@ -35,6 +36,17 @@ public void send(ClientMessage msg){
 | 
			
		||||
        clientSender.send(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Piece getPiece(UUID pieceId){
 | 
			
		||||
        for(Map.Entry<Color, PlayerData> entry : game.getBoard().getPlayerData().entrySet()){
 | 
			
		||||
            for(Piece piece : entry.getValue().getPieces()){
 | 
			
		||||
                if(piece.getUuid().equals(pieceId)){
 | 
			
		||||
                    return piece;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ClientSender getClientSender(){
 | 
			
		||||
        return clientSender;
 | 
			
		||||
    }
 | 
			
		||||
@@ -188,11 +200,12 @@ public void received(Spectator msg) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectPiece(UUID pieceId){
 | 
			
		||||
        state.selectPiece(pieceId);
 | 
			
		||||
        state.selectPiece(getPiece(pieceId));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: implement
 | 
			
		||||
    public void selectCard(UUID cardId){
 | 
			
		||||
        state.selectCard(cardId);
 | 
			
		||||
        state.selectCard(null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectTsk(Color color){
 | 
			
		||||
@@ -211,16 +224,20 @@ public void selectReady(boolean ready){
 | 
			
		||||
        state.selectReady();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectHost(){
 | 
			
		||||
        state.selectHost();
 | 
			
		||||
    public void selectHost(String name){
 | 
			
		||||
        state.selectHost(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectLeave(){
 | 
			
		||||
        state.selectLeave();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectJoin(){
 | 
			
		||||
        state.selectJoin();
 | 
			
		||||
    public void selectJoin(String name){
 | 
			
		||||
        state.selectJoin(name);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
        state.selectAnimationEnd();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectStart(){
 | 
			
		||||
@@ -229,6 +246,7 @@ public void selectStart(){
 | 
			
		||||
 | 
			
		||||
    public void setState(ClientState state){
 | 
			
		||||
        this.state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -247,4 +265,9 @@ public Interrupt getInterrupt(){
 | 
			
		||||
    public Dialogs getDialogs(){
 | 
			
		||||
        return dialogs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Notification getNotification(){
 | 
			
		||||
        return notifications.remove(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.game.BonusCard;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.server.*;
 | 
			
		||||
 | 
			
		||||
import java.lang.System.Logger.Level;
 | 
			
		||||
@@ -173,11 +175,11 @@ public void received(WaitPiece msg) {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Received {0} not allowed.", msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectPiece(UUID id) {
 | 
			
		||||
    public void selectPiece(Piece piece) {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Selecting piece not allowed.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectCard(UUID id) {
 | 
			
		||||
    public void selectCard(BonusCard card) {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Selecting card not allowed.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -197,11 +199,11 @@ public void selectReady() {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Selecting ready not allowed.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectHost() {
 | 
			
		||||
    public void selectHost(String name) {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Selecting host not allowed.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectJoin() {
 | 
			
		||||
    public void selectJoin(String name) {
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Selecting join not allowed.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -220,4 +222,8 @@ public void selectUnready(){
 | 
			
		||||
    public void selectStart(){
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Starting not allowed");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
        LOGGER.log(Level.DEBUG, "Animation end not allowed");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,11 +4,16 @@
 | 
			
		||||
import pp.mdga.client.dialogState.Lobby;
 | 
			
		||||
import pp.mdga.client.dialogState.NetworkDialog;
 | 
			
		||||
import pp.mdga.client.dialogState.StartDialog;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.server.LobbyPlayerJoin;
 | 
			
		||||
import pp.mdga.message.server.LobbyPlayerLeave;
 | 
			
		||||
 | 
			
		||||
public class Dialogs extends ClientState {
 | 
			
		||||
 | 
			
		||||
    private DialogStates currentState;
 | 
			
		||||
 | 
			
		||||
    private Player ownPlayer;
 | 
			
		||||
 | 
			
		||||
    private final Lobby lobby = new Lobby(this, logic);
 | 
			
		||||
    private final NetworkDialog networkDialog = new NetworkDialog(this, logic);
 | 
			
		||||
    private final StartDialog startDialog = new StartDialog(this, logic);
 | 
			
		||||
@@ -30,8 +35,12 @@ public void enter(){
 | 
			
		||||
 | 
			
		||||
    public void setState(DialogStates newState){
 | 
			
		||||
        currentState.exit();
 | 
			
		||||
        currentState = newState;
 | 
			
		||||
        currentState.enter();
 | 
			
		||||
        currentState = newState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Player getOwnPlayer() {
 | 
			
		||||
        return ownPlayer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Lobby getLobby() {
 | 
			
		||||
@@ -50,4 +59,14 @@ public void startGame(){
 | 
			
		||||
        exit();
 | 
			
		||||
        logic.setState(logic.getGameState());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerJoin msg){
 | 
			
		||||
        currentState.received(msg);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerLeave msg){
 | 
			
		||||
        currentState.received(msg);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,16 +1,17 @@
 | 
			
		||||
package pp.mdga.client;
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.gameState.*;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
 | 
			
		||||
public class GameState extends ClientState {
 | 
			
		||||
 | 
			
		||||
    private GameStates state;
 | 
			
		||||
 | 
			
		||||
    private Animation animation = new Animation(this, logic);
 | 
			
		||||
    private DetermineStartPlayer determineStartPlayer = new DetermineStartPlayer(this, logic);
 | 
			
		||||
    private Spectator spectator  = new Spectator(this, logic);
 | 
			
		||||
    private Turn turn = new Turn(this, logic);
 | 
			
		||||
    private Waiting waiting = new Waiting(this, logic);
 | 
			
		||||
    private final Animation animation = new Animation(this, logic);
 | 
			
		||||
    private final DetermineStartPlayer determineStartPlayer = new DetermineStartPlayer(this, logic);
 | 
			
		||||
    private final Spectator spectator  = new Spectator(this, logic);
 | 
			
		||||
    private final Turn turn = new Turn(this, logic);
 | 
			
		||||
    private final Waiting waiting = new Waiting(this, logic);
 | 
			
		||||
 | 
			
		||||
    public GameState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
@@ -26,4 +27,35 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(GameStates newState){
 | 
			
		||||
        state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        state = newState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
        state.selectAnimationEnd();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Animation getAnimation() {
 | 
			
		||||
        return animation;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public DetermineStartPlayer getDetermineStartPlayer() {
 | 
			
		||||
        return determineStartPlayer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Spectator getSpectator() {
 | 
			
		||||
        return spectator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Turn getTurn() {
 | 
			
		||||
        return turn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Waiting getWaiting() {
 | 
			
		||||
        return waiting;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,10 @@
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.Dialogs;
 | 
			
		||||
import pp.mdga.game.Color;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
import pp.mdga.message.client.*;
 | 
			
		||||
import pp.mdga.message.server.LobbyPlayerJoin;
 | 
			
		||||
import pp.mdga.message.server.LobbyPlayerLeave;
 | 
			
		||||
import pp.mdga.message.server.ServerStartGame;
 | 
			
		||||
 | 
			
		||||
public class Lobby extends DialogStates {
 | 
			
		||||
@@ -60,4 +63,14 @@ public void selectStart(){
 | 
			
		||||
    public void received(ServerStartGame msg){
 | 
			
		||||
        parent.startGame();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerJoin msg){
 | 
			
		||||
        logic.getGame().getPlayers().put(msg.getId(), new Player(msg.getName()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(LobbyPlayerLeave msg){
 | 
			
		||||
        logic.getGame().getPlayers().remove(msg.getId());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,8 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectBack() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectLeave() {
 | 
			
		||||
        parent.setState(parent.getStartDialog());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.Dialogs;
 | 
			
		||||
import pp.mdga.game.Player;
 | 
			
		||||
 | 
			
		||||
public class StartDialog extends DialogStates {
 | 
			
		||||
 | 
			
		||||
@@ -23,11 +24,13 @@ public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectJoin() {
 | 
			
		||||
    public void selectJoin(String name) {
 | 
			
		||||
        parent.getOwnPlayer().setName(name);
 | 
			
		||||
        parent.setState(parent.getNetworkDialog());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectHost() {
 | 
			
		||||
    public void selectHost(String name) {
 | 
			
		||||
        parent.getOwnPlayer().setName(name);
 | 
			
		||||
        parent.setState(parent.getLobby());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,16 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.message.client.AnimationEnd;
 | 
			
		||||
 | 
			
		||||
public class Animation extends GameStates {
 | 
			
		||||
 | 
			
		||||
    private final GameState parent;
 | 
			
		||||
 | 
			
		||||
    public Animation(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (GameState) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -17,4 +23,10 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectAnimationEnd(){
 | 
			
		||||
        logic.send(new AnimationEnd());
 | 
			
		||||
        parent.setState(parent.getWaiting());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,20 +2,45 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.client.gameState.determineStartPlayerState.DetermineStartPlayerStates;
 | 
			
		||||
import pp.mdga.client.gameState.determineStartPlayerState.RollRankingDice;
 | 
			
		||||
import pp.mdga.client.gameState.determineStartPlayerState.WaitRanking;
 | 
			
		||||
 | 
			
		||||
public class DetermineStartPlayer extends GameStates {
 | 
			
		||||
 | 
			
		||||
    private final GameState parent;
 | 
			
		||||
    private DetermineStartPlayerStates state;
 | 
			
		||||
 | 
			
		||||
    private final RollRankingDice rollRankingDice = new RollRankingDice(this, logic);
 | 
			
		||||
    private final WaitRanking waitRanking = new WaitRanking(this, logic);
 | 
			
		||||
 | 
			
		||||
    public DetermineStartPlayer(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (GameState) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        state = rollRankingDice;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        state = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(DetermineStartPlayerStates state) {
 | 
			
		||||
        this.state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RollRankingDice getRollRankingDice() {
 | 
			
		||||
        return rollRankingDice;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public WaitRanking getWaitRanking() {
 | 
			
		||||
        return waitRanking;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
 | 
			
		||||
public class Spectator extends GameStates {
 | 
			
		||||
    public Spectator(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
@@ -17,4 +18,9 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg){
 | 
			
		||||
        logic.setState(logic.getCeremony());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,20 +2,87 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.ChoosePiece;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.MovePiece;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.PlayPowerCard;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.PowerCard;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.RollDice;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.TurnStates;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurn;
 | 
			
		||||
import pp.mdga.message.server.NoTurn;
 | 
			
		||||
import pp.mdga.message.server.Spectator;
 | 
			
		||||
 | 
			
		||||
public class Turn extends GameStates {
 | 
			
		||||
 | 
			
		||||
    private GameState parent;
 | 
			
		||||
    private TurnStates state;
 | 
			
		||||
 | 
			
		||||
    private final ChoosePiece choosePiece = new ChoosePiece(this, logic);
 | 
			
		||||
    private final MovePiece movePiece = new MovePiece(this, logic);
 | 
			
		||||
    private final PlayPowerCard playPowerCard = new PlayPowerCard(this, logic);
 | 
			
		||||
    private final PowerCard powerCard = new PowerCard(this, logic);
 | 
			
		||||
    private final RollDice rollDice = new RollDice(this, logic);
 | 
			
		||||
 | 
			
		||||
    public Turn(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (GameState) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        state = powerCard;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        state = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(TurnStates state){
 | 
			
		||||
        this.state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(NoTurn msg){
 | 
			
		||||
        parent.setState(parent.getWaiting());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(EndOfTurn msg){
 | 
			
		||||
        parent.setState(parent.getWaiting());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg){
 | 
			
		||||
        logic.setState(logic.getCeremony());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(Spectator msg){
 | 
			
		||||
        parent.setState(parent.getSpectator());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ChoosePiece getChoosePiece() {
 | 
			
		||||
        return choosePiece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MovePiece getMovePiece() {
 | 
			
		||||
        return movePiece;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PlayPowerCard getPlayPowerCard() {
 | 
			
		||||
        return playPowerCard;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PowerCard getPowerCard() {
 | 
			
		||||
        return powerCard;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RollDice getRollDice() {
 | 
			
		||||
        return rollDice;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,19 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.message.client.AnimationEnd;
 | 
			
		||||
import pp.mdga.message.server.CeremonyMessage;
 | 
			
		||||
import pp.mdga.message.server.DiceNow;
 | 
			
		||||
import pp.mdga.message.server.EndOfTurn;
 | 
			
		||||
 | 
			
		||||
public class Waiting extends GameStates {
 | 
			
		||||
 | 
			
		||||
    private final GameState parent;
 | 
			
		||||
 | 
			
		||||
    public Waiting(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (GameState) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -17,4 +26,19 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg){
 | 
			
		||||
        logic.setState(logic.getCeremony());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DiceNow msg){
 | 
			
		||||
        parent.setState(parent.getTurn());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(EndOfTurn msg){
 | 
			
		||||
        parent.setState(parent.getWaiting());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,17 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.DetermineStartPlayer;
 | 
			
		||||
import pp.mdga.message.client.RequestDie;
 | 
			
		||||
import pp.mdga.message.server.Die;
 | 
			
		||||
 | 
			
		||||
public class RollRankingDice extends DetermineStartPlayerStates {
 | 
			
		||||
 | 
			
		||||
    private final DetermineStartPlayer parent;
 | 
			
		||||
 | 
			
		||||
    public RollRankingDice(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (DetermineStartPlayer) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -17,4 +24,14 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectDice(){
 | 
			
		||||
        logic.send(new RequestDie());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(Die msg){
 | 
			
		||||
        parent.setState(parent.getWaitRanking());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,18 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.DetermineStartPlayer;
 | 
			
		||||
import pp.mdga.client.gameState.GameStates;
 | 
			
		||||
import pp.mdga.message.server.RankingResponse;
 | 
			
		||||
import pp.mdga.message.server.RankingRollAgain;
 | 
			
		||||
 | 
			
		||||
public class WaitRanking extends DetermineStartPlayerStates {
 | 
			
		||||
 | 
			
		||||
    private final DetermineStartPlayer parent;
 | 
			
		||||
 | 
			
		||||
public class WaitRanking extends GameStates {
 | 
			
		||||
    public WaitRanking(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (DetermineStartPlayer) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -18,4 +25,14 @@ public void enter() {
 | 
			
		||||
    public void exit() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RankingRollAgain msg){
 | 
			
		||||
        parent.setState(parent.getRollRankingDice());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(RankingResponse msg){
 | 
			
		||||
        //TODO: implement
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,18 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.Turn;
 | 
			
		||||
import pp.mdga.message.server.PlayCard;
 | 
			
		||||
 | 
			
		||||
public class PlayPowerCard extends TurnStates {
 | 
			
		||||
 | 
			
		||||
    private final Turn parent;
 | 
			
		||||
 | 
			
		||||
    private PlayCard playCard;
 | 
			
		||||
 | 
			
		||||
    public PlayPowerCard(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (Turn) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
@@ -15,6 +23,10 @@ public void enter() {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        playCard = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPlayCard(PlayCard playCard) {
 | 
			
		||||
        this.playCard = playCard;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,20 +2,57 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.client.gameState.Turn;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.powerCardState.ChoosePowerCard;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.powerCardState.PowerCardStates;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.powerCardState.Shield;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.powerCardState.Swap;
 | 
			
		||||
 | 
			
		||||
public class PowerCard extends TurnStates {
 | 
			
		||||
 | 
			
		||||
    private final Turn parent;
 | 
			
		||||
    private PowerCardStates state;
 | 
			
		||||
 | 
			
		||||
    private final ChoosePowerCard choosePowerCard = new ChoosePowerCard(this, logic);
 | 
			
		||||
    private final Shield shield = new Shield(this, logic);
 | 
			
		||||
    private final Swap swap = new Swap(this, logic);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public PowerCard(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (Turn) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        state = choosePowerCard;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        state = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setState(PowerCardStates state) {
 | 
			
		||||
        this.state.exit();
 | 
			
		||||
        state.enter();
 | 
			
		||||
        this.state = state;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ChoosePowerCard getChoosePowerCard() {
 | 
			
		||||
        return choosePowerCard;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Shield getShield() {
 | 
			
		||||
        return shield;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Swap getSwap() {
 | 
			
		||||
        return swap;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Turn getParent() {
 | 
			
		||||
        return parent;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,19 +2,67 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.PowerCard;
 | 
			
		||||
import pp.mdga.game.BonusCard;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.client.NoPowerCard;
 | 
			
		||||
import pp.mdga.message.client.RequestPlayCard;
 | 
			
		||||
import pp.mdga.message.client.SelectCard;
 | 
			
		||||
import pp.mdga.message.server.DiceNow;
 | 
			
		||||
import pp.mdga.message.server.PossibleCard;
 | 
			
		||||
import pp.mdga.message.server.PossiblePiece;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class ChoosePowerCard extends PowerCardStates {
 | 
			
		||||
 | 
			
		||||
    private final PowerCard parent;
 | 
			
		||||
    private ArrayList<BonusCard> possibleCards;
 | 
			
		||||
 | 
			
		||||
    public ChoosePowerCard(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (PowerCard) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        possibleCards = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        possibleCards = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PossibleCard msg){
 | 
			
		||||
        possibleCards = (ArrayList<BonusCard>) msg.getPossibleCards();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectCard(BonusCard card){
 | 
			
		||||
        if(card != null){
 | 
			
		||||
            logic.send(new SelectCard(card));
 | 
			
		||||
        } else {
 | 
			
		||||
            logic.send(new NoPowerCard());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DiceNow msg){
 | 
			
		||||
        parent.getParent().setState(parent.getParent().getRollDice());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PossiblePiece msg){
 | 
			
		||||
        if (msg.getEnemyPossiblePieces().isEmpty()){
 | 
			
		||||
            parent.setState(parent.getShield());
 | 
			
		||||
            parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
 | 
			
		||||
        } else {
 | 
			
		||||
            parent.setState(parent.getSwap());
 | 
			
		||||
            parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
 | 
			
		||||
            parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,19 +2,53 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.PowerCard;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.client.RequestPlayCard;
 | 
			
		||||
import pp.mdga.message.client.SelectedPieces;
 | 
			
		||||
import pp.mdga.message.server.PlayCard;
 | 
			
		||||
import pp.mdga.server.TurnState;
 | 
			
		||||
 | 
			
		||||
import java.lang.System.Logger.Level;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class Shield extends PowerCardStates {
 | 
			
		||||
 | 
			
		||||
    private final PowerCard parent;
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Piece> possiblePieces;
 | 
			
		||||
 | 
			
		||||
    public Shield(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (PowerCard) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        possiblePieces = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        possiblePieces = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
 | 
			
		||||
        this.possiblePieces = possiblePieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void selectPiece(Piece piece) {
 | 
			
		||||
        if (possiblePieces.contains(piece)) {
 | 
			
		||||
            logic.send(RequestPlayCard.requestPlayShield(piece.getIdentifier()));
 | 
			
		||||
        } else {
 | 
			
		||||
            LOGGER.log(Level.DEBUG, "Invalid piece selected");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCard msg) {
 | 
			
		||||
        parent.getParent().setState(parent.getParent().getPlayPowerCard());
 | 
			
		||||
        parent.getParent().getPlayPowerCard().setPlayCard(msg);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,19 +2,62 @@
 | 
			
		||||
 | 
			
		||||
import pp.mdga.client.ClientGameLogic;
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.gameState.turnState.PowerCard;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.message.client.RequestPlayCard;
 | 
			
		||||
import pp.mdga.message.server.PlayCard;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class Swap extends PowerCardStates {
 | 
			
		||||
 | 
			
		||||
    private final PowerCard parent;
 | 
			
		||||
 | 
			
		||||
    private ArrayList<Piece> possibleOwnPieces;
 | 
			
		||||
    private ArrayList<Piece> possibleEnemyPieces;
 | 
			
		||||
    private Piece selectedOwnPiece;
 | 
			
		||||
    private Piece selectedEnemyPiece;
 | 
			
		||||
 | 
			
		||||
    public Swap(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
        super(parent, logic);
 | 
			
		||||
        this.parent = (PowerCard) parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        possibleOwnPieces = new ArrayList<>();
 | 
			
		||||
        possibleEnemyPieces = new ArrayList<>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        possibleOwnPieces = null;
 | 
			
		||||
        possibleEnemyPieces = null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPossibleOwnPieces(ArrayList<Piece> possibleOwnPieces) {
 | 
			
		||||
        this.possibleOwnPieces = possibleOwnPieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPossibleEnemyPieces(ArrayList<Piece> possibleEnemyPieces) {
 | 
			
		||||
        this.possibleEnemyPieces = possibleEnemyPieces;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectPiece(Piece piece){
 | 
			
		||||
        if (possibleOwnPieces.contains(piece)){
 | 
			
		||||
            selectedOwnPiece = piece;
 | 
			
		||||
        } else if (possibleEnemyPieces.contains(piece)){
 | 
			
		||||
            selectedEnemyPiece = piece;
 | 
			
		||||
        }
 | 
			
		||||
        if (selectedOwnPiece != null && selectedEnemyPiece != null){
 | 
			
		||||
            logic.send(RequestPlayCard.requestPlaySwap(selectedOwnPiece.getIdentifier(), selectedEnemyPiece.getIdentifier()));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCard msg) {
 | 
			
		||||
        parent.getParent().setState(parent.getParent().getPlayPowerCard());
 | 
			
		||||
        parent.getParent().getPlayPowerCard().setPlayCard(msg);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -134,6 +134,16 @@ public int getNumberOfActivePlayers() {
 | 
			
		||||
        return activePlayers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method will be used to return a piece based on the identifier.
 | 
			
		||||
     *
 | 
			
		||||
     * @return the piece specified by the identifier
 | 
			
		||||
     */
 | 
			
		||||
    public Piece getPieceThroughIdentifier(String identifier){
 | 
			
		||||
        String[] parts = identifier.split("-");
 | 
			
		||||
        return board.getPlayerData().get(Color.valueOf(parts[0])).getPieces()[Integer.parseInt(parts[1])];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method notifies the observers.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package pp.mdga.game;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This class will be used to hold all Piece relevant data.
 | 
			
		||||
 */
 | 
			
		||||
@@ -8,6 +10,7 @@ public class Piece {
 | 
			
		||||
    private PieceState state;
 | 
			
		||||
    private final Color color;
 | 
			
		||||
    private final int id;
 | 
			
		||||
    private final UUID uuid = UUID.randomUUID();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This constructor is used to create a new Piece
 | 
			
		||||
@@ -93,4 +96,13 @@ public Color getColor() {
 | 
			
		||||
    public String getIdentifier() {
 | 
			
		||||
        return color.toString() + "-" + id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This method is used to get the color of the piece
 | 
			
		||||
     *
 | 
			
		||||
     * @return the color of the piece
 | 
			
		||||
     */
 | 
			
		||||
    public UUID getUuid() {
 | 
			
		||||
        return uuid;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -53,15 +53,6 @@ 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.
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user