after switching from spectator to animation you should now be reset correctly into spectator
This commit is contained in:
		@@ -11,6 +11,8 @@ public class AnimationState extends GameStates {
 | 
			
		||||
 | 
			
		||||
    private final GameState parent;
 | 
			
		||||
 | 
			
		||||
    private boolean spectator = false;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructs a client state of the specified game logic.
 | 
			
		||||
     *
 | 
			
		||||
@@ -34,7 +36,16 @@ public void enter() {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void exit() {
 | 
			
		||||
        spectator = false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the spectator.
 | 
			
		||||
     *
 | 
			
		||||
     * @param spectator the spectator
 | 
			
		||||
     */
 | 
			
		||||
    public void setSpectator(boolean spectator) {
 | 
			
		||||
        this.spectator = spectator;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -43,6 +54,10 @@ public void exit() {
 | 
			
		||||
    @Override
 | 
			
		||||
    public void selectAnimationEnd() {
 | 
			
		||||
        logic.send(new AnimationEndMessage());
 | 
			
		||||
        parent.setState(parent.getWaiting());
 | 
			
		||||
        if (spectator){
 | 
			
		||||
            parent.setState(parent.getSpectator());
 | 
			
		||||
        } else {
 | 
			
		||||
            parent.setState(parent.getWaiting());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@
 | 
			
		||||
import pp.mdga.client.ClientState;
 | 
			
		||||
import pp.mdga.client.GameState;
 | 
			
		||||
import pp.mdga.game.BonusCard;
 | 
			
		||||
import pp.mdga.game.Node;
 | 
			
		||||
import pp.mdga.game.Piece;
 | 
			
		||||
import pp.mdga.game.PieceState;
 | 
			
		||||
import pp.mdga.game.ShieldState;
 | 
			
		||||
@@ -31,6 +32,7 @@ public SpectatorState(ClientState parent, ClientGameLogic logic) {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
        parent.getAnimation().setSpectator(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -42,7 +44,9 @@ public void exit() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the Ceremony Message.
 | 
			
		||||
     * Handles the reception of a CeremonyMessage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the ceremony message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(CeremonyMessage msg) {
 | 
			
		||||
@@ -50,34 +54,30 @@ public void received(CeremonyMessage msg) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the Draw card message.
 | 
			
		||||
     * Handles the reception of a DieMessage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the draw card message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DrawCardMessage msg) {
 | 
			
		||||
        logic.getGame().getActivePlayer().addHandCard(msg.getCard());
 | 
			
		||||
        if (msg.getCard() instanceof HiddenCard) {
 | 
			
		||||
            logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //stats
 | 
			
		||||
        logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
 | 
			
		||||
        logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the Die Message.
 | 
			
		||||
     * @param msg the die message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(DieMessage msg) {
 | 
			
		||||
        logic.getGame().setDiceEyes(msg.getDiceEye());
 | 
			
		||||
        logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier()));
 | 
			
		||||
        parent.setState(parent.getAnimation());
 | 
			
		||||
        if (logic.getGame().getTurboFlag()) {
 | 
			
		||||
            logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
 | 
			
		||||
        } else {
 | 
			
		||||
            logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //stats
 | 
			
		||||
        if (msg.getDiceEye() == 6) {
 | 
			
		||||
            logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
 | 
			
		||||
            logic.getGame().getGameStatistics().increaseDiced6();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the PlayCardMessage Message.
 | 
			
		||||
     * Handles the reception of a PlayCardMessage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the play card message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(PlayCardMessage msg) {
 | 
			
		||||
@@ -89,28 +89,73 @@ public void received(PlayCardMessage msg) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the ActivePlayerMessage Message.
 | 
			
		||||
     * Handles the reception of an ActivePlayerMessage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the active player message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(ActivePlayerMessage msg) {
 | 
			
		||||
        logic.addNotification(new ActivePlayerNotification(msg.getColor()));
 | 
			
		||||
        logic.getGame().setActiveColor(msg.getColor());
 | 
			
		||||
        parent.setState(parent.getAnimation());
 | 
			
		||||
        if (msg.getColor() == logic.getGame().getPlayers().get(logic.getOwnPlayerId()).getColor()) {
 | 
			
		||||
            parent.setState(parent.getTurn());
 | 
			
		||||
        } else {
 | 
			
		||||
            for (Piece piece : logic.getGame().getActivePlayer().getPieces()) {
 | 
			
		||||
                if (piece.isShielded() || piece.isSuppressed()) {
 | 
			
		||||
                    logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
 | 
			
		||||
                    piece.setShield(ShieldState.NONE);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Receives the MoveMessage Message.
 | 
			
		||||
     * Handles the reception of a MoveMessage.
 | 
			
		||||
     *
 | 
			
		||||
     * @param msg the move message
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void received(MoveMessage msg) {
 | 
			
		||||
        Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
 | 
			
		||||
        if (msg.isHomeMove()) {
 | 
			
		||||
            logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
 | 
			
		||||
            logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
 | 
			
		||||
            if (piece.getState().equals(PieceState.HOME)) {
 | 
			
		||||
                logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
                int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
 | 
			
		||||
                Node pieceNode = logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex];
 | 
			
		||||
 | 
			
		||||
                //gets the oldNode
 | 
			
		||||
                int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
 | 
			
		||||
                Node oldNode = logic.getGame().getActivePlayer().getHomeNodes()[homeIndex];
 | 
			
		||||
                //gets the targetNode
 | 
			
		||||
                Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
 | 
			
		||||
                if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
 | 
			
		||||
                    piece.setState(PieceState.HOMEFINISHED);
 | 
			
		||||
                } else {
 | 
			
		||||
                    piece.setState(PieceState.HOME);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                oldNode.clearOccupant();
 | 
			
		||||
                targetNode.setOccupant(piece);
 | 
			
		||||
 | 
			
		||||
            } else {
 | 
			
		||||
                logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
 | 
			
		||||
                int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
                Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
 | 
			
		||||
 | 
			
		||||
                //gets the targetNode
 | 
			
		||||
                Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
 | 
			
		||||
 | 
			
		||||
                if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
 | 
			
		||||
                    piece.setState(PieceState.HOMEFINISHED);
 | 
			
		||||
                } else {
 | 
			
		||||
                    piece.setState(PieceState.HOME);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                oldNode.clearOccupant();
 | 
			
		||||
                targetNode.setOccupant(piece);
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
 | 
			
		||||
 | 
			
		||||
            Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
 | 
			
		||||
            if (occ != null) {
 | 
			
		||||
                //TODO: MoveThrowNotification
 | 
			
		||||
@@ -122,7 +167,7 @@ public void received(MoveMessage msg) {
 | 
			
		||||
                //set occ to waiting
 | 
			
		||||
                logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
 | 
			
		||||
            }
 | 
			
		||||
            if (msg.getPiece().getState().equals(PieceState.WAITING)) {
 | 
			
		||||
            if (oldIndex == -1) {
 | 
			
		||||
                logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
 | 
			
		||||
                logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
 | 
			
		||||
                piece.setState(PieceState.ACTIVE);
 | 
			
		||||
@@ -133,7 +178,17 @@ public void received(MoveMessage msg) {
 | 
			
		||||
            }
 | 
			
		||||
            //set new node
 | 
			
		||||
            logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
 | 
			
		||||
            if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isStart()) {
 | 
			
		||||
                if (piece.isShielded()) {
 | 
			
		||||
                    piece.setShield(ShieldState.SUPPRESSED);
 | 
			
		||||
                    logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (piece.isSuppressed()) {
 | 
			
		||||
                piece.setShield(ShieldState.ACTIVE);
 | 
			
		||||
                logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        System.out.println("send AnimationEndMessage");
 | 
			
		||||
        logic.getGame().setTurboFlag(false);
 | 
			
		||||
        parent.setState(parent.getAnimation());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user