From d98d9ece8b3a1f1e00526a386afaa3164f889fe1 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:57:59 +0100 Subject: [PATCH 1/5] remove redundant code --- core/src/com/monjaro/gamejam/Die.java | 10 +--------- core/src/com/monjaro/gamejam/Face.java | 5 ++--- core/src/com/monjaro/gamejam/Game.java | 5 ----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index 2e7db70..b73e40a 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -9,26 +9,18 @@ import java.util.Random; public class Die extends Actor { private final Rectangle shape; + /* 0 1 2 3 4 5 */ - 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++) { - faces[i] = new Face(pips[i]); - } - shape = new Rectangle(); - } - public Die(float x, float y, float width, float height) { int[] pips = {4, 6, 5, 1, 2, 3}; for (int i = 0; i < faces.length; i++) { diff --git a/core/src/com/monjaro/gamejam/Face.java b/core/src/com/monjaro/gamejam/Face.java index e7e853d..4261db3 100644 --- a/core/src/com/monjaro/gamejam/Face.java +++ b/core/src/com/monjaro/gamejam/Face.java @@ -1,7 +1,7 @@ package com.monjaro.gamejam; + import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; @@ -10,10 +10,9 @@ import java.util.Collections; import java.util.List; import java.util.Random; - public class Face extends Actor{ - private Rectangle shape = new Rectangle(); + private final Rectangle shape = new Rectangle(); private final List pips = new ArrayList<>(); diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index 616304e..f457a32 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -3,9 +3,7 @@ package com.monjaro.gamejam; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; @@ -21,7 +19,6 @@ public class Game extends ApplicationAdapter { private final List dice = new ArrayList<>(); private SpriteBatch batch; - private BitmapFont font; private Texture img; private final static int TICKS_PER_SECOND = 60; @@ -30,7 +27,6 @@ public class Game extends ApplicationAdapter { @Override public void create() { batch = new SpriteBatch(); - font = new BitmapFont(); img = new Texture("badlogic.jpg"); Face.setBlankFaceSprite(new Texture("blank_die_face.png")); @@ -78,7 +74,6 @@ public class Game extends ApplicationAdapter { actors.forEach(a -> a.render(batch)); //TODO debug - int x = 100; for (Die die : dice) { die.render(batch); } From b34b175acde71c2e2eec0509c403aa775e5e0952 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 16:59:47 +0100 Subject: [PATCH 2/5] move check for locked dice when rerolling --- core/src/com/monjaro/gamejam/Die.java | 4 +--- core/src/com/monjaro/gamejam/Game.java | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index b73e40a..18ebcea 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -52,9 +52,7 @@ public class Die extends Actor { } public void roll() { - if (!locked) { - faceIndex = random.nextInt(6); - } + faceIndex = random.nextInt(6); } public void decay() { //remove a pip from all faces of this die diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index f457a32..9be2d61 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -46,8 +46,8 @@ public class Game extends ApplicationAdapter { public void processInput() { Input input = Gdx.input; - if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice - dice.forEach(Die::roll); + if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked + dice.stream().filter(d -> !d.isLocked()).forEach(Die::roll); } for (int i = 0; i < dice.size(); i++) { //lock dice, iterating over for each keycode From 92bd26341dc2def6e9fa54800366e9383fe16951 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:30:56 +0100 Subject: [PATCH 3/5] upgrade to java 1.20 --- core/build.gradle | 2 +- desktop/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index 0cad2ec..741d4b9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,4 +1,4 @@ -sourceCompatibility = 1.8 +sourceCompatibility = 1.20 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' sourceSets.main.java.srcDirs = [ "src/" ] diff --git a/desktop/build.gradle b/desktop/build.gradle index d957fdc..dffa54c 100644 --- a/desktop/build.gradle +++ b/desktop/build.gradle @@ -1,4 +1,4 @@ -sourceCompatibility = 1.8 +sourceCompatibility = 1.20 sourceSets.main.java.srcDirs = [ "src/" ] sourceSets.main.resources.srcDirs = ["../assets"] From 57e975c7c7e77365e72743facaa8122f7b8000a6 Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 19:18:00 +0100 Subject: [PATCH 4/5] added segment and kinsegment --- .../monjaro/gamejam/segment/KinSegment.java | 40 +++++++++++++++++++ .../com/monjaro/gamejam/segment/Segment.java | 23 +++++++++++ 2 files changed, 63 insertions(+) create mode 100644 core/src/com/monjaro/gamejam/segment/KinSegment.java create mode 100644 core/src/com/monjaro/gamejam/segment/Segment.java diff --git a/core/src/com/monjaro/gamejam/segment/KinSegment.java b/core/src/com/monjaro/gamejam/segment/KinSegment.java new file mode 100644 index 0000000..9dae9b5 --- /dev/null +++ b/core/src/com/monjaro/gamejam/segment/KinSegment.java @@ -0,0 +1,40 @@ +package com.monjaro.gamejam.segment; + +import com.monjaro.gamejam.Die; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class KinSegment extends Segment { //multiple dice of the same value + + private final int requirement; + + public KinSegment(int requirement) { + this.requirement = requirement; + + name = switch (requirement) { + case 1 -> "Any"; + case 2 -> "Pair"; + case 3 -> "Trio"; + case 4 -> "Quartet"; + case 5 -> "Quintet"; + default -> requirement + " of a kind"; + }; + } + + @Override + public boolean destroyedBy(List dice) { + Map counts = new HashMap<>(); + for (Die die : dice) { + int count = counts.getOrDefault(die.getFaceValue(), 1) + 1; + + if (count >= requirement) return true; + + counts.put(die.getFaceValue(), count); + } + + return false; + } + +} diff --git a/core/src/com/monjaro/gamejam/segment/Segment.java b/core/src/com/monjaro/gamejam/segment/Segment.java new file mode 100644 index 0000000..8edf3a5 --- /dev/null +++ b/core/src/com/monjaro/gamejam/segment/Segment.java @@ -0,0 +1,23 @@ +package com.monjaro.gamejam.segment; + +import com.monjaro.gamejam.Die; + +import java.util.List; + +public abstract class Segment { + + private boolean destroyed = false; + + protected String name; + + public void destroy() { + destroyed = true; + } + + public abstract boolean destroyedBy(List die); + + public String getName() { + return name; + } + +} From 64b12d17a636bc5036be7473a0ca1eda8fb8076b Mon Sep 17 00:00:00 2001 From: James <150948866+jameslaight@users.noreply.github.com> Date: Sat, 20 Apr 2024 20:22:57 +0100 Subject: [PATCH 5/5] add dual segments --- core/src/com/monjaro/gamejam/Die.java | 4 ++ core/src/com/monjaro/gamejam/Game.java | 16 +++++ .../monjaro/gamejam/segment/DualSegment.java | 58 +++++++++++++++++++ .../monjaro/gamejam/segment/KinSegment.java | 16 +++-- .../com/monjaro/gamejam/segment/Segment.java | 17 +++++- 5 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 core/src/com/monjaro/gamejam/segment/DualSegment.java diff --git a/core/src/com/monjaro/gamejam/Die.java b/core/src/com/monjaro/gamejam/Die.java index 18ebcea..b9af9e0 100644 --- a/core/src/com/monjaro/gamejam/Die.java +++ b/core/src/com/monjaro/gamejam/Die.java @@ -71,6 +71,10 @@ public class Die extends Actor { return getFace().getValue(); } + public boolean isBlank() { + return getFaceValue() <= 0; + } + public boolean isLocked() { return locked; } diff --git a/core/src/com/monjaro/gamejam/Game.java b/core/src/com/monjaro/gamejam/Game.java index 9be2d61..acf2641 100644 --- a/core/src/com/monjaro/gamejam/Game.java +++ b/core/src/com/monjaro/gamejam/Game.java @@ -6,6 +6,9 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.utils.ScreenUtils; +import com.monjaro.gamejam.segment.DualSegment; +import com.monjaro.gamejam.segment.KinSegment; +import com.monjaro.gamejam.segment.Segment; import java.util.ArrayList; import java.util.HashSet; @@ -17,6 +20,7 @@ public class Game extends ApplicationAdapter { private final Set actors = new HashSet<>(); private final List dice = new ArrayList<>(); + private final List segments = new ArrayList<>(); private SpriteBatch batch; private Texture img; @@ -35,6 +39,12 @@ public class Game extends ApplicationAdapter { for (int i = 1; i <= 5; i++) { dice.add(new Die((i*80), 20, 64, 64)); } + + for (int i = 1; i <= 5; i++) { + segments.add(new KinSegment(i)); + } + segments.add(new DualSegment(false)); + segments.add(new DualSegment(true)); } public void tick() { @@ -48,8 +58,14 @@ public class Game extends ApplicationAdapter { if (input.isKeyJustPressed(Input.Keys.R)) { //reroll dice that aren't locked dice.stream().filter(d -> !d.isLocked()).forEach(Die::roll); + + System.out.println("=".repeat(100)); + for (Segment segment : segments) { + System.out.println(segment.getName() + ": " + segment.isDestroyedBy(dice)); + } } + 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 diff --git a/core/src/com/monjaro/gamejam/segment/DualSegment.java b/core/src/com/monjaro/gamejam/segment/DualSegment.java new file mode 100644 index 0000000..07082af --- /dev/null +++ b/core/src/com/monjaro/gamejam/segment/DualSegment.java @@ -0,0 +1,58 @@ +package com.monjaro.gamejam.segment; + +import com.monjaro.gamejam.Die; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +public class DualSegment extends Segment { + + private final boolean firstTrio; + + public DualSegment(boolean firstTrio) { //first is a trio or duo, second is a duo + this.firstTrio = firstTrio; + + if (firstTrio) { + Random random = new Random(); + + if (random.nextInt(10) != 0) { + name = "Full House"; + } else { + String[] names = new String[]{ + "Complete Household", + "Entire Residence", + "Occupied Home", + "Family Residence", + "Filled Dwelling", + "Packed Abode", + "Crowded Domicile", + "Busy Household", + "Well-occupied Home", + "Houseful" + }; //thank you ChatGPT for alternate names + name = names[random.nextInt(names.length)]; + } + } else { + name = "Dual Duo"; + } + } + + @Override + public boolean isDestroyedBy(List dice) { + Map counts = countValues(dice); + + Map countCounts = new HashMap<>(); //count of counts + for (int count : counts.values()) { + for (int i = count; i >= 1; i--) { //add from count to 1 - this is so a trio is also a pair, e.g. 11122 is a dual duo + int countCount = countCounts.getOrDefault(i, 0) + 1; + countCounts.put(i, countCount); + } + } + + return countCounts.getOrDefault(2, 0) >= 2 + && (!firstTrio || countCounts.getOrDefault(3, 0) >= 1); + } + +} diff --git a/core/src/com/monjaro/gamejam/segment/KinSegment.java b/core/src/com/monjaro/gamejam/segment/KinSegment.java index 9dae9b5..f27f271 100644 --- a/core/src/com/monjaro/gamejam/segment/KinSegment.java +++ b/core/src/com/monjaro/gamejam/segment/KinSegment.java @@ -2,7 +2,6 @@ package com.monjaro.gamejam.segment; import com.monjaro.gamejam.Die; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -15,7 +14,7 @@ public class KinSegment extends Segment { //multiple dice of the same value name = switch (requirement) { case 1 -> "Any"; - case 2 -> "Pair"; + case 2 -> "Duo"; case 3 -> "Trio"; case 4 -> "Quartet"; case 5 -> "Quintet"; @@ -24,14 +23,13 @@ public class KinSegment extends Segment { //multiple dice of the same value } @Override - public boolean destroyedBy(List dice) { - Map counts = new HashMap<>(); - for (Die die : dice) { - int count = counts.getOrDefault(die.getFaceValue(), 1) + 1; + public boolean isDestroyedBy(List dice) { + Map counts = countValues(dice); - if (count >= requirement) return true; - - counts.put(die.getFaceValue(), count); + for (int count : counts.values()) { + if (count >= requirement) { + return true; + } } return false; diff --git a/core/src/com/monjaro/gamejam/segment/Segment.java b/core/src/com/monjaro/gamejam/segment/Segment.java index 8edf3a5..5086c0c 100644 --- a/core/src/com/monjaro/gamejam/segment/Segment.java +++ b/core/src/com/monjaro/gamejam/segment/Segment.java @@ -2,7 +2,9 @@ package com.monjaro.gamejam.segment; import com.monjaro.gamejam.Die; +import java.util.HashMap; import java.util.List; +import java.util.Map; public abstract class Segment { @@ -14,10 +16,23 @@ public abstract class Segment { destroyed = true; } - public abstract boolean destroyedBy(List die); + public abstract boolean isDestroyedBy(List die); public String getName() { return name; } + protected Map countValues(List dice) { + Map counts = new HashMap<>(); + + for (Die die : dice) { + if (die.isBlank()) continue; + + int count = counts.getOrDefault(die.getFaceValue(), 0) + 1; + counts.put(die.getFaceValue(), count); + } + + return counts; + } + }