From 40bcbee4e9b515d6d2676201ddc03ecd905c3749 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:34:16 +0100 Subject: [PATCH] added ability to lock dice --- core/src/com/monjaro/gamejam/Die.java | 14 ++++++++++++-- core/src/com/monjaro/gamejam/Game.java | 11 ++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index afa6416..84e6879 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -17,10 +17,10 @@ public class Die extends Actor { private final Face[] faces = new Face[6]; private int faceIndex = 3; + private boolean locked = false; private final Random random = new Random(); //TODO use central random - public Die() { int[] pips = {4, 6, 5, 1, 2, 3}; for (int i = 0; i < faces.length; i++) { @@ -49,7 +49,9 @@ public class Die extends Actor { } public void roll() { - faceIndex = random.nextInt(6); + if (!locked) { + faceIndex = random.nextInt(6); + } } public void decay() { //remove a pip from all faces of this die @@ -68,4 +70,12 @@ public class Die extends Actor { return getFace().getValue(); } + public boolean isLocked() { + return locked; + } + + public void setLocked(boolean locked) { + this.locked = locked; + } + } diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index d323f63..ca4a0ff 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -47,9 +47,18 @@ public class Game extends ApplicationAdapter { public void processInput() { Input input = Gdx.input; - if (input.isKeyJustPressed(Input.Keys.R)) { + if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice dice.forEach(Die::roll); } + + for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode + Die die = dice.get(i); //die iterator is looking at + int keyCode = Input.Keys.NUM_1 + i; //keycode for the current die, 1, 2...9, 0 on keyboard + + if (input.isKeyJustPressed(keyCode)) { //if key corresponding to die has been pressed + die.setLocked(!die.isLocked()); //flip lock state + } + } } @Override