This commit is contained in:
Cedric Beck
2024-12-11 14:23:44 +01:00
13 changed files with 160 additions and 44 deletions

View File

@@ -88,7 +88,7 @@ public class MdgaApp extends SimpleApplication {
private final TimerManager timerManager = new TimerManager(); private final TimerManager timerManager = new TimerManager();
public static final int DEBUG_MULTIPLIER = 1; public static final int DEBUG_MULTIPLIER = 0;
public MdgaApp() { public MdgaApp() {
networkConnection = new NetworkSupport(this); networkConnection = new NetworkSupport(this);
@@ -351,5 +351,9 @@ public GameView getGameView() {
public TimerManager getTimerManager() { public TimerManager getTimerManager() {
return timerManager; return timerManager;
} }
public CeremonyView getCeremonyView() {
return ceremonyView;
}
} }

View File

@@ -144,6 +144,10 @@ public void enter(MdgaState state) {
//app.enter(state); //app.enter(state);
} }
public void next() {
app.getGameLogic().selectNext();
}
public void setSwap(boolean swap) { public void setSwap(boolean swap) {
this.swap = swap; this.swap = swap;
} }

View File

@@ -133,8 +133,7 @@ private void handleGame(Notification notification) {
app.getAcousticHandler().playSound(MdgaSound.UI90); app.getAcousticHandler().playSound(MdgaSound.UI90);
delay = STANDARD_DELAY; delay = STANDARD_DELAY;
} else if (notification instanceof CeremonyNotification ceremonyNotification) { } else if (notification instanceof CeremonyNotification ceremonyNotification) {
app.enter(MdgaState.CEREMONY); CeremonyView ceremonyView = app.getCeremonyView();
CeremonyView ceremonyView = (CeremonyView) app.getView();
int size = ceremonyNotification.getNames().size(); int size = ceremonyNotification.getNames().size();
if (ceremonyNotification.getPiecesThrown().size() != size || if (ceremonyNotification.getPiecesThrown().size() != size ||
@@ -162,6 +161,7 @@ private void handleGame(Notification notification) {
ceremonyView.addStatisticsRow(name, v1, v2, v3, v4, v5, v6); ceremonyView.addStatisticsRow(name, v1, v2, v3, v4, v5, v6);
} }
app.enter(MdgaState.CEREMONY);
} else if (notification instanceof DiceNowNotification) { } else if (notification instanceof DiceNowNotification) {
guiHandler.hideText(); guiHandler.hideText();
guiHandler.showDice(); guiHandler.showDice();

View File

@@ -184,7 +184,7 @@ public void forward() {
enterSub(SubState.STATISTICS); enterSub(SubState.STATISTICS);
break; break;
case STATISTICS: case STATISTICS:
app.getModelSynchronize().enter(MdgaState.MAIN); app.getModelSynchronize().next();
break; break;
} }
} }
@@ -205,7 +205,7 @@ public void addCeremonyParticipant(Color color, int pos, String name) {
ceremonyButtons.add(button); ceremonyButtons.add(button);
if (state.equals(SubState.AWARD_CEREMONY)) { if (state != null && state.equals(SubState.AWARD_CEREMONY)) {
button.hide(); button.hide();
button.show(); button.show();
} }

View File

@@ -2,6 +2,7 @@
import pp.mdga.client.ClientGameLogic; import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.notification.StartDialogNotification;
public class StatisticsState extends CeremonyStates { public class StatisticsState extends CeremonyStates {
@@ -36,6 +37,7 @@ public void exit() {
*/ */
@Override @Override
public void selectNext() { public void selectNext() {
logic.addNotification(new StartDialogNotification());
logic.setState(logic.getDialogs()); logic.setState(logic.getDialogs());
} }
} }

View File

@@ -11,6 +11,8 @@ public class AnimationState extends GameStates {
private final GameState parent; private final GameState parent;
private boolean spectator = false;
/** /**
* Constructs a client state of the specified game logic. * Constructs a client state of the specified game logic.
* *
@@ -34,7 +36,16 @@ public void enter() {
*/ */
@Override @Override
public void exit() { public void exit() {
spectator = false;
}
/**
* Sets the spectator.
*
* @param spectator the spectator
*/
public void setSpectator(boolean spectator) {
this.spectator = spectator;
} }
/** /**
@@ -43,6 +54,10 @@ public void exit() {
@Override @Override
public void selectAnimationEnd() { public void selectAnimationEnd() {
logic.send(new AnimationEndMessage()); logic.send(new AnimationEndMessage());
parent.setState(parent.getWaiting()); if (spectator){
parent.setState(parent.getSpectator());
} else {
parent.setState(parent.getWaiting());
}
} }
} }

View File

@@ -4,6 +4,7 @@
import pp.mdga.client.ClientState; import pp.mdga.client.ClientState;
import pp.mdga.client.GameState; import pp.mdga.client.GameState;
import pp.mdga.game.BonusCard; import pp.mdga.game.BonusCard;
import pp.mdga.game.Node;
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.PieceState; import pp.mdga.game.PieceState;
import pp.mdga.game.ShieldState; import pp.mdga.game.ShieldState;
@@ -31,6 +32,7 @@ public SpectatorState(ClientState parent, ClientGameLogic logic) {
*/ */
@Override @Override
public void enter() { public void enter() {
parent.getAnimation().setSpectator(true);
} }
/** /**
@@ -42,7 +44,9 @@ public void exit() {
} }
/** /**
* Receives the Ceremony Message. * Handles the reception of a CeremonyMessage.
*
* @param msg the ceremony message
*/ */
@Override @Override
public void received(CeremonyMessage msg) { public void received(CeremonyMessage msg) {
@@ -50,34 +54,30 @@ public void received(CeremonyMessage msg) {
} }
/** /**
* Receives the Draw card message. * Handles the reception of a DieMessage.
* *
* @param msg the draw card message * @param msg the die message
*/
@Override
public void received(DrawCardMessage msg) {
logic.getGame().getActivePlayer().addHandCard(msg.getCard());
if (msg.getCard() instanceof HiddenCard) {
logic.addNotification(new DrawCardNotification(logic.getGame().getActiveColor(), BonusCard.HIDDEN));
}
//stats
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
}
/**
* Receives the Die Message.
*/ */
@Override @Override
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())); if (logic.getGame().getTurboFlag()) {
parent.setState(parent.getAnimation()); logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye(), logic.getGame().getDiceModifier()));
} else {
logic.addNotification(new RollDiceNotification(logic.getGame().getActiveColor(), msg.getDiceEye()));
}
//stats
if (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();
logic.getGame().getGameStatistics().increaseDiced6();
}
} }
/** /**
* Receives the PlayCardMessage Message. * Handles the reception of a PlayCardMessage.
*
* @param msg the play card message
*/ */
@Override @Override
public void received(PlayCardMessage msg) { public void received(PlayCardMessage msg) {
@@ -89,28 +89,73 @@ public void received(PlayCardMessage msg) {
} }
/** /**
* Receives the ActivePlayerMessage Message. * Handles the reception of an ActivePlayerMessage.
*
* @param msg the active player message
*/ */
@Override @Override
public void received(ActivePlayerMessage msg) { public void received(ActivePlayerMessage msg) {
logic.addNotification(new ActivePlayerNotification(msg.getColor())); logic.addNotification(new ActivePlayerNotification(msg.getColor()));
logic.getGame().setActiveColor(msg.getColor()); logic.getGame().setActiveColor(msg.getColor());
parent.setState(parent.getAnimation()); if (msg.getColor() == logic.getGame().getPlayers().get(logic.getOwnPlayerId()).getColor()) {
parent.setState(parent.getTurn());
} else {
for (Piece piece : logic.getGame().getActivePlayer().getPieces()) {
if (piece.isShielded() || piece.isSuppressed()) {
logic.addNotification(new RemoveShieldNotification(piece.getUuid()));
piece.setShield(ShieldState.NONE);
}
}
}
} }
/** /**
* Receives the MoveMessage Message. * Handles the reception of a MoveMessage.
*
* @param msg the move message
*/ */
@Override @Override
public void received(MoveMessage msg) { public void received(MoveMessage msg) {
Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid()); Piece piece = logic.getGame().getPieceThroughUUID(msg.getPiece().getUuid());
if (msg.isHomeMove()) { if (msg.isHomeMove()) {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex())); if (piece.getState().equals(PieceState.HOME)) {
logic.getGame().getBoard().getInfield()[logic.getGame().getBoard().getInfieldIndexOfPiece(piece)].clearOccupant(); logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
logic.getGame().getPlayerByColor(piece.getColor()).setPieceInHome(msg.getTargetIndex(), piece); int pieceHomeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
Node pieceNode = logic.getGame().getActivePlayer().getHomeNodes()[pieceHomeIndex];
//gets the oldNode
int homeIndex = logic.getGame().getActivePlayer().getHomeIndexOfPiece(piece);
Node oldNode = logic.getGame().getActivePlayer().getHomeNodes()[homeIndex];
//gets the targetNode
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
} else {
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
} else {
logic.addNotification(new HomeMoveNotification(piece.getUuid(), msg.getTargetIndex()));
int oldNoteIdx = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Node oldNode = logic.getGame().getBoard().getInfield()[oldNoteIdx];
//gets the targetNode
Node targetNode = logic.getGame().getActivePlayer().getHomeNodes()[msg.getTargetIndex()];
if (msg.getTargetIndex() == logic.getGame().getActivePlayer().getHighestHomeIdx()) {
piece.setState(PieceState.HOMEFINISHED);
} else {
piece.setState(PieceState.HOME);
}
oldNode.clearOccupant();
targetNode.setOccupant(piece);
}
} else { } else {
int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece); int oldIndex = logic.getGame().getBoard().getInfieldIndexOfPiece(piece);
Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant(); Piece occ = logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].getOccupant();
if (occ != null) { if (occ != null) {
//TODO: MoveThrowNotification //TODO: MoveThrowNotification
@@ -122,7 +167,7 @@ public void received(MoveMessage msg) {
//set occ to waiting //set occ to waiting
logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ); logic.getGame().getPlayerByColor(occ.getColor()).addWaitingPiece(occ);
} }
if (msg.getPiece().getState().equals(PieceState.WAITING)) { if (oldIndex == -1) {
logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true)); logic.addNotification(new MovePieceNotification(piece.getUuid(), msg.getTargetIndex(), true));
logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece); logic.getGame().getPlayerByColor(piece.getColor()).removeWaitingPiece(piece);
piece.setState(PieceState.ACTIVE); piece.setState(PieceState.ACTIVE);
@@ -133,7 +178,17 @@ public void received(MoveMessage msg) {
} }
//set new node //set new node
logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece); logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].setOccupant(piece);
if (logic.getGame().getBoard().getInfield()[msg.getTargetIndex()].isStart()) {
if (piece.isShielded()) {
piece.setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(piece.getUuid()));
}
} else if (piece.isSuppressed()) {
piece.setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(piece.getUuid()));
}
} }
System.out.println("send AnimationEndMessage");
logic.getGame().setTurboFlag(false); logic.getGame().setTurboFlag(false);
parent.setState(parent.getAnimation()); parent.setState(parent.getAnimation());
} }

