From 84d14c4f0b7a14cb0ccbb3321dfaca3716bfb444 Mon Sep 17 00:00:00 2001 From: dustineversmann Date: Mon, 6 May 2024 19:50:59 +0200 Subject: [PATCH] feat: Adding the functionality of the dice. - rolling a dice if its not locked --- src/Die.java | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Die.java b/src/Die.java index d538dc0..076eb43 100644 --- a/src/Die.java +++ b/src/Die.java @@ -1,11 +1,39 @@ package src; +import java.util.Random; 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() { + 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; } } +