From 0b45727bd72a2500d9e87a965328a4f4737f844f Mon Sep 17 00:00:00 2001 From: Daniel Grigencha Date: Mon, 2 Dec 2024 01:39:01 +0100 Subject: [PATCH] Updated 'Die' class. Updated the 'Die' class by adding a third constructor for test cases. --- .../model/src/main/java/pp/mdga/game/Die.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 047cf6ce..08a378e2 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 @@ -43,11 +43,14 @@ public class Die { */ private int lastNumberOfDice; + private final boolean lock; + /** * This constructor is used to create a new Die object with a random seed. */ public Die() { this.random = RandomGeneratorFactory.of("Random").create(); + this.lock = false; } /** @@ -57,6 +60,18 @@ public Die() { */ public Die(long seed) { this.random = RandomGeneratorFactory.of("Random").create(seed); + this.lock = false; + } + + /** + * Constructor. + * + * @param roll as the roll which should be returned everytime the shuffle method will be called as an Integer. + */ + public Die(int roll) { + this.random = RandomGeneratorFactory.of("Random").create(); + this.lastNumberOfDice = roll; + this.lock = true; } /** @@ -65,6 +80,10 @@ public Die(long seed) { * @return lastNumberOfDice as an Integer. */ public int shuffle() { + if (this.lock) { + return this.lastNumberOfDice; + } + this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1; return this.lastNumberOfDice;