Merge branch 'development' into 'dev/test'

merge development int test branch

See merge request progproj/gruppen-ht24/Gruppe-01!23
This commit is contained in:
Benjamin Feyer
2024-12-01 11:10:24 +00:00
17 changed files with 212 additions and 65 deletions

View File

@@ -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

View File

@@ -66,6 +66,10 @@ public boolean isHost(){
return isHost;
}
public int getCalculatedMoves(){
return game.getDiceEyes() * game.getDiceModifier();
}
public void setHost(boolean isHost){
this.isHost = isHost;
}

View File

@@ -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;
}
}

View File

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

View File

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

View File

@@ -2,9 +2,48 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece;
import pp.mdga.game.ShieldState;
import pp.mdga.message.server.PlayCardMessage;
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) {
super(parent, logic);
}
protected void handlePowerCard(PlayCardMessage msg){
if (msg.getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().equals(BonusCard.SHIELD)){
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid()));
} else {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid()));
}
} else {
Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier());
Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy());
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);
logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece);
}
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();
}
}

View File

@@ -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,30 +44,19 @@ 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());
}
@Override
public void received(PlayCardMessage msg){
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor(), msg.getCard()));
if (msg.getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().equals(BonusCard.SHIELD)){
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier())) % 10 != 0) {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);
logic.addNotification(new ShieldSuppressedNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid()));
} else {
logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).setShield(ShieldState.ACTIVE);
logic.addNotification(new ShieldActiveNotification(logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier()).getUuid()));
}
} else {
Piece ownPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier());
Piece enemyPiece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifierEnemy());
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);
logic.getGame().getBoard().getInfield()[ownIndex].setOccupant(enemyPiece);
}
handlePowerCard(msg);
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseCardsPlayed();
logic.getGame().getGameStatistics().increaseCardsPlayed();
parent.setState(parent.getAnimation());
}
@@ -106,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());
}

View File

@@ -3,6 +3,7 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.gameState.TurnState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.*;
public class MovePieceState extends TurnStates {
@@ -24,6 +25,11 @@ public void exit() {
}
@Override
public void selectAnimationEnd(){
logic.send(new AnimationEndMessage());
}
@Override
public void received(CeremonyMessage msg){
logic.setState(logic.getCeremony());

View File

@@ -3,9 +3,15 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.gameState.TurnState;
import pp.mdga.game.BonusCard;
import pp.mdga.game.Piece;
import pp.mdga.game.ShieldState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.PlayCardNotification;
import pp.mdga.notification.ShieldActiveNotification;
import pp.mdga.notification.ShieldSuppressedNotification;
import pp.mdga.notification.SwapPieceNotification;
public class PlayPowerCardState extends TurnStates {
@@ -20,7 +26,8 @@ public PlayPowerCardState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
logic.addNotification(new PlayCardNotification(null , playCardMessage.getCard())); //TODO: get color
logic.addNotification(new PlayCardNotification(logic.getGame().getActiveColor() , playCardMessage.getCard()));
handlePowerCard(playCardMessage);
}
@Override

View File

@@ -3,8 +3,12 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.gameState.turnState.ChoosePieceState;
import pp.mdga.game.Piece;
import pp.mdga.message.server.*;
import pp.mdga.message.server.StartPieceMessage;
import pp.mdga.notification.MovePieceNotification;
import pp.mdga.notification.SelectableMoveNotification;
import pp.mdga.notification.WaitMoveNotification;
import java.util.ArrayList;
import java.util.stream.Collectors;
@@ -31,16 +35,21 @@ public void exit() {
@Override
public void received(SelectPieceMessage msg) {
parent.setState(parent.getSelectPiece());
parent.getSelectPiece().setPossiblePieces(msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
ArrayList<Piece> pieces = msg.getPieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new));
parent.getSelectPiece().setPossiblePieces(pieces);
logic.addNotification(new SelectableMoveNotification(pieces.stream().map(Piece::getUuid).collect(Collectors.toCollection(ArrayList::new)), msg.getTargetIndex(), msg.getIsHomeMove()));
}
@Override
public void received(WaitPieceMessage msg){
logic.addNotification(new WaitMoveNotification(msg.getPieceID()));
parent.setState(parent.getWaitingPiece());
}
@Override
public void received(StartPieceMessage msg){
Piece piece = logic.getGame().getPieceThroughIdentifier(msg.getPieceIdentifier());
//TODO: logic.addNotification(null);
parent.setState(parent.getStartPiece());
}

View File

@@ -6,6 +6,8 @@
import pp.mdga.game.Piece;
import pp.mdga.message.client.SelectedPiecesMessage;
import pp.mdga.message.server.MoveMessage;
import pp.mdga.notification.HomeMoveNotification;
import pp.mdga.notification.MovePieceNotification;
import java.util.ArrayList;
@@ -42,6 +44,19 @@ public void selectPiece(Piece piece){
@Override
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());
}
}

