fixed and added some tests

This commit is contained in:
Benjamin Feyer
2024-12-12 15:01:57 +01:00
parent 0d4685f3c2
commit 48d6516073
3 changed files with 102 additions and 95 deletions

View File

@@ -12,6 +12,7 @@
import pp.mdga.server.automaton.game.turn.ChoosePieceState;
import java.util.ArrayList;
import java.util.List;
public class SelectPieceState extends ChoosePieceAutomatonState {
/**
@@ -20,8 +21,8 @@ public class SelectPieceState extends ChoosePieceAutomatonState {
private static final System.Logger LOGGER = System.getLogger(SelectPieceState.class.getName());
private ArrayList<Piece> moveablePieces = new ArrayList<>();
private final ArrayList<Boolean> isHomeMove = new ArrayList<>();
private final ArrayList<Integer> targetIndex = new ArrayList<>();
private ArrayList<Boolean> isHomeMove = new ArrayList<>();
private ArrayList<Integer> targetIndex = new ArrayList<>();
/**
* Constructs a server state of the specified game logic.
@@ -178,4 +179,22 @@ public void exit() {
public ArrayList<Piece> getMoveablePieces() {
return moveablePieces;
}
/**
* this method is used to set the isHomeMoveIndex
*
* @param list to be set
*/
public void setIsHomeMove(ArrayList<Boolean> list){
this.isHomeMove=list;
}
/**
* this method is used to set the targetIndex
*
* @param list to be set
*/
public void setTargetIndex(ArrayList<Integer> list){
this.targetIndex=list;
}
}

View File

