added logger to server state chart
This commit is contained in:
		@@ -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,32 @@
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * 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 +34,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 +45,7 @@ public GameState(ServerGameLogic logic) {
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void enter() {
 | 
			
		||||
 | 
			
		||||
        LOGGER.log(System.Logger.Level.DEBUG, "Entered GameState state.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -35,6 +57,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 +70,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 +83,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.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
     */
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user