fixed failing test, due to wrong assertions or missing messages, as well as rewriting the 'addBonusCards()' method in Game to not use duplicates
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user