merge the new developmentbranch into the test branch #39
@@ -1,8 +1,17 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.Resources;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.DiceAgainMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FirstRollState extends RollDiceAutomatonState {
|
||||
/**
|
||||
* Create FirstRollState constants.
|
||||
@@ -28,4 +37,37 @@ public void enter() {
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited FirstRollState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
List<Piece> moveablePieces = new ArrayList<>();
|
||||
for (Piece piece : this.rollDiceAutomaton.getTurnAutomaton().getPlayer().getPieces()) {
|
||||
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
|
||||
moveablePieces.add(piece);
|
||||
}
|
||||
}
|
||||
|
||||
int roll = this.logic.getGame().getDie().shuffle();
|
||||
this.logic.getGame().setDiceEyes(roll);
|
||||
|
||||
if (!moveablePieces.isEmpty()) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
if (roll == Resources.MAX_EYES) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceAgainMessage());
|
||||
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getSecondRollState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.DiceAgainMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
@@ -28,4 +31,23 @@ public void enter() {
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited SecondRollState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
if (roll == 6) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceAgainMessage());
|
||||
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getThirdRollState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||
|
||||
import pp.mdga.message.client.RequestDieMessage;
|
||||
import pp.mdga.message.server.ActivePlayerMessage;
|
||||
import pp.mdga.message.server.CeremonyMessage;
|
||||
import pp.mdga.message.server.DieMessage;
|
||||
import pp.mdga.message.server.NoTurnMessage;
|
||||
import pp.mdga.message.server.SpectatorMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||
|
||||
@@ -28,4 +34,34 @@ public void enter() {
|
||||
public void exit() {
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered ThirdRollState state.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
if (roll == 6) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||
} else {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new NoTurnMessage());
|
||||
|
||||
if (this.rollDiceAutomaton.getTurnAutomaton().getPlayer().isFinished()) {
|
||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new SpectatorMessage());
|
||||
|
||||
if (this.logic.getGame().getNumberOfActivePlayers() == 1) {
|
||||
this.logic.getServerSender().broadcast(new CeremonyMessage());
|
||||
} else {
|
||||
this.logic.getGame().setActiveColor(this.logic.getGame().getActiveColor().next());
|
||||
this.logic.getServerSender().broadcast(new ActivePlayerMessage(this.logic.getGame().getActiveColor()));
|
||||
this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getGameAutomaton().getAnimationState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user