Merge commit

This commit is contained in:
Felix Koppe
2024-12-02 01:59:49 +01:00
2 changed files with 28 additions and 0 deletions

View File

@@ -43,11 +43,14 @@ public class Die {
*/ */
private int lastNumberOfDice; private int lastNumberOfDice;
private final boolean lock;
/** /**
* This constructor is used to create a new Die object with a random seed. * This constructor is used to create a new Die object with a random seed.
*/ */
public Die() { public Die() {
this.random = RandomGeneratorFactory.of("Random").create(); this.random = RandomGeneratorFactory.of("Random").create();
this.lock = false;
} }
/** /**
@@ -57,6 +60,18 @@ public Die() {
*/ */
public Die(long seed) { public Die(long seed) {
this.random = RandomGeneratorFactory.of("Random").create(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. * @return lastNumberOfDice as an Integer.
*/ */
public int shuffle() { public int shuffle() {
if (this.lock) {
return this.lastNumberOfDice;
}
this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1; this.lastNumberOfDice = this.random.nextInt(MAXIMUM_EYES) + 1;
return this.lastNumberOfDice; return this.lastNumberOfDice;

View File

@@ -316,6 +316,15 @@ public void setActiveColor(Color activeColor) {
this.activeColor = activeColor; this.activeColor = activeColor;
} }
/**
* This method will be used to set die attribute of Game class to the given die parameter.
*
* @param die as the new value of die as a Die object.
*/
public void setDie(Die die) {
this.die = die;
}
/** /**
* This method will be used to set host attribute of Game class to the given host parameter. * This method will be used to set host attribute of Game class to the given host parameter.
* *