Updated 'TurnState' class.

Updated the 'TurnState' class by adding the 'SelectedPiecesMessage', 'NoPowerCardMessage', 'RequestDieMessage' and 'ReuqestMoveMessage' handling to it.
This commit is contained in:
Daniel Grigencha
2024-12-06 08:56:21 +01:00
parent a18165bc02
commit 77b0207214

View File

@@ -1,6 +1,10 @@
package pp.mdga.server.automaton.game;
import pp.mdga.game.Player;
import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.server.ServerGameLogic;
import pp.mdga.server.automaton.GameState;
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
@@ -49,8 +53,9 @@ public TurnState(GameState gameAutomaton, ServerGameLogic logic) {
@Override
public void enter() {
LOGGER.log(Level.DEBUG, "Entered TurnState state.");
LOGGER.log(Level.INFO, "Entered TurnState state.");
this.player = this.logic.getGame().getPlayerById(this.logic.getGame().getActivePlayerId());
this.setCurrentState(this.powerCardState);
}
@Override
@@ -58,6 +63,54 @@ public void exit() {
LOGGER.log(Level.DEBUG, "Exited TurnState state.");
}
/**
* This method will be called whenever the server received an SelectedPiecesMessage 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 SelectedPiecesMessage object.
* @param from as the client id of the player as an Integer.
*/
@Override
public void received(SelectedPiecesMessage msg, int from) {
this.currentState.received(msg, from);
}
/**
* This method will be called whenever the server received an NoPowerCardMessage 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 NoPowerCardMessage object.
* @param from as the client id of the player as an Integer.
*/
@Override
public void received(NoPowerCardMessage msg, int from) {
this.currentState.received(msg, from);
}
/**
* 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 a RequestMoveMessage 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 RequestMoveMessage object.
* @param from as the client id of the player as an Integer.
*/
@Override
public void received(RequestMoveMessage msg, int from) {
this.currentState.received(msg, from);
}
/**
* This method will be used to return currentState attribute of TurnState class.
*