add round generation

This commit is contained in:
James 2024-04-21 14:23:47 +01:00
parent 89b01891b4
commit fd59b1a4c5
5 changed files with 59 additions and 1 deletions

View file

@ -11,7 +11,9 @@ import com.monjaro.gamejam.SegmentUI;
import com.monjaro.gamejam.segment.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
public class Game extends ApplicationAdapter {
@ -38,7 +40,7 @@ public class Game extends ApplicationAdapter {
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 TallDecay()), 5);
round = generateRound(0);
Face.setBlankFaceSprite(new Texture("blank_die_face.png"));
Face.setPipSprite(new Texture("pip.png"));
@ -141,6 +143,44 @@ public class Game extends ApplicationAdapter {
img.dispose();
}
public Round generateRound(int difficulty) {
Random random = new Random();
int points = 5 + difficulty * 3;
List<Segment> segments = new ArrayList<>();
List<Decay> decays = new ArrayList<>();
List<Segment> pool = new ArrayList<>();
for (int i = 2; i <= 5; i++) {
for (int j = i; j <= 5; j++) {
pool.add(new KinSegment(i));
pool.add(new OlympicSegment(i));
}
}
for (boolean b : new boolean[] {true, false}) pool.add(new DualSegment(b));
pool.sort(Comparator.comparingInt(Segment::getCost).reversed());
for (Segment segment : pool) {
if (random.nextFloat() > (float) segment.getCost() / points) {
segments.add(segment);
points -= segment.getCost();
}
}
decays.add(switch (random.nextInt(3)) {
case 0 -> new ParityDecay(false);
case 1 -> new ParityDecay(true);
default -> new TallDecay();
});
for (Segment segment : segments) {
System.out.println(segment.getName());
}
return new Round(segments, decays, 5);
}
public List<Die> getSelectedDice() {
return dice.stream()
.filter(Die::isSelected)

View file

@ -55,6 +55,11 @@ public class DualSegment extends Segment {
&& (!firstTrio || countCounts.getOrDefault(3, 0) >= 1);
}
@Override
public int getCost() {
return firstTrio ? 10 : 6;
}
@Override
public int getSpriteColumn() {
return 0;

View file

@ -36,6 +36,11 @@ public class KinSegment extends Segment { //multiple dice of the same value
return false;
}
@Override
public int getCost() {
return (int) (0.5 * requirement * (requirement + 1));
}
@Override
public int getSpriteColumn() {
return 0;

View file

@ -47,6 +47,12 @@ public class OlympicSegment extends Segment {
return best >= length;
}
@Override
public int getCost() {
int x = length;
return (int) (0.5 * x * (x - 1));
}
@Override
public int getSpriteColumn() {
return 0;

View file

@ -39,6 +39,8 @@ public abstract class Segment {
return destroyed;
}
public abstract int getCost(); //difficulty cost
public abstract int getSpriteColumn();
public abstract int getSpriteRow();