Adding the functionality of the dice.
- rolling a dice if its not locked
main
dustineversmann 2024-05-06 19:50:59 +02:00
parent cffcf6237d
commit 84d14c4f0b
1 changed files with 30 additions and 2 deletions

View File

@ -1,11 +1,39 @@
package src; package src;
import java.util.Random;
public class Die { public class Die {
private int faces;
private int value;
private boolean locked;
private Random random;
public Die (int eyes){ public Die(int faces) {
this.faces = faces;
this.locked = false;
this.random = new Random();
roll();
} }
public void roll() { public void roll() {
if (!locked) {
value = random.nextInt(faces) + 1;
} }
} }
public int getValue() {
return value;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public boolean isLocked() {
return locked;
}
public void toggleLock() {
this.locked = !this.locked;
}
}