merge conflict vanished

This commit is contained in:
Rosia E Evans 2024-04-21 12:44:14 +01:00
commit bd02582186
8 changed files with 142 additions and 60 deletions

View file

@ -0,0 +1,15 @@
package com.monjaro.gamejam.main;
import java.util.List;
public abstract class Decay {
protected String description;
public abstract List<Die> getDecayed(List<Die> dice);
public String getDescription() {
return description;
}
}

View file

@ -61,7 +61,8 @@ public class Die extends Actor {
public void decay() { //remove a pip from all faces of this die
for (Face face : faces) {
List<Face.Pip> pips = face.getPips();
Face.Pip decayed = pips.get(random.nextInt());
if (pips.isEmpty()) continue;
Face.Pip decayed = pips.get(random.nextInt(pips.size()));
face.removePip(decayed);
}
}

View file

@ -6,7 +6,6 @@ import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ScreenUtils;
import com.monjaro.gamejam.SegmentUI;
import com.monjaro.gamejam.segment.DualSegment;
@ -20,7 +19,6 @@ import java.util.List;
public class Game extends ApplicationAdapter {
private final List<Die> dice = new ArrayList<>();
private final List<Segment> segments = new ArrayList<>();
private SpriteBatch batch;
private BitmapFont font;
@ -29,8 +27,7 @@ public class Game extends ApplicationAdapter {
private final static int TICKS_PER_SECOND = 60;
private double tickProgress = 0;
private RoundData roundData;
private Round round;
private UI ui;
private SegmentUI segUi;
@ -41,54 +38,66 @@ public class Game extends ApplicationAdapter {
font.getData().markupEnabled = true;
img = new Texture("badlogic.jpg");
ui = new UI(50, 280, 10);
roundData = new RoundData(10);
segUi = new SegmentUI();
ui = new UI(this, 50, 280);
round = new Round(List.of(new OlympicSegment(1), new OlympicSegment(3), new KinSegment(3), new DualSegment(false)), List.of(new ParityDecay(true)), 5);
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
Face.setPipSprite(new Texture("pip.png"));
Die.setLockedSprite(new Texture("locked_die_border.png"));
UI.setRerollTexture(new Texture("reroll_symbol.png"));
Vector2 dieSize = new Vector2();
float divide = Gdx.graphics.getWidth() / 6f;
for (int i = 0; i < 5; i++) {
dice.add(new Die(divide * (i + 1), 350, 64, 64));
}
for (int i = 1; i <= 5; i++) {
segments.add(new KinSegment(i));
}
for (int i = 2; i <= 5; i++) {
segments.add(new OlympicSegment(i));
}
segments.add(new DualSegment(false));
segments.add(new DualSegment(true));
}
public void tick() {
processInput();
ui.setRemainingRerolls(roundData.getRerolls());
ui.setRerolls(round.getRerolls());
}
public void processInput() {
Input input = Gdx.input;
if (input.isKeyJustPressed(Input.Keys.R) && roundData.getRerolls() > 0) { //reroll dice that aren't locked
dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll);
roundData.reduceRerolls(1);
if (input.isKeyJustPressed(Input.Keys.R) && round.getRerolls() > 0) { //reroll dice that aren't locked
reroll();
round.reduceRerolls(0);
}
if (input.isKeyPressed(Input.Keys.SHIFT_LEFT)) {
for (int i = 0; i < round.getSegments().size(); i++) {
int keyCode = Input.Keys.NUM_1 + i; //keycode for the current segment, shift + 1, 2...9, 0 on keyboard
if (input.isKeyJustPressed(keyCode)) {
Segment segment = round.getSegments().get(i);
if (segment.isDestroyedBy(getSelectedDice())) { //if can be destroyed with selected
segment.destroy();
round.getDecays().forEach(d -> d.getDecayed(getSelectedDice()).forEach(Die::decay)); //apply all decay rules
dice.forEach(d -> d.setSelected(false));
// reroll();
}
}
}
} else {
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 die = dice.get(i); //die iterator is looking at
die.setSelected(!die.isSelected()); //flip lock state
}
}
}
}
private void reroll() {
dice.stream().filter(d -> !d.isSelected()).forEach(Die::roll);
}
@Override
public void render() {
@ -107,13 +116,17 @@ public class Game extends ApplicationAdapter {
}
int y = Gdx.graphics.getHeight() - 50;
for (Segment segment : segments) {
for (Segment segment : round.getSegments()) {
String prefix = "[#9E65A8]";
if (segment.isDestroyed()) prefix = "[#EBE5EC]";
else if (segment.isDestroyedBy(getSelectedDice())) prefix = "[#528154]";
font.draw(batch, prefix + segment.getName(), 100, y -= 20);
}
y -= 50;
for (Decay decay : round.getDecays()) {
font.draw(batch, "[#9E65A8]" + decay.getDescription(), 100, y -= 20);
}
//-----
ui.render(batch);
@ -135,4 +148,8 @@ public class Game extends ApplicationAdapter {
.toList();
}
public Round getRound() {
return round;
}
}

View file

@ -0,0 +1,22 @@
package com.monjaro.gamejam.main;
import java.util.List;
public class ParityDecay extends Decay {
private final int parity;
public ParityDecay(boolean odd) {
parity = odd ? 1 : 0;
description = "All used dice with " + (odd ? "ODD" : "EVEN") + " value decay.";
}
@Override
public List<Die> getDecayed(List<Die> dice) {
return dice.stream()
.filter(d -> !d.isFaceBlank())
.filter(d -> d.getFaceValue() % 2 == parity)
.toList();
}
}

View file

@ -0,0 +1,45 @@
package com.monjaro.gamejam.main;
import com.monjaro.gamejam.segment.Segment;
import java.util.List;
public class Round {
private final List<Segment> segments;
private final List<Decay> decays;
private final int maxRerolls;
private int rerolls;
public Round(List<Segment> segments, List<Decay> decays, int rerolls) {
this.segments = segments;
this.decays = decays;
maxRerolls = rerolls;
this.rerolls = rerolls;
}
public List<Segment> getSegments() {
return segments;
}
public List<Decay> getDecays() {
return decays;
}
public int getMaxRerolls() {
return maxRerolls;
}
public int getRerolls() {
return rerolls;
}
public void setRerolls(int rerolls) {
this.rerolls = rerolls;
}
public void reduceRerolls(int i) {
rerolls -= i;
}
}

View file

@ -1,21 +0,0 @@
package com.monjaro.gamejam.main;
public class RoundData {
private int rerolls;
public RoundData(int rerolls){
this.rerolls = rerolls;
}
public int getRerolls() {
return rerolls;
}
public void setRerolls(int rerolls) {
this.rerolls = rerolls;
}
public void reduceRerolls(int i) {
rerolls -= i;
}
}

View file

@ -5,17 +5,16 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class UI extends Actor{
private Transform position;
private final Game game;
private final Transform position;
private static Texture rerollTexture;
private int rerolls;
private int remainingRerolls;
public UI(int x, int y, int rerolls)
{
public UI(Game game, int x, int y) {
this.game = game;
position = new Transform(x, y, 0, 0);
this.rerolls = rerolls;
this.remainingRerolls = rerolls;
}
public void setPosition(int x, int y){
@ -23,7 +22,9 @@ public class UI extends Actor{
position.y = y;
}
public void setRemainingRerolls(int x){remainingRerolls = x;}
public void setRerolls(int x){
rerolls = x;
}
public static void setRerollTexture(Texture texture){rerollTexture = texture;}
@ -34,8 +35,8 @@ public class UI extends Actor{
@Override
public void render(SpriteBatch batch) {
for (int i = 0; i < rerolls; i++) {
if (i > remainingRerolls-1)
for (int i = 0; i < game.getRound().getMaxRerolls(); i++) {
if (i >= game.getRound().getRerolls())
batch.setColor(Color.GRAY);
batch.draw(rerollTexture, (position.x + (40f*i)), (position.y));
batch.setColor(Color.WHITE);

View file

@ -30,15 +30,17 @@ public class OlympicSegment extends Segment {
.sorted()
.toList();
int last = -1, run = 1, best = run;
int last = -1, run = 1, best = 0;
for (int value : values) {
if (value == last + 1) {
if (++run > best) best = run;
run++;
} else {
run = 1;
}
if (run > best) best = run;
last = value;
}