View File

@@ -7,8 +7,10 @@
import pp.mdga.message.client.NoPowerCardMessage;
import pp.mdga.message.client.SelectCardMessage;
import pp.mdga.message.server.DiceNowMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.message.server.PossibleCardMessage;
import pp.mdga.message.server.PossiblePieceMessage;
import pp.mdga.notification.SelectableCardsNotification;
import java.util.ArrayList;
import java.util.stream.Collectors;
@@ -36,6 +38,7 @@ public void exit() {
@Override
public void received(PossibleCardMessage msg){
possibleCards = (ArrayList<BonusCard>) msg.getPossibleCards();
logic.addNotification(new SelectableCardsNotification(possibleCards));
}
@Override
@@ -47,6 +50,15 @@ public void selectCard(BonusCard card){
}
}
@Override
public void received(PlayCardMessage msg){
if(msg.getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier());
} else {
LOGGER.log(System.Logger.Level.ERROR, "Received card that is not turbo");
}
}
@Override
public void received(DiceNowMessage msg){
parent.getParent().setState(parent.getParent().getRollDice());
@@ -55,12 +67,12 @@ public void received(DiceNowMessage msg){
@Override
public void received(PossiblePieceMessage msg){
if (msg.getEnemyPossiblePieces().isEmpty()){
parent.setState(parent.getShield());
parent.getShield().setPossiblePieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getShield());
} else {
parent.setState(parent.getSwap());
parent.getSwap().setPossibleOwnPieces(msg.getOwnPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.getSwap().setPossibleEnemyPieces(msg.getEnemyPossiblePieces().stream().map(piece -> logic.getGame().getPieceThroughIdentifier(piece)).collect(Collectors.toCollection(ArrayList::new)));
parent.setState(parent.getSwap());
}
}
}

View File

@@ -19,11 +19,13 @@ public class ShieldState extends PowerCardStates {
public ShieldState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
this.parent = (PowerCardState) parent;
possiblePieces = new ArrayList<>();
}
@Override
public void enter() {
possiblePieces = new ArrayList<>();
logic.addNotification(null);
//TODO: selectable piece notification
}
@Override

View File

@@ -6,7 +6,9 @@
import pp.mdga.game.Piece;
import pp.mdga.message.client.RequestPlayCardMessage;
import pp.mdga.message.server.PlayCardMessage;
import pp.mdga.notification.SelectableSwapNotification;
import java.util.UUID;
import java.util.ArrayList;
public class SwapState extends PowerCardStates {
@@ -21,12 +23,15 @@ public class SwapState extends PowerCardStates {
public SwapState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
this.parent = (PowerCardState) parent;
possibleOwnPieces = new ArrayList<>();
possibleEnemyPieces = new ArrayList<>();
}
@Override
public void enter() {
possibleOwnPieces = new ArrayList<>();
possibleEnemyPieces = new ArrayList<>();
ArrayList<UUID> ownPieces = new ArrayList<>(possibleOwnPieces.stream().map(Piece::getUuid).toList());
ArrayList<UUID> enemyPieces = new ArrayList<>(possibleEnemyPieces.stream().map(Piece::getUuid).toList());
logic.addNotification(new SelectableSwapNotification(ownPieces, enemyPieces));
}
@Override

View File

@@ -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.
*/

View File

@@ -42,6 +42,24 @@ public List<String> getPieces(){
return pieces;
}
/**
* returns if a move is a home move for an index
*
* @return List of boolean values
*/
public List<Boolean> getIsHomeMove(){
return isHomeMove;
}
/**
* returns the target index of the pieces
*
* @return List of integers
*/
public List<Integer> getTargetIndex(){
return targetIndex;
}
/**
* Accepts a visitor to process this message.
*

View File

@@ -2,16 +2,39 @@
import com.jme3.network.serializing.Serializable;
import java.util.UUID;
/**
* A message sent by the server to the active player to choose a piece from the waiting area.
*/
@Serializable
public class WaitPieceMessage extends ServerMessage {
private final UUID pieceID;
/**
* Constructs a new WaitPiece instance.
*/
public WaitPieceMessage(UUID pieceID) {
super();
this.pieceID = pieceID;
}
/**
* Constructs a new WaitPiece instance.
*/
public WaitPieceMessage() {
super();
this.pieceID = null;
}
/**
* Getter for the pieceID
*
* @return the pieceID
*/
public UUID getPieceID() {
return pieceID;
}
/**