only selected dice beat segments

This commit is contained in:
James 2024-04-21 01:30:46 +01:00
parent 3a6b5379dc
commit f947e25af7
2 changed files with 16 additions and 11 deletions

View file

@ -16,13 +16,12 @@ public class Die extends Actor {
*/
private final Face[] faces = new Face[6];
private int faceIndex = 3;
private boolean locked = false;
private boolean selected = false;
private static Texture lockedSprite;
private final Random random = new Random(); //TODO use central random
public Die(float x, float y, float width, float height) {
transform = new Transform(x, y, width, height);
@ -79,14 +78,14 @@ public class Die extends Actor {
return getFaceValue() <= 0;
}
public boolean isLocked() {
return locked;
public boolean isSelected() {
return selected;
}
public void setLocked(boolean locked) {
if (locked != this.locked)
public void setSelected(boolean selected) {
if (selected != this.selected)
{
if (locked) {
if (selected) {
transform.y += 64;
transform.rotation = 20;
}
@ -96,7 +95,7 @@ public class Die extends Actor {
}
} // terrible
this.locked = locked;
this.selected = selected;
}
}

View file

@ -59,7 +59,7 @@ public class Game extends ApplicationAdapter {
Input input = Gdx.input;
if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked
dice.stream().filter(d -> !d.isLocked()).forEach(Die::roll);
dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll);
System.out.println("=".repeat(100));
for (Segment segment : segments) {
@ -72,7 +72,7 @@ public class Game extends ApplicationAdapter {
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
die.setSelected(!die.isSelected()); //flip lock state
}
}
}
@ -97,7 +97,7 @@ public class Game extends ApplicationAdapter {
for (Segment segment : segments) {
String prefix = "[#9E65A8]";
if (segment.isDestroyed()) prefix = "[#EBE5EC]";
else if (segment.isDestroyedBy(dice)) prefix = "[#528154]";
else if (segment.isDestroyedBy(getSelectedDice())) prefix = "[#528154]";
font.draw(batch, prefix + segment.getName(), x += 75, Gdx.graphics.getHeight() - 100);
}
@ -112,4 +112,10 @@ public class Game extends ApplicationAdapter {
img.dispose();
}
public List<Die> getSelectedDice() {
return dice.stream()
.filter(d -> !d.isSelected())
.toList();
}
}