implemented all methods required for the state pattern in the client and adjusted the messages to work with player ids instead of names

This commit is contained in:
Fleischer Hanno
2024-11-26 20:04:58 +01:00
parent f827757ad1
commit 84c289cfd1
42 changed files with 582 additions and 125 deletions

View File

@@ -49,7 +49,7 @@ public class ClientStateTest {
private DetermineStartPlayerStateMachine determineStartPlayerStateMachine;
private Dialogs dialogs;
private DialogsStateMachine dialogsStateMachine;
private Game gameState;
private GameState gameState;
private GameStateMachine gameStateMachine;
private Interrupt interrupt;
private Lobby lobby;
@@ -193,7 +193,7 @@ public void send(ClientMessage msg) {
//initialize the states
dialogs = new Dialogs(clientAutomaton,clientGameLogic);
gameState = new Game(clientAutomaton,clientGameLogic);
gameState = new GameState(clientAutomaton,clientGameLogic);
ceremony = new Ceremony(clientAutomaton,clientGameLogic);
interrupt = new Interrupt(clientAutomaton,clientGameLogic,gameState);
@@ -257,10 +257,10 @@ public void testDialogsToGame() {
clientGameLogic.receive(startGame);
//tests if the client is in the gameState after receiving the message
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//tests if the new State of the GameStateMachine is in DetermineStartPlayer
Game gameState1 = (Game) clientAutomaton.getState();
GameState gameState1 = (GameState) clientAutomaton.getState();
GameStateMachine gameStateMachine1 = gameState1.getGameStateMachine();
assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayer);
@@ -286,7 +286,7 @@ public void testDialogsToClientStateEndState() {
public void testClientGameToCeremony() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the Ceremony-Message to the client
clientGameLogic.receive(ceremonyMessage);
@@ -309,7 +309,7 @@ public void testClientGameSubStatesToInterrupt() {
clientAutomaton.gotoState(gameState);
//tests if the client is in GameState
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the Ceremony-Message to the client
clientGameLogic.receive(interrupt);
@@ -352,7 +352,7 @@ public void testClientInterruptToGame() {
//Todo sends the continue-message
//tests if the client is in the game
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
}
/**
@@ -576,10 +576,10 @@ public void testLobbyToRollRankingDice() {
clientGameLogic.receive();//TODO message
//tests if the clientStateMachine is in the GameState
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//tests if the clientStateMachine is in the DetermineStartPlayer
Game gameState1 = (Game) clientAutomaton.getState();
GameState gameState1 = (GameState) clientAutomaton.getState();
GameStateMachine gameStateMachine1 = gameState1.getGameStateMachine();
assertTrue(gameStateMachine1.getState() instanceof DetermineStartPlayer);
@@ -604,7 +604,7 @@ public void testDetermineStartPlayerToWait() {
public void testWaitToAnimation() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the client in WaitState
gameStateMachine.gotoState(waiting);
@@ -612,7 +612,7 @@ public void testWaitToAnimation() {
//tests if a piece is moved,that the client goes into Animation
clientGameLogic.receive(moveMessage); //Todo ??? richtige message
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Animation);
//sends the client in WaitState
@@ -621,7 +621,7 @@ public void testWaitToAnimation() {
//tests if a powerCard is played,that the client goes into Animation
clientGameLogic.receive(playCardTurbo); //Todo ??? richtige message
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Animation);
//sends the client in WaitState
@@ -630,7 +630,7 @@ public void testWaitToAnimation() {
//tests if a die is rolled,that the client goes into Animation
clientGameLogic.receive(dice); //Todo ??? richtige message
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Animation);
}
@@ -641,7 +641,7 @@ public void testWaitToAnimation() {
public void testWaitToTurn() {
//sends client in gameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Waiting
gameStateMachine.gotoState(waiting);
@@ -651,7 +651,7 @@ public void testWaitToTurn() {
clientGameLogic.receive(activePlayer);
//tests if the client is in GameState
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//tests if Client is in Turn
assertTrue(gameStateMachine.getState() instanceof Turn);
@@ -728,7 +728,7 @@ public void testPowerCardSubStatesToRollDice() {
public void testStayInPlayPowerCard() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -741,7 +741,7 @@ public void testStayInPlayPowerCard() {
//Todo send messages to test to stay in playPowerCard
//tests if the client is in PlayPowerCard
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PlayPowerCard);
}
@@ -753,7 +753,7 @@ public void testStayInPlayPowerCard() {
public void testPlayPowerCardToRollDice() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -767,7 +767,7 @@ public void testPlayPowerCardToRollDice() {
//Todo test other messages, that there is no state change
//tests if the client is in RollDice
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof RollDice);
}
@@ -853,7 +853,7 @@ public void testChoosePowerCardToRollDice() {
//TODO
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -870,7 +870,7 @@ public void testChoosePowerCardToRollDice() {
//todo send the messages, to force a state change to rollDice
//tests if the turnStateMachine is in RollDice
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof RollDice);
}
@@ -882,7 +882,7 @@ public void testChoosePowerCardToRollDice() {
public void testChoosePowerCardToSwap() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -899,7 +899,7 @@ public void testChoosePowerCardToSwap() {
//todo send the messages, to force a state change to swap
//tests if the client is in Swap
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PowerCard);
assertTrue(powerCardStateMachine.getState() instanceof Swap);
@@ -912,7 +912,7 @@ public void testChoosePowerCardToSwap() {
public void testChoosePowerCardToShield() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -929,7 +929,7 @@ public void testChoosePowerCardToShield() {
//todo send the messages, to force a state change to shield
//tests if the client is in Shield
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PowerCard);
assertTrue(powerCardStateMachine.getState() instanceof Shield);
@@ -942,7 +942,7 @@ public void testChoosePowerCardToShield() {
public void testStayInShield() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -959,7 +959,7 @@ public void testStayInShield() {
//todo send the messages, which dont force a statechange
//tests if the client is in PlayPowerCard
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PowerCard);
assertTrue(powerCardStateMachine.getState() instanceof PlayPowerCard);
@@ -972,7 +972,7 @@ public void testStayInShield() {
public void testShieldToPowerCardEndState() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -990,7 +990,7 @@ public void testShieldToPowerCardEndState() {
//todo send the message to force the statechange
//tests if the client is in PlayPowerCard
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PlayPowerCard);
}
@@ -1002,7 +1002,7 @@ public void testShieldToPowerCardEndState() {
public void testSwapToPowerCardEndState() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1019,7 +1019,7 @@ public void testSwapToPowerCardEndState() {
//todo send the message to force the statechange
//tests if the client is in PlayPowerCard
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof PlayPowerCard);
}
@@ -1031,7 +1031,7 @@ public void testSwapToPowerCardEndState() {
public void testNoPieceInWaitingPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1050,7 +1050,7 @@ public void testNoPieceInWaitingPiece() {
//sends to the clientGameLogic the message WaitPiece
clientGameLogic.receive(waitPiece);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof WaitingPiece);
@@ -1063,7 +1063,7 @@ public void testNoPieceInWaitingPiece() {
public void testNoPieceInSelectedPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1082,7 +1082,7 @@ public void testNoPieceInSelectedPiece() {
//sends to the clientGameLogic the message SelectPiece
clientGameLogic.receive(selectPiece);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof SelectPiece);
@@ -1095,7 +1095,7 @@ public void testNoPieceInSelectedPiece() {
public void testNoPieceInStartPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1114,7 +1114,7 @@ public void testNoPieceInStartPiece() {
//sends to the clientGameLogic the message StartPiece
clientGameLogic.receive(startPiece);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof StartPiece);
@@ -1127,7 +1127,7 @@ public void testNoPieceInStartPiece() {
public void testNoPieceInWait() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1146,7 +1146,7 @@ public void testNoPieceInWait() {
//sends to the clientGameLogic the message NoTurn
clientGameLogic.receive(noTurn);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof Waiting);
}
@@ -1158,7 +1158,7 @@ public void testNoPieceInWait() {
public void testStayInWaitingPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1174,7 +1174,7 @@ public void testStayInWaitingPiece() {
//TODO send all sever-messages except ... to the clientGameLogic to test there are no state change
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof WaitingPiece);
@@ -1187,7 +1187,7 @@ public void testStayInWaitingPiece() {
public void testWaitingPieceInChoosePieceEndState() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1203,7 +1203,7 @@ public void testWaitingPieceInChoosePieceEndState() {
//Todo send the message to the clientGameLogic to force a state change
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof MovePiece);
}
@@ -1215,7 +1215,7 @@ public void testWaitingPieceInChoosePieceEndState() {
public void testStayInSelectedPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1231,7 +1231,7 @@ public void testStayInSelectedPiece() {
//Todo send all server messages which dont force a state change here
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof SelectPiece);
@@ -1244,7 +1244,7 @@ public void testStayInSelectedPiece() {
public void testSelectedPieceInChoosePieceEndState() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1260,7 +1260,7 @@ public void testSelectedPieceInChoosePieceEndState() {
//Todo send the message which force a state change
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof MovePiece);
}
@@ -1272,7 +1272,7 @@ public void testSelectedPieceInChoosePieceEndState() {
public void testStayInStartPiece() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1288,7 +1288,7 @@ public void testStayInStartPiece() {
//todo send all messages which dont force a state change
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof ChoosePiece);
assertTrue(choosePieceStateMachine.getState() instanceof StartPiece);
@@ -1301,7 +1301,7 @@ public void testStayInStartPiece() {
public void testStartPieceToChoosePieceEndState() {
//sends the ClientAutomaton in GameState
clientAutomaton.gotoState(gameState);
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
//sends the gameStateMachine in the Turn
gameStateMachine.gotoState(turn);
@@ -1317,7 +1317,7 @@ public void testStartPieceToChoosePieceEndState() {
//Todo send the message which force a state change
assertTrue(clientAutomaton.getState() instanceof Game);
assertTrue(clientAutomaton.getState() instanceof GameState);
assertTrue(gameStateMachine.getState() instanceof Turn);
assertTrue(turnStateMachine.getState() instanceof MovePiece);
}