@@ -1,9 +1,18 @@
package pp.mdga.client.clientState;
import org.junit.*;
import pp.mdga.client.*;
import pp.mdga.client.ceremonystate.*;
import pp.mdga.client.dialogstate.*;
import org.junit.Before;
import org.junit.Test;
import pp.mdga.client.CeremonyState;
import pp.mdga.client.ClientGameLogic;
import pp.mdga.client.ClientSender;
import pp.mdga.client.DialogsState;
import pp.mdga.client.GameState;
import pp.mdga.client.InterruptState;
import pp.mdga.client.ceremonystate.PodiumState;
import pp.mdga.client.ceremonystate.StatisticsState;
import pp.mdga.client.dialogstate.LobbyState;
import pp.mdga.client.dialogstate.NetworkDialogState;
import pp.mdga.client.dialogstate.StartDialogState;
import pp.mdga.client.gamestate.AnimationState;
import pp.mdga.client.gamestate.DetermineStartPlayerState;
import pp.mdga.client.gamestate.SpectatorState;
@@ -11,28 +20,21 @@
import pp.mdga.client.gamestate.WaitingState;
import pp.mdga.client.gamestate.determinestartplayerstate.RollRankingDiceState;
import pp.mdga.client.gamestate.determinestartplayerstate.WaitRankingState;
import pp.mdga.client.gamestate.turnstate.ChoosePieceState;
import pp.mdga.client.gamestate.turnstate.MovePieceState;
import pp.mdga.client.gamestate.turnstate.*;
import pp.mdga.client.gamestate.turnstate.choosepiecestate.*;
import pp.mdga.client.gamestate.turnstate.powercardstate.*;
import pp.mdga.game.Game;
import pp.mdga.game.Piece;
import pp.mdga.game.PieceState;
import pp.mdga.game.Player;
import pp.mdga.game.card.PowerCard;
import pp.mdga.game.card.ShieldCard;
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import pp.mdga.message.server.*;
import pp.mdga.game.Color;
import pp.mdga.client.gamestate.turnstate.powercardstate.ShieldState;
import pp.mdga.game.*;
import pp.mdga.game.card.*;
import pp.mdga.message.client.ClientMessage;
import pp.mdga.visitor.Visitor;
import pp.mdga.message.server.*;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* this test-class tests the testcases T170-T239
@@ -75,7 +77,6 @@ public class ClientStateTest {
private WaitingState waiting;
private WaitingPieceState waitingPiece;
private WaitRankingState waitRanking;
//private todo
//declare server-messages here
private ShutdownMessage shutdownMessage;
@@ -131,7 +132,7 @@ public class ClientStateTest {
private Piece ownPiece;
//declare enemy piece
private Piece enemyPiece ;
private Piece enemyPiece;
@Before
public void setUp() {
@@ -155,23 +156,18 @@ public void send(ClientMessage msg) {
player = new Player(name);
player.setColor(color);
player.initialize();
game.addPlayer(1234,player);
game.addPlayer(1234, player);
game.setActiveColor(color);
ownPiece = player.getWaitingPiece();
ownPiece.setState(PieceState.ACTIVE);
player.removeWaitingPiece(ownPiece);
game.getBoard().setPieceOnBoard(22,ownPiece);
game.getBoard().setPieceOnBoard(22, ownPiece);
//todo piece
swapCard= new SwapCard();
swapCard = new SwapCard();
shieldCard = new ShieldCard();
turboCard = new TurboCard();
player.addHandCard(turboCard);
player.addHandCard(swapCard);
player.addHandCard(shieldCard);
@@ -179,24 +175,23 @@ public void send(ClientMessage msg) {
//declare ownPlayer
//declare other player
enemy= new Player(name);
enemy = new Player(name);
enemy.setColor(Color.CYBER);
enemyColor=Color.CYBER;
game.addPlayer(2345,enemy);
enemyColor = Color.CYBER;
game.addPlayer(2345, enemy);
enemy.initialize();
enemyPiece = enemy.getWaitingPiece();
enemyPiece.setState(PieceState.ACTIVE);
enemy.removeWaitingPiece(enemyPiece);
game.getBoard().setPieceOnBoard(33,enemyPiece);
game.getBoard().setPieceOnBoard(33, enemyPiece);
//sets the player in the game
clientGameLogic.getGame().addPlayer(0,player);
clientGameLogic.getGame().addPlayer(1,enemy);
clientGameLogic.getGame().getBoard().setPieceOnBoard(15,ownPiece);
clientGameLogic.getGame().getBoard().setPieceOnBoard(25,enemyPiece);
clientGameLogic.getGame().addPlayer(0, player);
clientGameLogic.getGame().addPlayer(1, enemy);
clientGameLogic.getGame().getBoard().setPieceOnBoard(15, ownPiece);
clientGameLogic.getGame().getBoard().setPieceOnBoard(25, enemyPiece);
//initialize the messages from the server
shutdownMessage = new ShutdownMessage();
@@ -210,31 +205,30 @@ public void send(ClientMessage msg) {
endOfTurn = new EndOfTurnMessage();
lobbyAccept = new LobbyAcceptMessage();
lobbyDeny = new LobbyDenyMessage();
lobbyPlayerJoin = new LobbyPlayerJoinedMessage(from, player,true);
lobbyPlayerJoin = new LobbyPlayerJoinedMessage(from, player, true);
lobbyPlayerLeave = new LobbyPlayerLeaveMessage(from);
moveMessage = new MoveMessage(ownPiece, false, 25);
noTurn = new NoTurnMessage();
interruptMessage = new PauseGameMessage();
playCardSwap = new PlayCardMessage(swapCard, new ArrayList<>(List.of(ownPiece, enemyPiece)), 1); //TODO
playCardSwap = new PlayCardMessage(swapCard, new ArrayList<>(List.of(ownPiece, enemyPiece)), 1);
playCardShield = new PlayCardMessage(shieldCard, new ArrayList<>(List.of(ownPiece)), 1);
playCardTurbo = new PlayCardMessage(turboCard, new ArrayList<>(List.of(ownPiece)),1);
possibleCard = new PossibleCardsMessage(new ArrayList<>(List.of(swapCard,shieldCard,turboCard)));
possiblePieceShield = PossiblePieceMessage.shieldPossiblePieces(new ArrayList<>(List.of(ownPiece))); //TODO
possiblePieceSwap = PossiblePieceMessage.swapPossiblePieces(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(enemyPiece))); //TODO
//todo possiblePieceSwap = new PossiblePieceMessage(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(enemyPiece)));
playCardTurbo = new PlayCardMessage(turboCard, new ArrayList<>(List.of(ownPiece)), 1);
possibleCard = new PossibleCardsMessage(new ArrayList<>(List.of(swapCard, shieldCard, turboCard)));
possiblePieceShield = PossiblePieceMessage.shieldPossiblePieces(new ArrayList<>(List.of(ownPiece)));
possiblePieceSwap = PossiblePieceMessage.swapPossiblePieces(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(enemyPiece)));
possiblePiece = new PossiblePieceMessage();
rankingResponse = new RankingResponseMessage();
rankingRollAgain = new RankingRollAgainMessage();
reconnectBriefing = new ReconnectBriefingMessage(game);
resumeGame = new ResumeGameMessage();
startGame = new ServerStartGameMessage();
startPieceMessage = new StartPieceMessage(ownPiece.getUuid(),25);
startPieceMessage = new StartPieceMessage(ownPiece.getUuid(), 25);
updateReady = new UpdateReadyMessage(2345, true);
updateTSK = new UpdateTSKMessage(2345, Color.NAVY,false);
updateTSK = new UpdateTSKMessage(2345, Color.NAVY, false);
waitPiece = new WaitPieceMessage(ownPiece.getUuid());
interruptMessage = new PauseGameMessage();
spectatorMessage = new SpectatorMessage();
selectPieceMessage = new SelectPieceMessage(new ArrayList<>(List.of(ownPiece)),new ArrayList<>(List.of(false)), new ArrayList<>(List.of(25)));
selectPieceMessage = new SelectPieceMessage(new ArrayList<>(List.of(ownPiece)), new ArrayList<>(List.of(false)), new ArrayList<>(List.of(25)));
//initialize the client-state
//sets the clientGameLogic-states
@@ -322,10 +316,7 @@ public void testDialogsToGame() {
clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing);
clientGameLogic.received(resumeGame);
//clientGameLogic.received(startGame);
clientGameLogic.received(startPieceMessage);
//clientGameLogic.received(updateReady);
//clientGameLogic.received(updateTSK);
clientGameLogic.received(waitPiece);
clientGameLogic.received(spectatorMessage);
clientGameLogic.received(selectPieceMessage);
@@ -401,7 +392,6 @@ public void testClientGameToCeremony() {
clientGameLogic.received(ceremonyMessage);
//tests if the client is in the ceremony after receiving the message
System.out.println(clientGameLogic.getState());
assertEquals(clientGameLogic.getState(), ceremony);
//tests if the state of ceremony is Podium
@@ -473,7 +463,6 @@ public void testStayInInterrupt() {
clientGameLogic.received(rankingResponse);
clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing);
//clientGameLogic.received(resumeGame); commented out, because it indicates a state-change to gameState
clientGameLogic.received(startGame);
clientGameLogic.received(startPieceMessage);
clientGameLogic.received(updateReady);
@@ -634,15 +623,13 @@ public void testNetworkDialogToNetworkDialog1() {
assertEquals(dialogs.getState(), networkDialog);
//simulate all input, that don't indicate a state-change
clientGameLogic.selectPiece(null); //TODO
clientGameLogic.selectPiece(null);
clientGameLogic.selectCard(null);
clientGameLogic.selectTsk(color);
clientGameLogic.selectDice();
clientGameLogic.selectName(name);
clientGameLogic.selectReady(true);
clientGameLogic.selectHost(name);
//clientGameLogic.selectLeave(); commented because it indicate a state-change to start-dialog
//clientGameLogic.selectJoin(name); commented because it indicate a state-change to lobby
clientGameLogic.selectAnimationEnd();
clientGameLogic.selectStart();
@@ -673,7 +660,7 @@ public void testNetworkDialogToLobby() {
//simulate connect to server with send lobby request
clientGameLogic.selectJoin("IP");
clientGameLogic.received(new LobbyAcceptMessage(1234) );
clientGameLogic.received(new LobbyAcceptMessage(1234));
assertEquals(clientGameLogic.getState(), dialogs);
assertEquals(dialogs.getState(), lobby);
@@ -714,17 +701,15 @@ public void testStayInLobby() {
assertEquals(dialogs.getState(), lobby);
//simulate all input that don't indicate a state-change
clientGameLogic.selectPiece(null); //TODO
clientGameLogic.selectPiece(null);
clientGameLogic.selectCard(null);
clientGameLogic.selectTsk(color);
clientGameLogic.selectDice();
clientGameLogic.selectName(name);
clientGameLogic.selectReady(true);
clientGameLogic.selectHost(name);
//clientGameLogic.selectLeave(); commented because it indicate a state-change to start-dialog
clientGameLogic.selectJoin(name);
clientGameLogic.selectAnimationEnd();
//clientGameLogic.selectStart(); commented because it indicate a state-change to determineStartPlayer if host
//sends all messages, which don't indicate a statechange
clientGameLogic.received(activePlayer);
@@ -751,7 +736,6 @@ public void testStayInLobby() {
clientGameLogic.received(rankingRollAgain);
clientGameLogic.received(reconnectBriefing);
clientGameLogic.received(resumeGame);
//clientGameLogic.received(startGame); commented because it indicate a state-change to determineStartPlayer
clientGameLogic.received(startPieceMessage);
clientGameLogic.received(updateReady);
clientGameLogic.received(updateTSK);
@@ -813,14 +797,12 @@ public void testDetermineStartPlayerToWait() {
//tests if the client is in the intro
assertEquals(clientGameLogic.getState(), gameState);
assertEquals(gameState.getState(), determineStartPlayer);
assertEquals(determineStartPlayer.getState(),determineStartPlayer.getIntro());
assertEquals(determineStartPlayer.getState(), determineStartPlayer.getIntro());
int animationCounter = determineStartPlayer.getIntro().getAnimationCounter();
System.out.println(animationCounter);
for(int i =0; i<animationCounter; i++){
for (int i = 0; i < animationCounter; i++) {
clientGameLogic.selectAnimationEnd();
}
System.out.println(determineStartPlayer.getIntro().getAnimationCounter());
//tests if the client is in the Wait-State
assertEquals(clientGameLogic.getState(), gameState);
@@ -851,7 +833,7 @@ public void testWaitToAnimation() {
gameState.setState(waiting);
assertEquals(gameState.getState(), waiting);
//sends the playTurboCard-message todo
//sends the playTurboCard-message
clientGameLogic.received(playCardTurbo);
//tests if a powerCard is played,that the client goes into Animation
@@ -942,18 +924,14 @@ public void testTurnSubStatesToGameEndState() {
clientGameLogic.received(activePlayer);
clientGameLogic.received(anyPiece);
clientGameLogic.received(briefing);
//clientGameLogic.received(ceremonyMessage); commented because it indicate a state-change to ceremony-state
clientGameLogic.received(die);
clientGameLogic.received(diceAgain);
//clientGameLogic.received(diceNow); commented because it indicate a state-change to rollDice-state
//clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state
clientGameLogic.received(lobbyAccept);
clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave);
clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state
clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo);
@@ -968,7 +946,6 @@ public void testTurnSubStatesToGameEndState() {
clientGameLogic.received(updateReady);
clientGameLogic.received(updateTSK);
clientGameLogic.received(waitPiece);
//clientGameLogic.received(spectatorMessage); commented because it indicate a state-change to spectator-state
clientGameLogic.received(selectPieceMessage);
//tests if the client is still in MovePiece
@@ -1170,18 +1147,14 @@ public void testTurnSubStatesToSpectator() {
clientGameLogic.received(activePlayer);
clientGameLogic.received(anyPiece);
clientGameLogic.received(briefing);
//clientGameLogic.received(ceremonyMessage); commented because it indicate a state-change to ceremony-state
clientGameLogic.received(die);
clientGameLogic.received(diceAgain);
//clientGameLogic.received(diceNow); commented because it indicate a state-change to rollDice-state
//clientGameLogic.received(endOfTurn); commented because it indicate a state-change to wait-state
clientGameLogic.received(lobbyAccept);
clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave);
clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage); commented because it indicate a state-change to interrupt-state
clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo);
@@ -1196,7 +1169,6 @@ public void testTurnSubStatesToSpectator() {
clientGameLogic.received(updateReady);
clientGameLogic.received(updateTSK);
clientGameLogic.received(waitPiece);
//clientGameLogic.received(spectatorMessage); commented because it indicate a state-change to spectator-state
clientGameLogic.received(selectPieceMessage);
//tests if the client is still in MovePiece
@@ -1466,7 +1438,7 @@ public void testPlayPowerCardToRollDice() {
//sends the die-message
int count = playPowerCard.getExtraAnimationCounter();
for (int i =0; i< count;i++){
for (int i = 0; i < count; i++) {
clientGameLogic.selectAnimationEnd();
}
clientGameLogic.selectAnimationEnd();
@@ -2397,9 +2369,7 @@ public void testStayInSelectedPiece() {
clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave);
//clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage);
clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo);
@@ -2485,9 +2455,7 @@ public void testStayInStartPiece() {
clientGameLogic.received(lobbyDeny);
clientGameLogic.received(lobbyPlayerJoin);
clientGameLogic.received(lobbyPlayerLeave);
//clientGameLogic.received(moveMessage);
clientGameLogic.received(noTurn);
//clientGameLogic.received(interruptMessage);
clientGameLogic.received(playCardSwap);
clientGameLogic.received(playCardShield);
clientGameLogic.received(playCardTurbo);
@@ -2749,8 +2717,8 @@ public void testWaitRankingToEndStateDetermineStartingPlayer() {
assertEquals(determineStartPlayer.getState(), determineStartPlayer.getIntro());
//sends endOfTurn-message
int animationCounter =determineStartPlayer.getIntro().getAnimationCounter();
for(int i =0; i<animationCounter;i++){
int animationCounter = determineStartPlayer.getIntro().getAnimationCounter();
for (int i = 0; i < animationCounter; i++) {
clientGameLogic.selectAnimationEnd();
}

View File

@@ -165,7 +165,7 @@ public void setUp() {
playerClient.initialize();
playerClient.addHandCard(bonusCardClient);
game.addPlayer(IDPlayerClient, playerClient);
pieceClient4 = playerHost.getWaitingArea()[3];
pieceClient4 = playerClient.getWaitingArea()[3];
game.getBoard().setPieceOnBoard(22,pieceClient4);
pieceClient4.setState(PieceState.ACTIVE);
@@ -784,19 +784,34 @@ public void testPlayPowerCardToRollDice() {
*/
@Test
public void testChoosePieceToMovePiece() {
playerClient.setHandCards(new ArrayList<>());
game.setActiveColor(playerClientColor);
turnState.setPlayer(playerClient);
playerClient.removeWaitingPiece(pieceClient4);
game.getBoard().setPieceOnBoard(25,pieceClient4);
pieceClient4.setState(PieceState.ACTIVE);
//sends the server in Game-State
serverGameLogic.setCurrentState(gameState);
assertEquals(serverGameLogic.getCurrentState(), gameState);
game.setActiveColor(playerClientColor);
game.setDiceEyes(1);
//sends the gameState in Turn
gameState.setCurrentState(turnState);
assertEquals(gameState.getCurrentState(), turnState);
game.setActiveColor(playerClientColor);
//sends the TurnState in ChoosePiece
turnState.setCurrentState(choosePieceState);
assertEquals(turnState.getCurrentState(), choosePieceState);
//Todo ???
choosePieceState.setCurrentState(selectPieceState);
System.out.println(game.getBoard().getInfieldIndexOfPiece(pieceClient4));
selectPieceState.setMoveablePieces(new ArrayList<>(List.of(pieceClient4)));
selectPieceState.setIsHomeMove(new ArrayList<>(List.of(false)));
selectPieceState.setTargetIndex(new ArrayList<>(List.of(23)));
serverGameLogic.received(new RequestMoveMessage(pieceClient4),IDPlayerClient);
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
@@ -867,7 +882,7 @@ public void testMovePieceToFirstRoll() {
*/
@Test
public void testFirstRollToRollDiceEndState() {
playerClient.setHandCards(new ArrayList<>());
//sends the server in Game-State
serverGameLogic.setCurrentState(gameState);
@@ -877,6 +892,7 @@ public void testFirstRollToRollDiceEndState() {
gameState.setCurrentState(turnState);
assertEquals(gameState.getCurrentState(), turnState);
game.setActiveColor(playerClientColor);
//sends the TurnState in RollDice
turnState.setCurrentState(rollDiceState);
assertEquals(turnState.getCurrentState(), rollDiceState);
@@ -885,13 +901,17 @@ public void testFirstRollToRollDiceEndState() {
rollDiceState.setCurrentState(firstRollState);
assertEquals(rollDiceState.getCurrentState(), firstRollState);
//TODO 2 Möglichkeiten
firstRollState.setMoveablePieces(new ArrayList<>(List.of(pieceClient4)));
//tests if the server is in NoPiece of ChoosePiece
game.setDie(new Die(1));
serverGameLogic.received(new RequestDieMessage(),IDPlayerClient);
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient);
//tests if the server is in ChoosePiece
assertEquals(serverGameLogic.getCurrentState(), gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(), choosePieceState);
assertEquals(choosePieceState.getCurrentState(), noPieceState);
}
/**
@@ -923,9 +943,9 @@ public void testFirstRollToSecondRoll() {
game.setDie(new Die(5));
game.setDiceEyes(5);
//Todo player has no figures to move and had no 6
serverGameLogic.received(requestDie, IDPlayerHost);
serverGameLogic.received(animationEnd, IDPlayerHost);
//player has no figures to move and had no 6
serverGameLogic.received(requestDie, IDPlayerClient);
serverGameLogic.received(animationEnd, IDPlayerClient);
//tests if the server is in the SecondRoll
assertEquals(serverGameLogic.getCurrentState(), gameState);