merge the new developmentbranch into the test branch #39
@@ -7,6 +7,8 @@
|
||||
|
||||
public class AnimationState extends GameStates {
|
||||
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
private final GameState parent;
|
||||
|
||||
public AnimationState(ClientState parent, ClientGameLogic logic) {
|
||||
@@ -16,7 +18,7 @@ public AnimationState(ClientState parent, ClientGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
LOGGER.log(System.Logger.Level.INFO, "Entering AnimationState");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
import java.util.UUID;
|
||||
|
||||
public abstract class GameStates extends ClientState {
|
||||
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
public GameStates(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
}
|
||||
@@ -27,6 +30,7 @@ protected void handlePowerCard(PlayCardMessage msg) {
|
||||
} else {
|
||||
Piece ownPiece = logic.getGame().getPieceThroughUUID(msg.getPieces().get(0).getUuid());
|
||||
Piece enemyPiece = logic.getGame().getPieceThroughUUID(msg.getPieces().get(1).getUuid());
|
||||
LOGGER.log(System.Logger.Level.INFO, "Swapping");
|
||||
int ownIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(ownPiece);
|
||||
logic.addNotification(new SwapPieceNotification(ownPiece.getUuid(), enemyPiece.getUuid()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(enemyPiece)].setOccupant(ownPiece);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
public class WaitingState extends GameStates {
|
||||
|
||||
private final GameState parent;
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
public WaitingState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
@@ -46,7 +47,6 @@ public void received(DieMessage msg) {
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
|
||||
logic.getGame().getGameStatistics().increaseDiced6();
|
||||
}
|
||||
parent.setState(parent.getAnimation());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,35 +62,24 @@ public void received(PlayCardMessage msg) {
|
||||
public void received(ActivePlayerMessage msg) {
|
||||
logic.addNotification(new ActivePlayerNotification(msg.getColor()));
|
||||
logic.getGame().setActiveColor(msg.getColor());
|
||||
parent.setState(parent.getAnimation());
|
||||
parent.setState(parent.getTurn());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
|
||||
for (int i = msg.getTargetIndex() + 1; i < 4; i++) {
|
||||
if (!logic.getGame().getPlayerByColor(pieceToMove.getColor()).getHomeNodes()[i].isOccupied()) {
|
||||
pieceToMove.setState(PieceState.HOME);
|
||||
break;
|
||||
}
|
||||
pieceToMove.setState(PieceState.HOMEFINISHED);
|
||||
}
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
} else {
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
|
||||
throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown();
|
||||
logic.getGame().getGameStatistics().increasePiecesThrown();
|
||||
}
|
||||
if (logic.getGame().getPlayerByColor(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)) {
|
||||
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true));
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
|
||||
} else {
|
||||
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(pieceToMove);
|
||||
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
this.LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
|
||||
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
}
|
||||
}
|
||||
parent.setState(parent.getAnimation());
|
||||
|
||||
@@ -34,6 +34,7 @@ public void enter() {
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
canChange = false;
|
||||
LOGGER.log(System.Logger.Level.INFO, "Exiting WaitRankingState");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.notification.HomeMoveNotification;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.ThrowPieceNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -15,6 +17,7 @@ public class SelectPieceState extends ChoosePieceStates {
|
||||
|
||||
private final ChoosePieceState parent;
|
||||
private ArrayList<Piece> possiblePieces;
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
public SelectPieceState(ClientState parent, ClientGameLogic logic) {
|
||||
super(parent, logic);
|
||||
@@ -37,27 +40,28 @@ public void setPossiblePieces(ArrayList<Piece> possiblePieces) {
|
||||
|
||||
@Override
|
||||
public void selectPiece(Piece piece) {
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
if(possiblePieces.contains(piece)){
|
||||
pieces.add(piece);
|
||||
logic.send(new SelectedPiecesMessage(pieces));
|
||||
logic.send(new RequestMoveMessage(piece));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg) {
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
if (msg.isHomeMove()) {
|
||||
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
|
||||
} else {
|
||||
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) {
|
||||
throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant());
|
||||
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown();
|
||||
logic.getGame().getGameStatistics().increasePiecesThrown();
|
||||
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
|
||||
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
}
|
||||
logic.addNotification(new MovePieceNotification(piece.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
|
||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||
}
|
||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@
|
||||
import pp.mdga.client.ClientState;
|
||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.ThrowPieceNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -38,15 +41,22 @@ public void setMoveablePiece(Piece moveablePiece) {
|
||||
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
if(moveablePiece.equals(piece)){
|
||||
pieces.add(piece);
|
||||
logic.send(new SelectedPiecesMessage(pieces));
|
||||
logic.send(new RequestMoveMessage(piece));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg){
|
||||
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
int i = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
|
||||
LOGGER.log(System.Logger.Level.INFO, "Received MoveMessage with start index: " + i);
|
||||
logic.addNotification(new MovePieceNotification(msg.getPiece().getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex()));
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(piece);
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), piece.getColor()));
|
||||
}
|
||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.game.PieceState;
|
||||
import pp.mdga.message.client.RequestMoveMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.MoveMessage;
|
||||
import pp.mdga.notification.MovePieceNotification;
|
||||
import pp.mdga.notification.ThrowPieceNotification;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,16 +35,20 @@ public void exit() {
|
||||
|
||||
@Override
|
||||
public void selectPiece(Piece piece){
|
||||
ArrayList<Piece> pieces = new ArrayList<>();
|
||||
if(moveablePiece.equals(piece)){
|
||||
pieces.add(piece);
|
||||
logic.send(new SelectedPiecesMessage(pieces));
|
||||
logic.send(new RequestMoveMessage(piece));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(MoveMessage msg){
|
||||
Piece pieceToMove = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].moveOccupant(pieceToMove);
|
||||
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getStartNodeIndex(), true));
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
logic.addNotification(new ThrowPieceNotification(occ.getUuid(), pieceToMove.getColor()));
|
||||
}
|
||||
pieceToMove.setState(PieceState.ACTIVE);
|
||||
parent.getParent().setState(parent.getParent().getMovePiece());
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
public class ShieldState extends PowerCardStates {
|
||||
|
||||
private final PowerCardState parent;
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
|
||||
private ArrayList<Piece> possiblePieces;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.message.client.RequestPlayCardMessage;
|
||||
import pp.mdga.message.client.SelectCardMessage;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.notification.SelectableSwapNotification;
|
||||
|
||||
@@ -61,7 +62,10 @@ public void selectPiece(Piece piece){
|
||||
selectedEnemyPiece = piece;
|
||||
}
|
||||
if (selectedOwnPiece != null && selectedEnemyPiece != null){
|
||||
logic.send(RequestPlayCardMessage.requestPlaySwap(selectedOwnPiece.getUuid(), selectedEnemyPiece.getUuid()));
|
||||
ArrayList<Piece> temp = new ArrayList<>();
|
||||
temp.add(selectedOwnPiece);
|
||||
temp.add(selectedEnemyPiece);
|
||||
logic.send(new SelectedPiecesMessage(temp));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,10 @@ private StartNode createStartNode(int i) {
|
||||
*/
|
||||
public int getInfieldIndexOfPiece(Piece piece) {
|
||||
for (int i = 0; i < infield.length; i++) {
|
||||
if (infield[i].getOccupant() == piece) {
|
||||
if(infield[i].getOccupant() == null) {
|
||||
continue;
|
||||
}
|
||||
if (infield[i].getOccupant().equals(piece)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,15 @@ public void received(SelectCardMessage msg, int from){
|
||||
currentState.received(msg, from);
|
||||
}
|
||||
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
this.currentState.received(msg, from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(SelectedPiecesMessage 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.
|
||||
|
||||
@@ -51,11 +51,14 @@ public void received(AnimationEndMessage msg, int from){
|
||||
if (logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).isFinished()){
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new SpectatorMessage());
|
||||
setActivePlayer(logic.getGame().getActiveColor());
|
||||
this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState());
|
||||
} else if (logic.getGame().getDiceEyes() == 6){
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new DiceNowMessage());
|
||||
this.turnAutomaton.setCurrentState(this.turnAutomaton.getRollDiceState());
|
||||
} else {
|
||||
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(logic.getGame().getActiveColor()), new EndOfTurnMessage());
|
||||
setActivePlayer(logic.getGame().getActiveColor());
|
||||
this.turnAutomaton.getGameAutomaton().setCurrentState(this.turnAutomaton.getGameAutomaton().getTurnState());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public PlayPowerCardState(TurnState turnAutomaton, ServerGameLogic logic) {
|
||||
|
||||
@Override
|
||||
public void enter() {
|
||||
|
||||
LOGGER.log(System.Logger.Level.DEBUG, "Entered PlayPowerCardState state.");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ public void enter() {
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
if (moveablePieces.contains(msg.getPiece())) {
|
||||
int indexOfPiece = moveablePieces.indexOf(msg.getPiece());
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(moveablePieces.get(indexOfPiece))].clearOccupant();
|
||||
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()))) {
|
||||
|
||||
@@ -38,6 +38,7 @@ public void enter() {
|
||||
@Override
|
||||
public void received(RequestMoveMessage msg, int from){
|
||||
if (piece.equals(msg.getPiece())) {
|
||||
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant();
|
||||
Piece occ = logic.getGame().getBoard().getInfield()[logic.getGame().getPlayerByColor(piece.getColor()).getStartNodeIndex()].getOccupant();
|
||||
if (occ != null){
|
||||
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
|
||||
|
||||
@@ -3,10 +3,13 @@
|
||||
import pp.mdga.game.Piece;
|
||||
import pp.mdga.message.client.SelectedPiecesMessage;
|
||||
import pp.mdga.message.server.IncorrectRequestMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.message.server.PossiblePieceMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.automaton.game.turn.PowerCardState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SwapCardState extends PowerCardAutomatonState {
|
||||
|
||||
private final System.Logger LOGGER = System.getLogger(this.getClass().getName());
|
||||
@@ -56,6 +59,13 @@ public void received(SelectedPiecesMessage msg, int from) {
|
||||
&& this.powerCardAutomaton.getVisitor().getSwapOtherPieces().contains(first))) {
|
||||
this.powerCardAutomaton.addSelectedPiece(first);
|
||||
this.powerCardAutomaton.addSelectedPiece(second);
|
||||
|
||||
ArrayList<Piece> temp = new ArrayList<>();
|
||||
temp.add(first);
|
||||
temp.add(second);
|
||||
|
||||
logic.getServerSender().broadcast(new PlayCardMessage(this.powerCardAutomaton.getSelectedCard(), temp, 1));
|
||||
|
||||
this.powerCardAutomaton.getTurnAutomaton().setCurrentState(this.powerCardAutomaton.getTurnAutomaton().getPlayPowerCardState());
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user