This commit is contained in:
Cedric Beck
2024-12-02 17:12:00 +01:00
9 changed files with 33 additions and 23 deletions

View File

@@ -18,7 +18,7 @@ public CeremonyState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
currentState = podiumState; setState(podiumState);
logic.addNotification(createCeremonyNotification()); logic.addNotification(createCeremonyNotification());
} }
@@ -28,7 +28,9 @@ public void exit() {
} }
public void setState(CeremonyStates state){ public void setState(CeremonyStates state){
if(this.currentState != null){
this.currentState.exit(); this.currentState.exit();
}
state.enter(); state.enter();
currentState = state; currentState = state;
} }

View File

@@ -30,13 +30,15 @@ public void exit(){
@Override @Override
public void enter(){ public void enter(){
currentState = startDialogState; setState(startDialogState);
ownPlayerID = 0; ownPlayerID = 0;
ownPlayerName = null; ownPlayerName = null;
} }
public void setState(DialogStates newState){ public void setState(DialogStates newState){
if(currentState != null){
currentState.exit(); currentState.exit();
}
newState.enter(); newState.enter();
currentState = newState; currentState = newState;
} }
@@ -69,11 +71,6 @@ public StartDialogState getStartDialog() {
return startDialogState; return startDialogState;
} }
public void startGame(){
exit();
logic.setState(logic.getGameState());
}
@Override @Override
public void selectLeave(){ public void selectLeave(){
currentState.selectLeave(); currentState.selectLeave();

View File

@@ -27,7 +27,6 @@ public class GameState extends ClientState {
*/ */
public GameState(ClientState parent, ClientGameLogic logic) { public GameState(ClientState parent, ClientGameLogic logic) {
super(parent, logic); super(parent, logic);
state = determineStartPlayerState;
} }
/** /**
@@ -35,7 +34,7 @@ public GameState(ClientState parent, ClientGameLogic logic) {
*/ */
@Override @Override
public void enter() { public void enter() {
this.setState(this.determineStartPlayerState);
} }
/** /**
@@ -52,8 +51,10 @@ public void exit() {
* @param newState the state to be set * @param newState the state to be set
*/ */
public void setState(GameStates newState){ public void setState(GameStates newState){
state.exit(); if(this.state != null){
state.enter(); this.state.exit();
}
newState.enter();
state = newState; state = newState;
} }

View File

@@ -95,7 +95,7 @@ public void received(ServerStartGameMessage msg){
} }
logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceList , logic.getGame().getPlayerByColor(entry.getKey()).getName())); logic.addNotification(new PlayerInGameNotification(entry.getKey(), pieceList , logic.getGame().getPlayerByColor(entry.getKey()).getName()));
} }
parent.startGame(); logic.setState(logic.getGameState());
} }
@Override @Override

View File

@@ -34,7 +34,9 @@ public void exit() {
} }
public void setState(DetermineStartPlayerStates state) { public void setState(DetermineStartPlayerStates state) {
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }

View File

@@ -31,7 +31,7 @@ public TurnState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
state = powerCardState; this.setState(this.powerCardState);
} }
@Override @Override
@@ -40,7 +40,9 @@ public void exit() {
} }
public void setState(TurnStates state){ public void setState(TurnStates state){
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }

View File

@@ -6,6 +6,7 @@
import pp.mdga.message.client.RequestDieMessage; import pp.mdga.message.client.RequestDieMessage;
import pp.mdga.message.server.DieMessage; import pp.mdga.message.server.DieMessage;
import pp.mdga.notification.DiceNowNotification; import pp.mdga.notification.DiceNowNotification;
import pp.mdga.notification.RollDiceNotification;
public class RollRankingDiceState extends DetermineStartPlayerStates { public class RollRankingDiceState extends DetermineStartPlayerStates {
@@ -23,16 +24,17 @@ public void enter() {
@Override @Override
public void exit() { public void exit() {
} }
@Override @Override
public void selectDice(){ public void selectDice(){
System.out.println("selectDice");
logic.send(new RequestDieMessage()); logic.send(new RequestDieMessage());
} }
@Override @Override
public void received(DieMessage msg){ public void received(DieMessage msg){
logic.addNotification(new RollDiceNotification(logic.getGame().getPlayerById(logic.getDialogs().getOwnPlayerId()).getColor(), msg.getDiceEye(),true));
parent.setState(parent.getWaitRanking()); parent.setState(parent.getWaitRanking());
} }
} }

View File

@@ -24,7 +24,7 @@ public ChoosePieceState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
currentState = noPieceState; this.setState(this.noPieceState);
} }
@Override @Override
@@ -34,9 +34,11 @@ public void exit() {
} }
public void setState(ChoosePieceStates state){ public void setState(ChoosePieceStates state){
if(currentState != null){
currentState.exit(); currentState.exit();
}
state.enter();
currentState = state; currentState = state;
currentState.enter();
} }
@Override @Override

View File

@@ -31,7 +31,7 @@ public PowerCardState(ClientState parent, ClientGameLogic logic) {
@Override @Override
public void enter() { public void enter() {
state = choosePowerCardState; this.setState(this.choosePowerCardState);
} }
public void exit() { public void exit() {
@@ -40,7 +40,9 @@ public void exit() {
} }
public void setState(PowerCardStates state) { public void setState(PowerCardStates state) {
if(this.state != null){
this.state.exit(); this.state.exit();
}
state.enter(); state.enter();
this.state = state; this.state = state;
} }