View File

@@ -109,6 +109,16 @@ public void received(EndOfTurnMessage msg) {
currentState.received(msg); currentState.received(msg);
} }
/**
* Receives the dice now message.
*
* @param msg the dice now message
*/
@Override
public void received(DiceNowMessage msg) {
currentState.received(msg);
}
/** /**
* Receives the move message. * Receives the move message.
* *

View File

@@ -4,6 +4,7 @@
import pp.mdga.game.Piece; import pp.mdga.game.Piece;
import pp.mdga.game.PieceState; import pp.mdga.game.PieceState;
import pp.mdga.game.Player; import pp.mdga.game.Player;
import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.*; import pp.mdga.message.client.*;
import pp.mdga.message.server.*; import pp.mdga.message.server.*;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -51,7 +52,12 @@ public void exit() {
public void initializeGame() { public void initializeGame() {
for (var player : this.logic.getGame().getPlayers().values()) { for (var player : this.logic.getGame().getPlayers().values()) {
player.initialize(); player.initialize();
player.addHandCard(this.logic.getGame().draw()); PowerCard card = this.logic.getGame().draw();
if (card == null) {
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
} else {
player.addHandCard(card);
}
Piece piece = player.getPieces()[0]; Piece piece = player.getPieces()[0];
player.getWaitingArea()[0] = null; player.getWaitingArea()[0] = null;

View File

@@ -5,6 +5,7 @@
import pp.mdga.game.card.PowerCard; import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.RequestMoveMessage; import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.server.DrawCardMessage; import pp.mdga.message.server.DrawCardMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.MoveMessage; import pp.mdga.message.server.MoveMessage;
import pp.mdga.message.server.SelectPieceMessage; import pp.mdga.message.server.SelectPieceMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -137,13 +138,21 @@ public void received(RequestMoveMessage msg, int from) {
if (targetNode.isBonus()) { if (targetNode.isBonus()) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes(); logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes(); logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
PowerCard cardToDraw = logic.getGame().draw();
for (Player p : logic.getGame().getPlayersAsList()) { for (Player p : logic.getGame().getPlayersAsList()) {
if (p.getColor() == logic.getGame().getActiveColor()) { if (p.getColor() == logic.getGame().getActiveColor()) {
PowerCard cardToDraw = logic.getGame().draw(); if (cardToDraw == null) {
p.addHandCard(cardToDraw); this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw)); } else {
p.addHandCard(cardToDraw);
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
}
} else { } else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard())); if (cardToDraw == null) {
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
} }
} }
} }

View File

@@ -7,6 +7,7 @@
import pp.mdga.game.card.PowerCard; import pp.mdga.game.card.PowerCard;
import pp.mdga.message.client.RequestMoveMessage; import pp.mdga.message.client.RequestMoveMessage;
import pp.mdga.message.server.DrawCardMessage; import pp.mdga.message.server.DrawCardMessage;
import pp.mdga.message.server.IncorrectRequestMessage;
import pp.mdga.message.server.MoveMessage; import pp.mdga.message.server.MoveMessage;
import pp.mdga.message.server.StartPieceMessage; import pp.mdga.message.server.StartPieceMessage;
import pp.mdga.server.ServerGameLogic; import pp.mdga.server.ServerGameLogic;
@@ -70,13 +71,21 @@ public void received(RequestMoveMessage msg, int from) {
if (targetNode.isBonus()) { if (targetNode.isBonus()) {
logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes(); logic.getGame().getActivePlayer().getPlayerStatistic().increaseActivatedBonusNodes();
logic.getGame().getGameStatistics().increaseActivatedBonusNodes(); logic.getGame().getGameStatistics().increaseActivatedBonusNodes();
PowerCard cardToDraw = logic.getGame().draw();
for (Player p : logic.getGame().getPlayersAsList()) { for (Player p : logic.getGame().getPlayersAsList()) {
if (p.getColor() == logic.getGame().getActiveColor()) { if (p.getColor() == logic.getGame().getActiveColor()) {
PowerCard cardToDraw = logic.getGame().draw(); if (cardToDraw == null) {
p.addHandCard(cardToDraw); this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw)); } else {
p.addHandCard(cardToDraw);
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(cardToDraw));
}
} else { } else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard())); if (cardToDraw == null) {
this.logic.getServerSender().broadcast(new IncorrectRequestMessage(7));
} else {
logic.getServerSender().send(logic.getGame().getPlayerIdByColor(p.getColor()), new DrawCardMessage(new HiddenCard()));
}
} }
} }
} }

View File

@@ -7,6 +7,7 @@ incorrect.request.3=Selected to many or wrong pieces.
incorrect.request.4=Did not select exactly 2 pieces or selected wrong pieces. incorrect.request.4=Did not select exactly 2 pieces or selected wrong pieces.
incorrect.request.5=Cannot start game because not everyone is ready. incorrect.request.5=Cannot start game because not everyone is ready.
incorrect.request.6=You are alone in this Lobby. incorrect.request.6=You are alone in this Lobby.
incorrect.request.7=The draw pile is empty.

View File

@@ -7,3 +7,4 @@ incorrect.request.3=Du hast zuviele, oder eine falsche Figur ausgew
incorrect.request.4=Du hast nicht genau zwei Figuren, oder falsche Figuren ausgewählt. incorrect.request.4=Du hast nicht genau zwei Figuren, oder falsche Figuren ausgewählt.
incorrect.request.5=Du kannst das Spiel nicht starten, da nicht alle Spieler bereit sind. incorrect.request.5=Du kannst das Spiel nicht starten, da nicht alle Spieler bereit sind.
incorrect.request.6=Du bist alleine in dieser Lobby. incorrect.request.6=Du bist alleine in dieser Lobby.
incorrect.request.7=Der Nachziehstapel ist leer.