added segment and kinsegment
This commit is contained in:
parent
92bd26341d
commit
57e975c7c7
2 changed files with 63 additions and 0 deletions
40
core/src/com/monjaro/gamejam/segment/KinSegment.java
Normal file
40
core/src/com/monjaro/gamejam/segment/KinSegment.java
Normal file
|
@ -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<Die> dice) {
|
||||||
|
Map<Integer, Integer> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
23
core/src/com/monjaro/gamejam/segment/Segment.java
Normal file
23
core/src/com/monjaro/gamejam/segment/Segment.java
Normal file
|
@ -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> die);
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue