diff --git a/Projekte/mdga/model/src/main/java/pp/mdga/game/Die.java b/Projekte/mdga/model/src/main/java/pp/mdga/game/Die.java index 08a378e2..fc013d75 100644 --- a/Projekte/mdga/model/src/main/java/pp/mdga/game/Die.java +++ b/Projekte/mdga/model/src/main/java/pp/mdga/game/Die.java @@ -1,7 +1,11 @@ package pp.mdga.game; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; import java.util.random.RandomGenerator; import java.util.random.RandomGeneratorFactory; +import java.util.stream.IntStream; /** * This class represents a simple die with the possibilities to shuffle and return the roll result. @@ -43,6 +47,14 @@ public class Die { */ private int lastNumberOfDice; + /** + * Predefined rolls for testing. + */ + private Iterator rolls; + + /** + * If the results of the die should be locked. + */ private final boolean lock; /** @@ -65,7 +77,7 @@ public Die(long seed) { /** * Constructor. - * + * * @param roll as the roll which should be returned everytime the shuffle method will be called as an Integer. */ public Die(int roll) { @@ -74,6 +86,17 @@ public Die(int roll) { this.lock = true; } + /** + * Constructor. + * + * @param rolls as a variable list of rolls which will be used by test cases as an Array of Integers. + */ + public Die(int... rolls) { + this.random = RandomGeneratorFactory.of("Random").create(); + this.rolls = IntStream.of(rolls).iterator(); + this.lock = false; + } + /** * This method will be used to return a random number generated by the random attribute of Die class. * @@ -84,6 +107,11 @@ public int shuffle() { return this.lastNumberOfDice; } + if (this.rolls != null && this.rolls.hasNext()) { + this.lastNumberOfDice = this.rolls.next(); + return this.lastNumberOfDice; + } + this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1; return this.lastNumberOfDice;