diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index ce11c7d..2e7db70 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++) { @@ -60,7 +60,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 @@ -79,4 +81,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 811bc01..616304e 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -50,9 +50,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