Merge branch 'main' into 'development2'

fixed failing test, due to wrong assertions or missing messages, as well as...

See merge request progproj/gruppen-ht24/Gruppe-01!41
This commit is contained in:
Hanno Fleischer
2024-12-13 13:05:31 +00:00
5 changed files with 42 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
package pp.mdga.client;
import pp.mdga.message.client.ForceContinueGameMessage;
import pp.mdga.message.client.LeaveGameMessage;
import pp.mdga.message.server.ResumeGameMessage;
import pp.mdga.notification.StartDialogNotification;
public class InterruptState extends ClientState {
@@ -61,6 +63,13 @@ public void selectResume() {
}
}
@Override
public void selectLeave() {
logic.send(new LeaveGameMessage());
logic.addNotification(new StartDialogNotification());
logic.setState(logic.getDialogs());
}
/**
* The server resumes the game
*

View File

@@ -5,6 +5,8 @@
import pp.mdga.game.card.SwapCard;
import pp.mdga.game.card.TurboCard;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
/**
@@ -134,7 +136,20 @@ public PowerCard draw() {
* @param count the number of cards to add
*/
private void addBonusCards(PowerCard card, int count) {
drawPile.addAll(Collections.nCopies(count, card));
Class<? extends PowerCard> cardClass = card.getClass();
try {
// Get the constructor for the PowerCard class
Constructor<? extends PowerCard> constructor = cardClass.getDeclaredConstructor();
constructor.setAccessible(true); // Necessary if the constructor is not public
for (int i = 0; i < count; i++) {
// Create a new instance of the PowerCard
PowerCard newCard = constructor.newInstance();
this.drawPile.add(newCard);
}
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace(); // Log any issues with reflection
}
}
/**

View File

@@ -145,6 +145,7 @@ public void testDeselectTSK() {
serverGameLogic.setCurrentState(lobbyState);
assertEquals(lobbyState, serverGameLogic.getCurrentState());
serverGameLogic.received(selectTSKMessage, IDClient);
assertEquals(Color.CYBER, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
serverGameLogic.received(deselectTSKMessage, IDClient);
assertEquals(Color.NONE, serverGameLogic.getGame().getPlayerById(IDClient).getColor());
@@ -189,7 +190,7 @@ public void testReady() {
// Send a LobbyReadyMessage and validate the player is marked as ready
serverGameLogic.received(readyMessage, IDClient);
assertFalse(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
assertTrue(serverGameLogic.getGame().getPlayerById(IDClient).isReady());
serverGameLogic.received(readyMessage, IDHost);
assertTrue(serverGameLogic.getGame().getPlayerById(IDHost).isReady());

View File

@@ -684,6 +684,8 @@ public void testReachBonusField() {
//gets the top bonusCard
PowerCard card = game.getDrawPile().get(0);
System.out.println(card);
System.out.println(game.getDrawPile().get(1));
//sets the dice-seed to 4
game.setDie(die4);
@@ -700,8 +702,8 @@ public void testReachBonusField() {
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
//tests if the player has received a bonusCard
assertNotEquals(card, game.getDrawPile().get(0));
assertTrue(game.getPlayers().get(IDHost).getHandCards().stream().toList().contains(card));
assertNotEquals(card, game.getDrawPile().get(0));
}
/**