added ability to lock dice

This commit is contained in:
James 2024-04-20 16:34:16 +01:00
parent 2544da0313
commit 40bcbee4e9
2 changed files with 22 additions and 3 deletions

View file

@ -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