merge
This commit is contained in:
commit
fe4a77b32a
2 changed files with 22 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue