added more logic to the client (choosepiece and powercard)

This commit is contained in:
Fleischer Hanno
2024-12-01 08:40:16 +01:00
parent 5ff56ed9d8
commit bdc527b83e
12 changed files with 133 additions and 25 deletions

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

@@ -2,9 +2,39 @@
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;
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());
}
}

View File

@@ -75,24 +75,7 @@ public void received(DieMessage msg){
@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);
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,9 @@
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 pp.mdga.notification.SelectableMoveNotification;
import java.util.ArrayList;
@@ -42,6 +45,12 @@ 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()));
} else {
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

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