Merge branch 'development' into 'dev/test'

Updated 'Die' class.

See merge request progproj/gruppen-ht24/Gruppe-01!31
This commit was merged in pull request #31.
This commit is contained in:
Benjamin Feyer
2024-12-02 00:49:22 +00:00
6 changed files with 1953 additions and 49 deletions

View File

@@ -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;