implemented rest of the server logic in choosepiece substates, and began to fix bugs after testing
This commit is contained in:
@@ -52,7 +52,6 @@ public GameView(MdgaApp app) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnter() {
|
public void onEnter() {
|
||||||
setOwnColor(Color.AIRFORCE);
|
|
||||||
camera.init(ownColor);
|
camera.init(ownColor);
|
||||||
boardHandler.init();
|
boardHandler.init();
|
||||||
guiHandler.init(ownColor);
|
guiHandler.init(ownColor);
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public void received(ServerStartGameMessage msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logic.getGame().setBoard(msg.getBoard());
|
logic.getGame().setBoard(msg.getBoard());
|
||||||
|
System.out.println(logic.getGame().getPlayerById(logic.getOwnPlayerId()).toString());
|
||||||
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
|
logic.addNotification(new GameNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor()));
|
||||||
for (var player : logic.getGame().getPlayers().values()) {
|
for (var player : logic.getGame().getPlayers().values()) {
|
||||||
List<UUID> pieces = new ArrayList<>();
|
List<UUID> pieces = new ArrayList<>();
|
||||||
@@ -94,6 +95,7 @@ public void received(ServerStartGameMessage msg) {
|
|||||||
@Override
|
@Override
|
||||||
public void received(LobbyPlayerJoinedMessage msg) {
|
public void received(LobbyPlayerJoinedMessage msg) {
|
||||||
if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
|
if (msg.getPlayer().getName().equals(logic.getOwnPlayerName())) {
|
||||||
|
System.out.println(msg.getId());
|
||||||
logic.setOwnPlayerId(msg.getId());
|
logic.setOwnPlayerId(msg.getId());
|
||||||
}
|
}
|
||||||
if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()) {
|
if (msg.isHost() && msg.getId() == logic.getOwnPlayerId()) {
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ public void setState(DetermineStartPlayerStates state) {
|
|||||||
if(this.state != null){
|
if(this.state != null){
|
||||||
this.state.exit();
|
this.state.exit();
|
||||||
}
|
}
|
||||||
state.enter();
|
|
||||||
this.state = state;
|
this.state = state;
|
||||||
|
this.state.enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public void received(ActivePlayerMessage msg) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(MoveMessage msg) {
|
public void received(MoveMessage msg) {
|
||||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
|
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||||
if (msg.isHomeMove()) {
|
if (msg.isHomeMove()) {
|
||||||
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
|
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
|
||||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
|
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public void received(ActivePlayerMessage msg) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(MoveMessage msg) {
|
public void received(MoveMessage msg) {
|
||||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
|
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||||
if (msg.isHomeMove()) {
|
if (msg.isHomeMove()) {
|
||||||
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
|
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
|
||||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
|
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public DetermineStartPlayerState getParent(){
|
|||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
|
for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
|
||||||
//logic.addNotification(new WaitMoveNotification(entry.getValue().getPieces()[0].getUuid()));
|
|
||||||
logic.addNotification(new MovePieceNotification(entry.getValue().getPieces()[0].getUuid(), entry.getValue().getStartNodeIndex(), true));
|
logic.addNotification(new MovePieceNotification(entry.getValue().getPieces()[0].getUuid(), entry.getValue().getStartNodeIndex(), true));
|
||||||
logic.getGame().getBoard().getInfield()[entry.getValue().getStartNodeIndex()].setOccupant(entry.getValue().getPieces()[0]);
|
logic.getGame().getBoard().getInfield()[entry.getValue().getStartNodeIndex()].setOccupant(entry.getValue().getPieces()[0]);
|
||||||
animationCounter++;
|
animationCounter++;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
public class RollRankingDiceState extends DetermineStartPlayerStates {
|
public class RollRankingDiceState extends DetermineStartPlayerStates {
|
||||||
|
|
||||||
|
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||||
|
|
||||||
private final DetermineStartPlayerState parent;
|
private final DetermineStartPlayerState parent;
|
||||||
|
|
||||||
public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
|
public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
|
||||||
@@ -19,11 +21,13 @@ public RollRankingDiceState(ClientState parent, ClientGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Entering RollRankingDiceState");
|
||||||
logic.addNotification(new DiceNowNotification());
|
logic.addNotification(new DiceNowNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Exiting RollRankingDiceState");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
public class WaitRankingState extends DetermineStartPlayerStates {
|
public class WaitRankingState extends DetermineStartPlayerStates {
|
||||||
|
|
||||||
|
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||||
|
|
||||||
private final DetermineStartPlayerState parent;
|
private final DetermineStartPlayerState parent;
|
||||||
private boolean canChange = false;
|
private boolean canChange = false;
|
||||||
|
|
||||||
@@ -27,11 +29,12 @@ private void changeToIntro(){
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Entering WaitRankingState");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Exiting WaitRankingState");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ public void received(DieMessage msg){
|
|||||||
@Override
|
@Override
|
||||||
public void selectAnimationEnd(){
|
public void selectAnimationEnd(){
|
||||||
logic.send(new AnimationEndMessage());
|
logic.send(new AnimationEndMessage());
|
||||||
|
parent.setState(parent.getChoosePiece());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
public class NoPieceState extends ChoosePieceStates {
|
public class NoPieceState extends ChoosePieceStates {
|
||||||
|
|
||||||
|
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||||
|
|
||||||
private final ChoosePieceState parent;
|
private final ChoosePieceState parent;
|
||||||
|
|
||||||
public NoPieceState(ClientState parent, ClientGameLogic logic) {
|
public NoPieceState(ClientState parent, ClientGameLogic logic) {
|
||||||
@@ -25,7 +27,7 @@ public NoPieceState(ClientState parent, ClientGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Entering NoPieceState");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -35,14 +37,16 @@ public void exit() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(SelectPieceMessage msg) {
|
public void received(SelectPieceMessage msg) {
|
||||||
parent.setState(parent.getSelectPiece());
|
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece.getUuid())).collect(Collectors.toCollection(ArrayList::new));
|
||||||
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughUUID(piece)).collect(Collectors.toCollection(ArrayList::new));
|
|
||||||
parent.getSelectPiece().setPossiblePieces(pieces);
|
parent.getSelectPiece().setPossiblePieces(pieces);
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Received " + msg.getPieces().size() + " pieces");
|
||||||
logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove()));
|
logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove()));
|
||||||
|
parent.setState(parent.getSelectPiece());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(WaitPieceMessage msg){
|
public void received(WaitPieceMessage msg){
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Received WaitPieceMessage");
|
||||||
logic.addNotification(new WaitMoveNotification(msg.getPieceID()));
|
logic.addNotification(new WaitMoveNotification(msg.getPieceID()));
|
||||||
parent.setState(parent.getWaitingPiece());
|
parent.setState(parent.getWaitingPiece());
|
||||||
}
|
}
|
||||||
@@ -56,6 +60,8 @@ public void received(StartPieceMessage msg){
|
|||||||
listPiece.add(piece.getUuid());
|
listPiece.add(piece.getUuid());
|
||||||
listIndex.add(msg.getTargetIndex());
|
listIndex.add(msg.getTargetIndex());
|
||||||
homeMove.add(false);
|
homeMove.add(false);
|
||||||
|
parent.getStartPiece().setMoveablePiece(piece);
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Received start piece " + listPiece.get(0));
|
||||||
logic.addNotification(new SelectableMoveNotification(listPiece, listIndex, homeMove));
|
logic.addNotification(new SelectableMoveNotification(listPiece, listIndex, homeMove));
|
||||||
parent.setState(parent.getStartPiece());
|
parent.setState(parent.getStartPiece());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public void selectPiece(Piece piece) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(MoveMessage msg) {
|
public void received(MoveMessage msg) {
|
||||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
|
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||||
if (msg.isHomeMove()) {
|
if (msg.isHomeMove()) {
|
||||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
public class StartPieceState extends ChoosePieceStates {
|
public class StartPieceState extends ChoosePieceStates {
|
||||||
|
|
||||||
|
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||||
|
|
||||||
private final ChoosePieceState parent;
|
private final ChoosePieceState parent;
|
||||||
private Piece moveablePiece;
|
private Piece moveablePiece;
|
||||||
|
|
||||||
@@ -27,7 +29,11 @@ public void enter() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
moveablePiece = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoveablePiece(Piece moveablePiece) {
|
||||||
|
this.moveablePiece = moveablePiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public void selectPiece(Piece piece){
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void received(MoveMessage msg){
|
public void received(MoveMessage msg){
|
||||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getIdentifier());
|
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||||
pieceToMove.setState(PieceState.ACTIVE);
|
pieceToMove.setState(PieceState.ACTIVE);
|
||||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class Game {
|
|||||||
/**
|
/**
|
||||||
* The dice modifier.
|
* The dice modifier.
|
||||||
*/
|
*/
|
||||||
private int diceModifier;
|
private int diceModifier = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of eyes on the dice.
|
* The number of eyes on the dice.
|
||||||
|
|||||||
@@ -49,6 +49,25 @@ public void setOccupant(Piece occupant) {
|
|||||||
this.occupant = occupant;
|
this.occupant = occupant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method handles the event when a new occupant is moved to the node,
|
||||||
|
* it then returns the old occupant.
|
||||||
|
*
|
||||||
|
* @param newOccupant the new occupant of the node
|
||||||
|
* @return the old occupant of the node
|
||||||
|
*/
|
||||||
|
public Piece moveOccupant(Piece newOccupant) {
|
||||||
|
if (occupant == null) {
|
||||||
|
setOccupant(newOccupant);
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
occupant.setShield(ShieldState.NONE);
|
||||||
|
occupant.setState(PieceState.WAITING);
|
||||||
|
setOccupant(newOccupant);
|
||||||
|
return occupant;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to clear the node of its occupant
|
* This method is used to clear the node of its occupant
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -152,6 +152,57 @@ public PowerCard getPowerCardByType(BonusCard bonusCard) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Piece getWaitingPiece(){
|
||||||
|
for (Piece piece : this.waitingArea) {
|
||||||
|
if (piece != null){
|
||||||
|
return piece;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns a boolean based on if the Player has a piece in its waiting area
|
||||||
|
*
|
||||||
|
* @return the boolean if the waiting area contains a piece
|
||||||
|
*/
|
||||||
|
public boolean hasPieceInWaitingArea(){
|
||||||
|
for (Piece piece : this.waitingArea) {
|
||||||
|
if (piece != null){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHomeIndexOfPiece(Piece piece) {
|
||||||
|
for (int i = 0; i < Resources.MAX_PIECES; i++) {
|
||||||
|
if (this.homeNodes[i].getOccupant().equals(piece)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean pieceInsideOfHome(Piece piece) {
|
||||||
|
for (Node node : this.homeNodes) {
|
||||||
|
if (node.getOccupant().equals(piece)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHomeFinished(Piece piece) {
|
||||||
|
for (int i = getHomeIndexOfPiece(piece); i < Resources.MAX_PIECES; i++) {
|
||||||
|
if (!this.homeNodes[i].isOccupied()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the give name of the Player
|
* This method returns the give name of the Player
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pp.mdga.message.client;
|
package pp.mdga.message.client;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -12,22 +13,22 @@ public class RequestMoveMessage extends ClientMessage {
|
|||||||
/**
|
/**
|
||||||
* The identifier for the piece.
|
* The identifier for the piece.
|
||||||
*/
|
*/
|
||||||
private final UUID pieceIdentifier;
|
private final Piece piece;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for RequestMove
|
* Constructor for RequestMove
|
||||||
*
|
*
|
||||||
* @param pieceIdentifier the piece identifier
|
* @param piece the piece
|
||||||
*/
|
*/
|
||||||
public RequestMoveMessage(UUID pieceIdentifier) {
|
public RequestMoveMessage(Piece piece) {
|
||||||
this.pieceIdentifier = pieceIdentifier;
|
this.piece = piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor for serialization purposes.
|
* Default constructor for serialization purposes.
|
||||||
*/
|
*/
|
||||||
private RequestMoveMessage() {
|
private RequestMoveMessage() {
|
||||||
pieceIdentifier = null;
|
piece = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -35,8 +36,8 @@ private RequestMoveMessage() {
|
|||||||
*
|
*
|
||||||
* @return the piece identifier
|
* @return the piece identifier
|
||||||
*/
|
*/
|
||||||
public UUID getPieceIdentifier() {
|
public Piece getPiece() {
|
||||||
return pieceIdentifier;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +47,8 @@ public UUID getPieceIdentifier() {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RequestMove{pieceIdentifier = " + pieceIdentifier + '}';
|
assert piece != null;
|
||||||
|
return "RequestMove{pieceIdentifier = " + piece.toString() + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package pp.mdga.message.server;
|
package pp.mdga.message.server;
|
||||||
|
|
||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ public class MoveMessage extends ServerMessage {
|
|||||||
/**
|
/**
|
||||||
* The identifier of the piece that should be moved.
|
* The identifier of the piece that should be moved.
|
||||||
*/
|
*/
|
||||||
private final UUID pieceUUID;
|
private final Piece piece;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The index of the target node;
|
* The index of the target node;
|
||||||
@@ -27,11 +28,13 @@ public class MoveMessage extends ServerMessage {
|
|||||||
/**
|
/**
|
||||||
* Constructs a new MoveMessage instance.
|
* Constructs a new MoveMessage instance.
|
||||||
*
|
*
|
||||||
* @param identifier the identifier of the piece that should be moved
|
* @param piece the identifier of the piece that should be moved
|
||||||
|
* @param isHomeMove boolean flag declaring home move or not
|
||||||
|
* @param targetIndex the targetIndex
|
||||||
*/
|
*/
|
||||||
public MoveMessage(UUID identifier, boolean isHomeMove, int targetIndex) {
|
public MoveMessage(Piece piece, boolean isHomeMove, int targetIndex) {
|
||||||
super();
|
super();
|
||||||
this.pieceUUID = identifier;
|
this.piece = piece;
|
||||||
this.isHomeMove = isHomeMove;
|
this.isHomeMove = isHomeMove;
|
||||||
this.targetIndex = targetIndex;
|
this.targetIndex = targetIndex;
|
||||||
}
|
}
|
||||||
@@ -41,7 +44,7 @@ public MoveMessage(UUID identifier, boolean isHomeMove, int targetIndex) {
|
|||||||
*/
|
*/
|
||||||
private MoveMessage() {
|
private MoveMessage() {
|
||||||
super();
|
super();
|
||||||
pieceUUID = null;
|
piece = null;
|
||||||
targetIndex = 0;
|
targetIndex = 0;
|
||||||
isHomeMove = false;
|
isHomeMove = false;
|
||||||
}
|
}
|
||||||
@@ -51,8 +54,8 @@ private MoveMessage() {
|
|||||||
*
|
*
|
||||||
* @return the identifier of the piece that should be moved
|
* @return the identifier of the piece that should be moved
|
||||||
*/
|
*/
|
||||||
public UUID getIdentifier() {
|
public Piece getPiece() {
|
||||||
return pieceUUID;
|
return piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,6 +93,6 @@ public void accept(ServerInterpreter interpreter) {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "MoveMessage{" + "pieceUUID=" + pieceUUID + ", targetIndex=" + targetIndex + ", isHomeMove=" + isHomeMove + '}';
|
return "MoveMessage{" + "pieceUUID=" + piece.getUuid() + ", targetIndex=" + targetIndex + ", isHomeMove=" + isHomeMove + '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import com.jme3.network.serializing.Serializable;
|
import com.jme3.network.serializing.Serializable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import pp.mdga.game.Piece;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message sent by the server to the active player to select a piece to move.
|
* A message sent by the server to the active player to select a piece to move.
|
||||||
@@ -13,7 +13,7 @@ public class SelectPieceMessage extends ServerMessage {
|
|||||||
/**
|
/**
|
||||||
* The list of pieces
|
* The list of pieces
|
||||||
*/
|
*/
|
||||||
private final List<UUID> pieces;
|
private final List<Piece> pieces;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The list of booleans of isHomeMove of the pieces
|
* The list of booleans of isHomeMove of the pieces
|
||||||
@@ -32,7 +32,7 @@ public class SelectPieceMessage extends ServerMessage {
|
|||||||
* @param isHomeMove the List of booleans of isHomeMove of the pieces
|
* @param isHomeMove the List of booleans of isHomeMove of the pieces
|
||||||
* @param targetIndex the List of indexes of target nodes of the pieces
|
* @param targetIndex the List of indexes of target nodes of the pieces
|
||||||
*/
|
*/
|
||||||
public SelectPieceMessage(List<UUID> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex) {
|
public SelectPieceMessage(List<Piece> pieces, List<Boolean> isHomeMove, List<Integer> targetIndex) {
|
||||||
super();
|
super();
|
||||||
this.pieces = pieces;
|
this.pieces = pieces;
|
||||||
this.isHomeMove = isHomeMove;
|
this.isHomeMove = isHomeMove;
|
||||||
@@ -54,7 +54,7 @@ public SelectPieceMessage() {
|
|||||||
*
|
*
|
||||||
* @return the pieces
|
* @return the pieces
|
||||||
*/
|
*/
|
||||||
public List<UUID> getPieces() {
|
public List<Piece> getPieces() {
|
||||||
return pieces;
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package pp.mdga.server.automaton;
|
package pp.mdga.server.automaton;
|
||||||
|
|
||||||
import pp.mdga.message.client.AnimationEndMessage;
|
import pp.mdga.message.client.*;
|
||||||
import pp.mdga.message.client.DisconnectedMessage;
|
|
||||||
import pp.mdga.message.client.LeaveGameMessage;
|
|
||||||
import pp.mdga.message.client.RequestDieMessage;
|
|
||||||
import pp.mdga.message.server.CeremonyMessage;
|
import pp.mdga.message.server.CeremonyMessage;
|
||||||
import pp.mdga.message.server.PauseGameMessage;
|
import pp.mdga.message.server.PauseGameMessage;
|
||||||
import pp.mdga.server.automaton.game.AnimationState;
|
import pp.mdga.server.automaton.game.AnimationState;
|
||||||
@@ -88,6 +85,11 @@ public void received(LeaveGameMessage msg, int from) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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.
|
* 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.
|
* It will also get the client id of the player who send this message.
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ public void received(AnimationEndMessage msg, int from) {
|
|||||||
this.messageReceived.add(from);
|
this.messageReceived.add(from);
|
||||||
if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
|
if (this.messageReceived.size() == this.logic.getGame().getPlayers().size()) {
|
||||||
this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
|
this.gameAutomaton.setCurrentState(this.gameAutomaton.getTurnState());
|
||||||
this.gameAutomaton.getTurnState().setCurrentState(this.gameAutomaton.getTurnState().getPowerCardState());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,9 +79,6 @@ else if (maximumRoll < entry.getValue()) {
|
|||||||
this.playersHaveToRoll.clear();
|
this.playersHaveToRoll.clear();
|
||||||
this.playersHaveToRoll.add(entry.getKey());
|
this.playersHaveToRoll.add(entry.getKey());
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
this.logic.getServerSender().send(entry.getKey(), new EndOfTurnMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int id: this.playersHaveToRoll) {
|
for (int id: this.playersHaveToRoll) {
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
package pp.mdga.server.automaton.game;
|
package pp.mdga.server.automaton.game;
|
||||||
|
|
||||||
import pp.mdga.game.Player;
|
import pp.mdga.game.Player;
|
||||||
import pp.mdga.message.client.NoPowerCardMessage;
|
import pp.mdga.message.client.*;
|
||||||
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.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.GameState;
|
import pp.mdga.server.automaton.GameState;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
@@ -111,6 +108,11 @@ public void received(RequestMoveMessage msg, int from) {
|
|||||||
this.currentState.received(msg, from);
|
this.currentState.received(msg, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(AnimationEndMessage msg, int from) {
|
||||||
|
this.currentState.received(msg, from);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used to return currentState attribute of TurnState class.
|
* This method will be used to return currentState attribute of TurnState class.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,17 +34,17 @@ public ChoosePieceState(TurnState turnAutomaton, ServerGameLogic logic) {
|
|||||||
this.waitingPieceState = new WaitingPieceState(this, logic);
|
this.waitingPieceState = new WaitingPieceState(this, logic);
|
||||||
this.startPieceState = new StartPieceState(this, logic);
|
this.startPieceState = new StartPieceState(this, logic);
|
||||||
this.selectPieceState = new SelectPieceState(this, logic);
|
this.selectPieceState = new SelectPieceState(this, logic);
|
||||||
this.setCurrentState(this.noPieceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited ChoosePieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered ChoosePieceState state.");
|
||||||
|
this.setCurrentState(this.noPieceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered ChoosePieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited ChoosePieceState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,13 +1,24 @@
|
|||||||
package pp.mdga.server.automaton.game.turn;
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
import pp.mdga.game.Player;
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
|
import pp.mdga.message.server.ActivePlayerMessage;
|
||||||
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
|
import pp.mdga.message.server.EndOfTurnMessage;
|
||||||
|
import pp.mdga.message.server.SpectatorMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.TurnState;
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovePieceState extends TurnAutomatonState {
|
public class MovePieceState extends TurnAutomatonState {
|
||||||
/**
|
/**
|
||||||
* Create LobbyState constants.
|
* Create LobbyState constants.
|
||||||
*/
|
*/
|
||||||
private static final System.Logger LOGGER = System.getLogger(MovePieceState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(MovePieceState.class.getName());
|
||||||
|
private Set<Player> finishedAnimations = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
@@ -24,8 +35,34 @@ public void enter() {
|
|||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered MovePieceState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setActivePlayer(Color color) {
|
||||||
|
if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
|
||||||
|
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
|
||||||
|
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
|
||||||
|
} else {
|
||||||
|
setActivePlayer(color.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(AnimationEndMessage msg, int from){
|
||||||
|
finishedAnimations.add(logic.getGame().getPlayerById(from));
|
||||||
|
if (finishedAnimations.size() == logic.getGame().getPlayers().size()) {
|
||||||
|
if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()){
|
||||||
|
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
|
||||||
|
setActivePlayer(logic.getGame().getActiveColor());
|
||||||
|
} else if (logic.getGame().getDiceEyes() == 6){
|
||||||
|
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage());
|
||||||
|
} else {
|
||||||
|
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new EndOfTurnMessage());
|
||||||
|
setActivePlayer(logic.getGame().getActiveColor());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
|
finishedAnimations.clear();
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited MovePieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited MovePieceState state.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import pp.mdga.game.Piece;
|
import pp.mdga.game.Piece;
|
||||||
import pp.mdga.game.card.PowerCard;
|
import pp.mdga.game.card.PowerCard;
|
||||||
|
import pp.mdga.message.client.NoPowerCardMessage;
|
||||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||||
import pp.mdga.message.server.DiceNowMessage;
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
import pp.mdga.message.server.PossibleCardsMessage;
|
import pp.mdga.message.server.PossibleCardsMessage;
|
||||||
@@ -51,12 +52,12 @@ public PowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
|
|||||||
this.shieldCardState = new ShieldCardState(this, logic);
|
this.shieldCardState = new ShieldCardState(this, logic);
|
||||||
this.swapCardState = new SwapCardState(this, logic);
|
this.swapCardState = new SwapCardState(this, logic);
|
||||||
this.turboCardState = new TurboCardState(this, logic);
|
this.turboCardState = new TurboCardState(this, logic);
|
||||||
this.setCurrentState(this.choosePowerCardState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited PowerCardState state.");
|
LOGGER.log(System.Logger.Level.INFO, "Enter PowerCardState state.");
|
||||||
|
this.setCurrentState(this.choosePowerCardState);
|
||||||
this.visitor = new ServerCardVisitor(this.logic);
|
this.visitor = new ServerCardVisitor(this.logic);
|
||||||
for (PowerCard card : this.turnAutomaton.getPlayer().getHandCards()) {
|
for (PowerCard card : this.turnAutomaton.getPlayer().getHandCards()) {
|
||||||
card.accept(this.visitor);
|
card.accept(this.visitor);
|
||||||
@@ -73,7 +74,12 @@ public void enter() {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered PowerCardState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exit PowerCardState state.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(NoPowerCardMessage msg, int form){
|
||||||
|
currentState.received(msg, form);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package pp.mdga.server.automaton.game.turn;
|
package pp.mdga.server.automaton.game.turn;
|
||||||
|
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.message.client.RequestDieMessage;
|
import pp.mdga.message.client.RequestDieMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.TurnState;
|
import pp.mdga.server.automaton.game.TurnState;
|
||||||
@@ -33,12 +34,12 @@ public RollDiceState(TurnState turnAutomaton, ServerGameLogic logic) {
|
|||||||
this.firstRollState = new FirstRollState(this, logic);
|
this.firstRollState = new FirstRollState(this, logic);
|
||||||
this.secondRollState = new SecondRollState(this, logic);
|
this.secondRollState = new SecondRollState(this, logic);
|
||||||
this.thirdRollState = new ThirdRollState(this, logic);
|
this.thirdRollState = new ThirdRollState(this, logic);
|
||||||
this.setCurrentState(this.firstRollState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered RollDiceState state.");
|
||||||
|
this.setCurrentState(this.firstRollState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,6 +59,11 @@ public void received(RequestDieMessage msg, int from) {
|
|||||||
this.currentState.received(msg, from);
|
this.currentState.received(msg, from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(AnimationEndMessage msg, int from){
|
||||||
|
this.currentState.received(msg, from);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used to return currentState attribute of RollDiceState class.
|
* This method will be used to return currentState attribute of RollDiceState class.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.game.*;
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.ServerState;
|
import pp.mdga.server.automaton.ServerState;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
@@ -20,4 +22,76 @@ public ChoosePieceAutomatonState(ChoosePieceState choosePieceAutomaton, ServerGa
|
|||||||
super(logic);
|
super(logic);
|
||||||
this.choosePieceAutomaton = choosePieceAutomaton;
|
this.choosePieceAutomaton = choosePieceAutomaton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean canMove(Piece piece){
|
||||||
|
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||||
|
if (piece.getState().equals(PieceState.HOME)){
|
||||||
|
return canHomeMove(piece, steps);
|
||||||
|
} else {
|
||||||
|
int homeMoves = getHomeMoves(piece, steps);
|
||||||
|
if (homeMoves > 0){
|
||||||
|
return canHomeMove(piece, homeMoves);
|
||||||
|
} else {
|
||||||
|
return canInfieldMove(piece, steps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getHomeMoves(Piece piece, int steps){
|
||||||
|
int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||||
|
Color color = piece.getColor();
|
||||||
|
int startIndex = logic.getGame().getPlayerByColor(color).getStartNodeIndex();
|
||||||
|
int moveIndex = pieceIndex + steps;
|
||||||
|
if (moveIndex > logic.getGame().getBoard().getInfield().length){
|
||||||
|
if (startIndex > pieceIndex){
|
||||||
|
return steps - (startIndex - pieceIndex -1);
|
||||||
|
}
|
||||||
|
moveIndex %= logic.getGame().getBoard().getInfield().length;
|
||||||
|
if (moveIndex >= startIndex){
|
||||||
|
return moveIndex - startIndex + 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (pieceIndex < startIndex && startIndex <= moveIndex){
|
||||||
|
return moveIndex - startIndex + 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canInfieldMove(Piece piece, int steps){
|
||||||
|
int pieceIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||||
|
int moveIndex = (pieceIndex + steps) % logic.getGame().getBoard().getInfield().length;
|
||||||
|
Piece occupant = logic.getGame().getBoard().getInfield()[moveIndex].getOccupant();
|
||||||
|
if (occupant != null){
|
||||||
|
return occupant.getColor() != piece.getColor();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canHomeMove(Piece piece, int moveIndex){
|
||||||
|
Color color = piece.getColor();
|
||||||
|
Player player = logic.getGame().getPlayerByColor(color);
|
||||||
|
Node[] homeNodes = player.getHomeNodes();
|
||||||
|
int index;
|
||||||
|
if (player.pieceInsideOfHome(piece)){
|
||||||
|
index = player.getHomeIndexOfPiece(piece);
|
||||||
|
} else {
|
||||||
|
index = 0;
|
||||||
|
}
|
||||||
|
if (index + moveIndex >= homeNodes.length){
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
for (int i = index; i <= index + moveIndex; i++){
|
||||||
|
if(homeNodes[i].isOccupied()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int calculateTargetIndex(Piece piece){
|
||||||
|
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||||
|
return (logic.getGame().getBoard().getInfieldIndexOfPiece(piece) + steps) % logic.getGame().getBoard().getInfield().length;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.Resources;
|
||||||
|
import pp.mdga.game.*;
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class NoPieceState extends ChoosePieceAutomatonState {
|
public class NoPieceState extends ChoosePieceAutomatonState {
|
||||||
/**
|
/**
|
||||||
* Create FirstRollState constants.
|
* Create FirstRollState constants.
|
||||||
@@ -19,12 +24,57 @@ public NoPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic
|
|||||||
super(choosePieceAutomaton, logic);
|
super(choosePieceAutomaton, logic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initialize(){
|
||||||
|
Player activePlayer = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor());
|
||||||
|
if(logic.getGame().getDiceModifier() == 0){
|
||||||
|
if (logic.getGame().getDiceEyes() == 6) {
|
||||||
|
if (activePlayer.hasPieceInWaitingArea()){
|
||||||
|
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
|
||||||
|
}
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||||
|
}
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||||
|
}
|
||||||
|
} else if (activePlayer.hasPieceInWaitingArea()) {
|
||||||
|
if (!logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].isOccupied(activePlayer.getColor())){
|
||||||
|
if (logic.getGame().getDiceEyes() == 6) {
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getWaitingPieceState());
|
||||||
|
} else {
|
||||||
|
checkSelectPiece(activePlayer);
|
||||||
|
}
|
||||||
|
} else if (canMove(logic.getGame().getBoard().getInfield()[activePlayer.getStartNodeIndex()].getOccupant())){
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getStartPieceState());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
checkSelectPiece(activePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkSelectPiece(Player activePlayer){
|
||||||
|
ArrayList<Piece> moveablePieces = new ArrayList<>();
|
||||||
|
for (Piece piece : activePlayer.getPieces()){
|
||||||
|
if (piece.getState().equals(PieceState.ACTIVE) || piece.getState().equals(PieceState.HOME)){
|
||||||
|
moveablePieces.add(piece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
moveablePieces.removeIf(piece -> !canMove(piece));
|
||||||
|
if (moveablePieces.isEmpty()) {
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getNoTurnState());
|
||||||
|
} else {
|
||||||
|
this.choosePieceAutomaton.getSelectPieceState().setMoveablePieces(moveablePieces);
|
||||||
|
this.choosePieceAutomaton.setCurrentState(this.choosePieceAutomaton.getSelectPieceState());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used whenever this state will be entered.
|
* This method will be used whenever this state will be entered.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered NoPieceState state.");
|
LOGGER.log(System.Logger.Level.INFO, "Entered NoPieceState state.");
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.game.Color;
|
||||||
|
import pp.mdga.message.server.ActivePlayerMessage;
|
||||||
|
import pp.mdga.message.server.EndOfTurnMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
@@ -19,12 +22,23 @@ public NoTurnState(ChoosePieceState choosePieceAutomaton, ServerGameLogic logic)
|
|||||||
super(choosePieceAutomaton, logic);
|
super(choosePieceAutomaton, logic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setActivePlayer(Color color) {
|
||||||
|
if (!logic.getGame().getPlayerByColor(color.next()).isFinished()) {
|
||||||
|
logic.getGame().setActiveColor(logic.getGame().getActiveColor().next());
|
||||||
|
logic.getServerSender().broadcast(new ActivePlayerMessage(color.next()));
|
||||||
|
} else {
|
||||||
|
setActivePlayer(color.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used whenever this state will be entered.
|
* This method will be used whenever this state will be entered.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered NoTurnState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered NoTurnState state.");
|
||||||
|
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new EndOfTurnMessage());
|
||||||
|
setActivePlayer(logic.getGame().getActiveColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
import pp.mdga.game.PieceState;
|
||||||
|
import pp.mdga.game.ShieldState;
|
||||||
|
import pp.mdga.message.client.RequestMoveMessage;
|
||||||
|
import pp.mdga.message.server.MoveMessage;
|
||||||
|
import pp.mdga.message.server.SelectPieceMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SelectPieceState extends ChoosePieceAutomatonState {
|
public class SelectPieceState extends ChoosePieceAutomatonState {
|
||||||
/**
|
/**
|
||||||
* Create FirstRollState constants.
|
* Create FirstRollState constants.
|
||||||
*/
|
*/
|
||||||
private static final System.Logger LOGGER = System.getLogger(SelectPieceState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(SelectPieceState.class.getName());
|
||||||
|
|
||||||
|
private ArrayList<Piece> moveablePieces = new ArrayList<>();
|
||||||
|
private final ArrayList<Boolean> isHomeMove = new ArrayList<>();
|
||||||
|
private final ArrayList<Integer> targetIndex = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
*
|
*
|
||||||
@@ -19,12 +31,51 @@ public SelectPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic l
|
|||||||
super(choosePieceAutomaton, logic);
|
super(choosePieceAutomaton, logic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMoveablePieces(ArrayList<Piece> moveablePieces) {
|
||||||
|
this.moveablePieces = moveablePieces;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used whenever this state will be entered.
|
* This method will be used whenever this state will be entered.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered SelectPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered SelectPieceState state.");
|
||||||
|
int steps = logic.getGame().getDiceModifier() * logic.getGame().getDiceEyes();
|
||||||
|
for (Piece piece : moveablePieces) {
|
||||||
|
int homeMoves = getHomeMoves(piece, steps);
|
||||||
|
if (homeMoves > 0) {
|
||||||
|
isHomeMove.add(true);
|
||||||
|
targetIndex.add(homeMoves);
|
||||||
|
} else {
|
||||||
|
isHomeMove.add(false);
|
||||||
|
targetIndex.add(calculateTargetIndex(piece));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new SelectPieceMessage(moveablePieces, isHomeMove, targetIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(RequestMoveMessage msg, int from){
|
||||||
|
if (moveablePieces.contains(msg.getPiece())) {
|
||||||
|
int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
|
||||||
|
if (isHomeMove.get(indexOfPiece)) {
|
||||||
|
logic.getGame().getPlayerByColor(msg.getPiece().getColor()).setPieceInHome(targetIndex.get(indexOfPiece), logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()));
|
||||||
|
if (logic.getGame().getPlayerByColor(msg.getPiece().getColor()).isHomeFinished(logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()))) {
|
||||||
|
logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setState(PieceState.HOMEFINISHED);
|
||||||
|
} else {
|
||||||
|
logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setState(PieceState.HOME);
|
||||||
|
}
|
||||||
|
logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()).setShield(ShieldState.NONE);
|
||||||
|
} else {
|
||||||
|
Piece occ = logic.getGame().getBoard().getInfield()[targetIndex.get(indexOfPiece)].moveOccupant(moveablePieces.get(indexOfPiece));
|
||||||
|
if (occ != null) {
|
||||||
|
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
logic.getServerSender().broadcast(new MoveMessage(moveablePieces.get(indexOfPiece), isHomeMove.get(indexOfPiece), targetIndex.get(indexOfPiece)));
|
||||||
|
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,5 +84,8 @@ public void enter() {
|
|||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited SelectPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited SelectPieceState state.");
|
||||||
|
moveablePieces.clear();
|
||||||
|
isHomeMove.clear();
|
||||||
|
targetIndex.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
import pp.mdga.message.client.RequestMoveMessage;
|
||||||
|
import pp.mdga.message.server.MoveMessage;
|
||||||
|
import pp.mdga.message.server.StartPieceMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
|
|
||||||
@@ -9,6 +13,8 @@ public class StartPieceState extends ChoosePieceAutomatonState {
|
|||||||
*/
|
*/
|
||||||
private static final System.Logger LOGGER = System.getLogger(StartPieceState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(StartPieceState.class.getName());
|
||||||
|
|
||||||
|
private Piece piece;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
*
|
*
|
||||||
@@ -25,6 +31,20 @@ public StartPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic lo
|
|||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited StartPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited StartPieceState state.");
|
||||||
|
piece = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].getOccupant();
|
||||||
|
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new StartPieceMessage(piece.getUuid(), calculateTargetIndex(piece)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(RequestMoveMessage msg, int from){
|
||||||
|
if (piece.equals(msg.getPiece())) {
|
||||||
|
Piece occ = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(piece.getColor()).getStartNodeIndex()].getOccupant();
|
||||||
|
if (occ != null){
|
||||||
|
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||||
|
}
|
||||||
|
logic.getServerSender().broadcast(new MoveMessage(piece, false, calculateTargetIndex(piece)));
|
||||||
|
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,5 +53,6 @@ public void enter() {
|
|||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered StartPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered StartPieceState state.");
|
||||||
|
piece = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.choosepiece;
|
package pp.mdga.server.automaton.game.turn.choosepiece;
|
||||||
|
|
||||||
|
import pp.mdga.game.Piece;
|
||||||
|
import pp.mdga.game.PieceState;
|
||||||
|
import pp.mdga.game.ShieldState;
|
||||||
|
import pp.mdga.message.client.RequestMoveMessage;
|
||||||
|
import pp.mdga.message.server.MoveMessage;
|
||||||
|
import pp.mdga.message.server.WaitPieceMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
|
||||||
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
|
import pp.mdga.server.automaton.game.turn.rolldice.FirstRollState;
|
||||||
@@ -9,6 +15,7 @@ public class WaitingPieceState extends ChoosePieceAutomatonState {
|
|||||||
* Create FirstRollState constants.
|
* Create FirstRollState constants.
|
||||||
*/
|
*/
|
||||||
private static final System.Logger LOGGER = System.getLogger(WaitingPieceState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(WaitingPieceState.class.getName());
|
||||||
|
private Piece piece;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
@@ -26,6 +33,21 @@ public WaitingPieceState(ChoosePieceState choosePieceAutomaton, ServerGameLogic
|
|||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered WaitingPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered WaitingPieceState state.");
|
||||||
|
this.piece = logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getWaitingPiece();
|
||||||
|
logic.getServerSender().send(logic.getGame().getActivePlayerId(), new WaitPieceMessage(this.piece.getUuid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(RequestMoveMessage msg, int from){
|
||||||
|
if (msg.getPiece().equals(this.piece)) {
|
||||||
|
piece.setState(PieceState.ACTIVE);
|
||||||
|
Piece thrownOcc = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex()].moveOccupant(this.piece);
|
||||||
|
if (thrownOcc != null) {
|
||||||
|
logic.getGame().getPlayerByColor(thrownOcc.getColor()).addWaitingPiece(thrownOcc);
|
||||||
|
}
|
||||||
|
logic.getServerSender().broadcast(new MoveMessage(this.piece, false, logic.getGame().getPlayerById(logic.getGame().getActivePlayerId()).getStartNodeIndex()));
|
||||||
|
this.choosePieceAutomaton.getTurnAutomaton().setCurrentState(this.choosePieceAutomaton.getTurnAutomaton().getMovePieceState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,5 +56,6 @@ public void enter() {
|
|||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited WaitingPieceState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited WaitingPieceState state.");
|
||||||
|
piece = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,18 @@
|
|||||||
import pp.mdga.game.card.ShieldCard;
|
import pp.mdga.game.card.ShieldCard;
|
||||||
import pp.mdga.game.card.SwapCard;
|
import pp.mdga.game.card.SwapCard;
|
||||||
import pp.mdga.game.card.TurboCard;
|
import pp.mdga.game.card.TurboCard;
|
||||||
|
import pp.mdga.message.client.NoPowerCardMessage;
|
||||||
import pp.mdga.message.client.SelectCardMessage;
|
import pp.mdga.message.client.SelectCardMessage;
|
||||||
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||||
import pp.mdga.visitor.Visitor;
|
import pp.mdga.visitor.Visitor;
|
||||||
|
|
||||||
public class ChoosePowerCardState extends PowerCardAutomatonState implements Visitor {
|
public class ChoosePowerCardState extends PowerCardAutomatonState implements Visitor {
|
||||||
|
|
||||||
|
private static final System.Logger LOGGER = System.getLogger(ChoosePowerCardState.class.getName());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
*
|
*
|
||||||
@@ -26,7 +31,7 @@ public ChoosePowerCardState(PowerCardState powerCardAutomaton, ServerGameLogic l
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
LOGGER.log(System.Logger.Level.INFO, "Entered ChoosePowerCard state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +52,12 @@ public void received(SelectCardMessage msg, int from) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(NoPowerCardMessage msg, int from) {
|
||||||
|
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getRollDiceState());
|
||||||
|
logic.getServerSender().send(from, new DiceNowMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
* This method will be used to change the state of the power card automaton depending on the given card parameter.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import pp.mdga.Resources;
|
import pp.mdga.Resources;
|
||||||
import pp.mdga.game.Piece;
|
import pp.mdga.game.Piece;
|
||||||
import pp.mdga.game.PieceState;
|
import pp.mdga.game.PieceState;
|
||||||
|
import pp.mdga.message.client.AnimationEndMessage;
|
||||||
import pp.mdga.message.client.RequestDieMessage;
|
import pp.mdga.message.client.RequestDieMessage;
|
||||||
import pp.mdga.message.server.DiceAgainMessage;
|
import pp.mdga.message.server.DiceAgainMessage;
|
||||||
import pp.mdga.message.server.DiceNowMessage;
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
@@ -18,6 +19,8 @@ public class FirstRollState extends RollDiceAutomatonState {
|
|||||||
* Create FirstRollState constants.
|
* Create FirstRollState constants.
|
||||||
*/
|
*/
|
||||||
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
|
private static final System.Logger LOGGER = System.getLogger(FirstRollState.class.getName());
|
||||||
|
private List<Piece> moveablePieces;
|
||||||
|
private int roll;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a server state of the specified game logic.
|
* Constructs a server state of the specified game logic.
|
||||||
@@ -31,12 +34,19 @@ public FirstRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered FirstRollState state.");
|
LOGGER.log(System.Logger.Level.INFO, "Entered FirstRollState state.");
|
||||||
|
roll = 0;
|
||||||
|
moveablePieces = new ArrayList<>();
|
||||||
|
for (Piece piece : this.rollDiceAutomaton.getTurnAutomaton().getPlayer().getPieces()) {
|
||||||
|
if (piece.getState() == PieceState.HOME || piece.getState() == PieceState.ACTIVE) {
|
||||||
|
moveablePieces.add(piece);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exit() {
|
public void exit() {
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited FirstRollState state.");
|
LOGGER.log(System.Logger.Level.INFO, "Exited FirstRollState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,25 +58,19 @@ public void exit() {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void received(RequestDieMessage msg, int from) {
|
public void received(RequestDieMessage msg, int from) {
|
||||||
List<Piece> moveablePieces = new ArrayList<>();
|
roll = this.logic.getGame().getDie().shuffle();
|
||||||
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);
|
this.logic.getGame().setDiceEyes(roll);
|
||||||
|
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void received(AnimationEndMessage msg, int from) {
|
||||||
if (!moveablePieces.isEmpty()) {
|
if (!moveablePieces.isEmpty()) {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||||
} else {
|
} else {
|
||||||
if (roll == Resources.MAX_EYES) {
|
if (roll == Resources.MAX_EYES) {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||||
} else {
|
} else {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
|
|
||||||
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getSecondRollState());
|
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getSecondRollState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import pp.mdga.message.client.RequestDieMessage;
|
import pp.mdga.message.client.RequestDieMessage;
|
||||||
import pp.mdga.message.server.DiceAgainMessage;
|
import pp.mdga.message.server.DiceAgainMessage;
|
||||||
|
import pp.mdga.message.server.DiceNowMessage;
|
||||||
import pp.mdga.message.server.DieMessage;
|
import pp.mdga.message.server.DieMessage;
|
||||||
import pp.mdga.server.ServerGameLogic;
|
import pp.mdga.server.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||||
@@ -24,6 +25,7 @@ public SecondRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered SecondRollState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Entered SecondRollState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,11 +44,10 @@ public void exit() {
|
|||||||
@Override
|
@Override
|
||||||
public void received(RequestDieMessage msg, int from) {
|
public void received(RequestDieMessage msg, int from) {
|
||||||
int roll = this.logic.getGame().getDie().shuffle();
|
int roll = this.logic.getGame().getDie().shuffle();
|
||||||
|
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||||
if (roll == 6) {
|
if (roll == 6) {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||||
} else {
|
} else {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceAgainMessage());
|
|
||||||
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getThirdRollState());
|
this.rollDiceAutomaton.setCurrentState(this.rollDiceAutomaton.getThirdRollState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
package pp.mdga.server.automaton.game.turn.rolldice;
|
package pp.mdga.server.automaton.game.turn.rolldice;
|
||||||
|
|
||||||
import pp.mdga.message.client.RequestDieMessage;
|
import pp.mdga.message.client.RequestDieMessage;
|
||||||
import pp.mdga.message.server.ActivePlayerMessage;
|
import pp.mdga.message.server.*;
|
||||||
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.ServerGameLogic;
|
||||||
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
import pp.mdga.server.automaton.game.turn.RollDiceState;
|
||||||
|
|
||||||
@@ -27,6 +23,7 @@ public ThirdRollState(RollDiceState rollDiceAutomaton, ServerGameLogic logic) {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
|
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DiceNowMessage());
|
||||||
LOGGER.log(System.Logger.Level.DEBUG, "Exited ThirdRollState state.");
|
LOGGER.log(System.Logger.Level.DEBUG, "Exited ThirdRollState state.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,8 +42,8 @@ public void exit() {
|
|||||||
@Override
|
@Override
|
||||||
public void received(RequestDieMessage msg, int from) {
|
public void received(RequestDieMessage msg, int from) {
|
||||||
int roll = this.logic.getGame().getDie().shuffle();
|
int roll = this.logic.getGame().getDie().shuffle();
|
||||||
|
this.logic.getServerSender().broadcast(new DieMessage(roll));
|
||||||
if (roll == 6) {
|
if (roll == 6) {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new DieMessage(roll));
|
|
||||||
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
this.rollDiceAutomaton.getTurnAutomaton().setCurrentState(this.rollDiceAutomaton.getTurnAutomaton().getChoosePieceState());
|
||||||
} else {
|
} else {
|
||||||
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new NoTurnMessage());
|
this.logic.getServerSender().send(this.logic.getGame().getActivePlayerId(), new NoTurnMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user