summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2015-07-19 13:20:33 +0200
commitde0463bcf0f76ef8b07f2719679c9e0d72745c5d (patch)
tree9a33df947ceeea16a3e20b400585b1d3c304e77e /core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
parente66f9f2a61d3dab4545e996046486de0d44e2901 (diff)
downloadRustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip
RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java b/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
new file mode 100644
index 0000000..5618a9d
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/engine/ObjectiveSet.java
@@ -0,0 +1,78 @@
+package ch.asynk.rustanddust.engine;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+public class ObjectiveSet extends HashMap<Tile, Objective>
+{
+ public interface ObjectiveCb
+ {
+ public void showObjective(Tile tile, Faction faction);
+ }
+
+ private final Board board;
+ private final HashMap<Objective, Tile> modified;
+
+ public ObjectiveSet(Board board, int n)
+ {
+ super(n);
+ this.board = board;
+ this.modified = new HashMap<Objective, Tile>(10);
+ }
+
+ public void add(Tile tile, Faction faction, boolean persistent)
+ {
+ put(tile, new Objective(faction, persistent));
+ }
+
+ public int count(Faction faction)
+ {
+ int n = 0;
+ for (Objective objective : values()) {
+ if (objective.is(faction))
+ n += 1;
+ }
+ return n;
+ }
+
+ public Faction claim(Tile tile, Faction faction)
+ {
+ Objective objective = get(tile);
+ if (objective == null)
+ return null;
+
+ if (objective.set(faction))
+ modified.put(objective, tile);
+ return objective.faction();
+ }
+
+ public Faction unclaim(Tile tile)
+ {
+ Objective objective = get(tile);
+ if (objective == null)
+ return null;
+
+ if (objective.unset())
+ modified.remove(objective);
+ return objective.faction();
+ }
+
+ public void forget()
+ {
+ modified.clear();
+ }
+
+ public int modifiedCount()
+ {
+ return modified.size();
+ }
+
+ public void revert(ObjectiveCb cb)
+ {
+ for (Objective objective : modified.keySet()) {
+ objective.revert();
+ cb.showObjective(modified.get(objective), objective.faction());
+ }
+ modified.clear();
+ }
+}