added some more client game logic

This commit is contained in:
Fleischer Hanno
2024-12-01 12:06:06 +01:00
parent bdc527b83e
commit 789868863f
8 changed files with 80 additions and 41 deletions

View File

@@ -16,19 +16,10 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
} }
private CeremonyNotification prepareNotification(){
CeremonyNotification notification = new CeremonyNotification();
//TODO: creation of the notification
return notification;
}
@Override @Override
public void enter() { public void enter() {
currentState = podiumState; currentState = podiumState;
logic.addNotification(prepareNotification()); logic.addNotification(createCeremonyNotification());
} }
@Override @Override

View File

@@ -4,6 +4,7 @@
import pp.mdga.game.Color; import pp.mdga.game.Color;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.notification.CeremonyNotification;
import java.lang.System.Logger.Level; import java.lang.System.Logger.Level;
@@ -230,4 +231,32 @@ public void selectStart(){
public void selectAnimationEnd(){ public void selectAnimationEnd(){
LOGGER.log(Level.DEBUG, "Animation end not allowed"); 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;
}
} }

View File

@@ -23,6 +23,7 @@ public void exit() {
} }
@Override
public void selectNext(){ public void selectNext(){
parent.setState(parent.getStatisticsState()); parent.setState(parent.getStatisticsState());
} }

View File

@@ -17,4 +17,9 @@ public void enter() {
public void exit() { public void exit() {
} }
@Override
public void selectNext(){
logic.setState(logic.getDialogs());
}
} }

View File

@@ -9,6 +9,7 @@
import pp.mdga.notification.ShieldActiveNotification; import pp.mdga.notification.ShieldActiveNotification;
import pp.mdga.notification.ShieldSuppressedNotification; import pp.mdga.notification.ShieldSuppressedNotification;
import pp.mdga.notification.SwapPieceNotification; import pp.mdga.notification.SwapPieceNotification;
import pp.mdga.notification.ThrowPieceNotification;
public abstract class GameStates extends ClientState { public abstract class GameStates extends ClientState {
public GameStates(ClientState parent, ClientGameLogic logic) { 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().getPlayerByColor(logic.getGame().getActiveColor()).removeHandCard(msg.getCard());
logic.getGame().getDiscardPile().add(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();
}
} }

View File

@@ -19,30 +19,6 @@ public WaitingState(ClientState parent, ClientGameLogic logic) {
this.parent = (GameState) parent; 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 @Override
public void enter() { public void enter() {
@@ -55,7 +31,6 @@ public void exit() {
@Override @Override
public void received(CeremonyMessage msg){ public void received(CeremonyMessage msg){
logic.addNotification(createCeremonyNotification());
logic.setState(logic.getCeremony()); logic.setState(logic.getCeremony());
} }
@@ -69,6 +44,10 @@ public void received(DiceNowMessage msg){
public void received(DieMessage msg){ public void received(DieMessage msg){
logic.getGame().setDiceEyes(msg.getDiceEye()); logic.getGame().setDiceEyes(msg.getDiceEye());
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), logic.getGame().getDiceEyes(), logic.getGame().getDiceEyes() * logic.getGame().getDiceModifier())); 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()); parent.setState(parent.getAnimation());
} }
@@ -76,6 +55,8 @@ public void received(DieMessage msg){
public void received(PlayCardMessage msg){ public void received(PlayCardMessage msg){
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard())); logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
handlePowerCard(msg); handlePowerCard(msg);
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
logic.getGame().getGameStatistics().increaseCardsPlayed();
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }
@@ -89,15 +70,23 @@ public void received(ActivePlayerMessage msg){
@Override @Override
public void received(MoveMessage msg){ public void received(MoveMessage msg){
Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); Piece pieceToMove = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier());
if(logic.getGame().getBoard().getPlayerData().get(pieceToMove.getColor()).getStartNodeIndex() == logic.getGame().getBoard().getInfieldIndexOfPiece(pieceToMove)){ if (msg.isHomeMove()){
logic.addNotification(new MovePieceNotification(pieceToMove.getUuid(), msg.getTargetIndex(), true));
} else 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().getPlayerData().get(pieceToMove.getColor()).setPieceInHome(msg.getTargetIndex(), pieceToMove);
} else { } else {
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isOccupied()) { 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()); parent.setState(parent.getAnimation());
} }

View File

@@ -8,7 +8,6 @@
import pp.mdga.message.server.MoveMessage; import pp.mdga.message.server.MoveMessage;
import pp.mdga.notification.HomeMoveNotification; import pp.mdga.notification.HomeMoveNotification;
import pp.mdga.notification.MovePieceNotification; import pp.mdga.notification.MovePieceNotification;
import pp.mdga.notification.SelectableMoveNotification;
import java.util.ArrayList; import java.util.ArrayList;
@@ -48,7 +47,14 @@ public void received(MoveMessage msg){
Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier()); Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getIdentifier());
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().getPlayerData().get(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece);
} else { } 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())); 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());

View File

@@ -163,6 +163,15 @@ public void increaseTraveledNodes() {
traveledNodes++; 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. * This method increases the value of cardsPlayed by 1.
*/ */