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] 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; + } + +}