diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java index a34d765c..38541512 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/CeremonyState.java @@ -16,19 +16,10 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) { super(parent, logic); } - - private CeremonyNotification prepareNotification(){ - CeremonyNotification notification = new CeremonyNotification(); - - //TODO: creation of the notification - - return notification; - } - @Override public void enter() { currentState = podiumState; - logic.addNotification(prepareNotification()); + logic.addNotification(createCeremonyNotification()); } @Override diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java index 190e4c45..97d058a5 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ClientState.java @@ -4,6 +4,7 @@ import pp.mdga.game.Color; import pp.mdga.game.Piece; import pp.mdga.message.server.*; +import pp.mdga.notification.CeremonyNotification; import java.lang.System.Logger.Level; @@ -230,4 +231,32 @@ public void selectStart(){ public void selectAnimationEnd(){ LOGGER.log(Level.DEBUG, "Animation end not allowed"); } + + public void selectNext(){ + LOGGER.log(Level.DEBUG, "Next not allowed"); + } + + protected CeremonyNotification createCeremonyNotification(){ + CeremonyNotification notification = new CeremonyNotification(); + for (var player : logic.getGame().getPlayers().entrySet()){ + notification.getColors().add(player.getValue().getColor()); + notification.getNames().add(player.getValue().getName()); + notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6()); + notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes()); + notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown()); + notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown()); + notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes()); + notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed()); + } + + notification.getNames().add("GAME OVERALL"); + notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes()); + notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6()); + notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown()); + notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown()); + notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes()); + notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed()); + + return notification; + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java index 199fde11..4410d8c0 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/PodiumState.java @@ -23,6 +23,7 @@ public void exit() { } + @Override public void selectNext(){ parent.setState(parent.getStatisticsState()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java index fdc5de34..89c5e8a1 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/ceremonyState/StatisticsState.java @@ -17,4 +17,9 @@ public void enter() { public void exit() { } + + @Override + public void selectNext(){ + logic.setState(logic.getDialogs()); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java index 6be90533..5be2d171 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/GameStates.java @@ -9,6 +9,7 @@ import pp.mdga.notification.ShieldActiveNotification; import pp.mdga.notification.ShieldSuppressedNotification; import pp.mdga.notification.SwapPieceNotification; +import pp.mdga.notification.ThrowPieceNotification; public abstract class GameStates extends ClientState { public GameStates(ClientState parent, ClientGameLogic logic) { @@ -37,4 +38,12 @@ protected void handlePowerCard(PlayCardMessage msg){ logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard()); logic.getGame().getDiscardPile().add(msg.getCard()); } + + protected void throwPiece(Piece piece){ + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(piece.getColor()).addWaitingPiece(piece); + logic.addNotification(new ThrowPieceNotification(piece.getUuid())); + logic.getGame().getPlayerByColor(piece.getColor()).getPlayerStatistic().increasePiecesBeingThrown(); + logic.getGame().getGameStatistics().increasePiecesBeingThrown(); + } } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java index 8c43233e..6f3708ac 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/WaitingState.java @@ -19,30 +19,6 @@ public WaitingState(ClientState parent, ClientGameLogic logic) { this.parent = (GameState) parent; } - private CeremonyNotification createCeremonyNotification(){ - CeremonyNotification notification = new CeremonyNotification(); - for (var player : logic.getGame().getPlayers().entrySet()){ - notification.getColors().add(player.getValue().getColor()); - notification.getNames().add(player.getValue().getName()); - notification.getSixes().add(player.getValue().getPlayerStatistic().getDiced6()); - notification.getBonusNodes().add(player.getValue().getPlayerStatistic().getActivatedBonusNodes()); - notification.getPiecesLost().add(player.getValue().getPlayerStatistic().getPiecesBeingThrown()); - notification.getPiecesThrown().add(player.getValue().getPlayerStatistic().getPiecesThrown()); - notification.getNodesMoved().add(player.getValue().getPlayerStatistic().getTraveledNodes()); - notification.getBonusCardsPlayed().add(player.getValue().getPlayerStatistic().getCardsPlayed()); - } - - notification.getNames().add("GAME OVERALL"); - notification.getNodesMoved().add(logic.getGame().getGameStatistics().getTraveledNodes()); - notification.getSixes().add(logic.getGame().getGameStatistics().getDiced6()); - notification.getPiecesThrown().add(logic.getGame().getGameStatistics().getPiecesThrown()); - notification.getPiecesLost().add(logic.getGame().getGameStatistics().getPiecesBeingThrown()); - notification.getBonusNodes().add(logic.getGame().getGameStatistics().getActivatedBonusNodes()); - notification.getBonusCardsPlayed().add(logic.getGame().getGameStatistics().getCardsPlayed()); - - return notification; - } - @Override public void enter() { @@ -55,7 +31,6 @@ public void exit() { @Override public void received(CeremonyMessage msg){ - logic.addNotification(createCeremonyNotification()); logic.setState(logic.getCeremony()); } @@ -69,6 +44,10 @@ public void received(DiceNowMessage msg){ public void received(DieMessage msg){ logic.getGame().setDiceEyes(msg.getDiceEye()); logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); + if(msg.getDiceEye() == 6){ + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6(); + logic.getGame().getGameStatistics().increaseDiced6(); + } parent.setState(parent.getAnimation()); } @@ -76,6 +55,8 @@ public void received(DieMessage msg){ public void received(PlayCardMessage msg){ logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); handlePowerCard(msg); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed(); + logic.getGame().getGameStatistics().increaseCardsPlayed(); parent.setState(parent.getAnimation()); } @@ -89,15 +70,23 @@ public void received(ActivePlayerMessage msg){ @Override public void received(MoveMessage msg){ Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); - if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ - logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true)); - } else if (msg.isHomeMove()){ + if (msg.isHomeMove()){ logic.addNotification(new HomeMoveNotification(pieceToMove.getUuid(), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove); } else { if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { - logic.addNotification(new ThrowPieceNotification(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant().getUuid())); + throwPiece(logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant()); + logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increasePiecesThrown(); + logic.getGame().getGameStatistics().increasePiecesThrown(); + } + if(logic.getGame().getBoard().getPlayerData().get(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); } - logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove), msg.getTargetIndex())); } parent.setState(parent.getAnimation()); } diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java index 209ba093..89519bdc 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/client/gameState/turnState/choosePieceState/SelectPieceState.java @@ -8,7 +8,6 @@ import pp.mdga.message.server.MoveMessage; import pp.mdga.notification.HomeMoveNotification; import pp.mdga.notification.MovePieceNotification; -import pp.mdga.notification.SelectableMoveNotification; import java.util.ArrayList; @@ -48,7 +47,14 @@ public void received(MoveMessage msg){ Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); if(msg.isHomeMove()){ logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); + logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); + logic.getGame().getBoard().getPlayerData().get(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(); + } logic.addNotification(new MovePieceNotification(piece.getUuid(), logic.getGame().getBoard().getInfieldIndexOfPiece(piece), msg.getTargetIndex())); } parent.getParent().setState(parent.getParent().getMovePiece()); diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java index dab633f4..2b5e31aa 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Statistic.java @@ -163,6 +163,15 @@ public void increaseTraveledNodes() { traveledNodes++; } + /** + * This method increases the value of traveledNodes by the given amount. + * + * @param nodes the amount of nodes to increase the traveledNodes by. + */ + public void increaseTraveledNodes(int nodes) { + traveledNodes += nodes; + } + /** * This method increases the value of cardsPlayed by 1. */