fixed state transitions and implemented the Intro state to move the pieces to the correct start setup

added some logic so that the client only transitions to the intro state when the animation has finished at it received the new active Player, and after animating the setup it switches to the corresponding state baserd on  the active player and displays the now new active player.
This commit is contained in:
Hanno Fleischer
2024-12-05 14:02:02 +01:00
parent 3b0cd9ebdb
commit 0622c35303
11 changed files with 45 additions and 17 deletions

View File

@@ -152,7 +152,7 @@ public boolean isHost() {
* @return the calculated moves as int
*/
public int getCalculatedMoves() {
return game.getDiceEyes() * game.getDiceModifier();
return 0;
}
/**

View File

@@ -7,6 +7,8 @@
import pp.mdga.client.gamestate.determinestartplayerstate.Intro;
import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState;
import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.DieMessage;
import pp.mdga.message.server.RankingResponseMessage;
import pp.mdga.message.server.RankingRollAgainMessage;
@@ -68,6 +70,11 @@ public void selectDice() {
state.selectDice();
}
@Override
public void selectAnimationEnd(){
state.selectAnimationEnd();
}
@Override
public void received(DieMessage msg){
state.received(msg);
@@ -82,4 +89,9 @@ public void received(RankingRollAgainMessage msg){
public void received(RankingResponseMessage msg){
state.received(msg);
}
@Override
public void received(ActivePlayerMessage msg){
state.received(msg);
}
}

View File

@@ -19,7 +19,7 @@ public GameStates(ClientState parent, ClientGameLogic logic) {
protected void handlePowerCard(PlayCardMessage msg) {
if (msg.getCard().equals(BonusCard.TURBO)) {
logic.getGame().setDiceModifier(msg.getDiceModifier());
//logic.getGame().setDiceModifier(msg.getDiceModifier());
} else if (msg.getCard().equals(BonusCard.SHIELD)) {
if (logic.getGame().getBoard().getInfieldIndexOfPiece(logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier())) % 10 != 0) {
logic.getGame().getPieceThroughUUID(msg.getPieceIdentifier()).setShield(ShieldState.SUPPRESSED);

View File

@@ -36,7 +36,7 @@ public void received(CeremonyMessage msg) {
@Override
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 (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();

View File

@@ -40,7 +40,7 @@ public void received(DiceNowMessage msg) {
@Override
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 (msg.getDiceEye() == 6) {
logic.getGame().getPlayerByColor(logic.getGame().getActiveColor()).getPlayerStatistic().increaseDiced6();

View File

@@ -5,9 +5,7 @@
import pp.mdga.client.gamestate.DetermineStartPlayerState;
import pp.mdga.game.Player;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.notification.AcquireCardNotification;
import pp.mdga.notification.DrawCardNotification;
import pp.mdga.notification.WaitMoveNotification;
import pp.mdga.notification.MovePieceNotification;
import java.util.Map;
@@ -43,12 +41,13 @@ public DetermineStartPlayerState getParent(){
@Override
public void enter() {
for(Map.Entry<Integer, Player> entry : logic.getGame().getPlayers().entrySet()){
logic.addNotification(new WaitMoveNotification(entry.getValue().getPieces()[0].getUuid()));
//logic.addNotification(new WaitMoveNotification(entry.getValue().getPieces()[0].getUuid()));
logic.addNotification(new MovePieceNotification(entry.getValue().getPieces()[0].getUuid(), entry.getValue().getStartNodeIndex(), true));
animationCounter++;
if(entry.getKey() == logic.getOwnPlayerId()){
logic.addNotification(new AcquireCardNotification(entry.getValue().getHandCards().get(0)));
//logic.addNotification(new AcquireCardNotification(entry.getValue().getHandCards().get(0)));
} else {
logic.addNotification(new DrawCardNotification(entry.getValue().getColor(), entry.getValue().getHandCards().get(0)));
//logic.addNotification(new DrawCardNotification(entry.getValue().getColor(), entry.getValue().getHandCards().get(0)));
}
}
}
@@ -66,6 +65,7 @@ public void exit() {
*/
@Override
public void selectAnimationEnd(){
System.out.println("selectAnimationEnd");
animationCounter--;
if(animationCounter != 0){
return;

View File

@@ -28,13 +28,12 @@ public void exit() {
@Override
public void selectDice(){
System.out.println("selectDice");
logic.send(new RequestDieMessage());
}
@Override
public void received(DieMessage msg){
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
parent.setState(parent.getWaitRanking());
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
}
}

View File

@@ -3,6 +3,7 @@
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientState;
import pp.mdga.client.gamestate.DetermineStartPlayerState;
import pp.mdga.message.client.AnimationEndMessage;
import pp.mdga.message.server.ActivePlayerMessage;
import pp.mdga.message.server.RankingResponseMessage;
import pp.mdga.message.server.RankingRollAgainMessage;
@@ -11,6 +12,7 @@
public class WaitRankingState extends DetermineStartPlayerStates {
private final DetermineStartPlayerState parent;
private boolean canTransition = false;
public WaitRankingState(ClientState parent, ClientGameLogic logic) {
super(parent, logic);
@@ -19,7 +21,6 @@ public WaitRankingState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
}
@Override
@@ -36,10 +37,25 @@ public void received(RankingRollAgainMessage msg){
public void received(RankingResponseMessage msg){
}
@Override
public void selectAnimationEnd(){
logic.send(new AnimationEndMessage());
changeToIntro();
}
@Override
public void received(ActivePlayerMessage msg){
logic.addNotification(new ActivePlayerNotification(msg.getColor()));
logic.getGame().setActiveColor(msg.getColor());
changeToIntro();
}
private void changeToIntro(){
if (!canTransition){
canTransition = true;
return;
}
parent.setState(parent.getIntro());
}
}

View File

@@ -22,7 +22,7 @@ public void enter() {
@Override
public void exit() {
logic.getGame().setDiceModifier(1);
//logic.getGame().setDiceModifier(1);
}
public TurnState getParent() {
@@ -30,7 +30,7 @@ public TurnState getParent() {
}
public void received(DieMessage msg){
logic.getGame().setDiceEyes(msg.getDiceEye());
// logic.getGame().setDiceEyes(msg.getDiceEye());
parent.setState(parent.getChoosePiece());
}

View File

@@ -39,7 +39,7 @@ public ChoosePowerCardState(ClientState parent, ClientGameLogic logic) {
@Override
public void enter() {
possibleCards = new ArrayList<>();
//TODO: logic.send(new RequestPossibleCardsMessage());
System.out.println("ChoosePowerCardState");
}
/**
@@ -80,7 +80,7 @@ public void selectCard(BonusCard card){
@Override
public void received(PlayCardMessage msg){
if(msg.getCard().equals(BonusCard.TURBO)){
logic.getGame().setDiceModifier(msg.getDiceModifier());
//logic.getGame().setDiceModifier(msg.getDiceModifier());
} else {
LOGGER.log(System.Logger.Level.ERROR, "Received card that is not turbo");
}

View File

@@ -85,6 +85,7 @@ public void initialize() {
this.pieces[index] = new Piece(this.color, PieceState.WAITING);
this.waitingArea[index] = this.pieces[index];
}
startNodeIndex = color.ordinal() * 10;
}
/**