diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-21 17:04:55 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-21 17:04:55 +0100 |
commit | 38acb010de83c6c4b3bce7209a2a796f6dda4dff (patch) | |
tree | d27e1e381f3491e4a622a28b5bbc5ea0e4de7aa1 /core/src/ch/asynk | |
parent | b2c746a1340f44056d27c11e25a835f5e5feef8e (diff) | |
download | RustAndDust-38acb010de83c6c4b3bce7209a2a796f6dda4dff.zip RustAndDust-38acb010de83c6c4b3bce7209a2a796f6dda4dff.tar.gz |
add game.ObjectiveSet implements MoveToAnimationCb
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/ObjectiveSet.java | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/ObjectiveSet.java b/core/src/ch/asynk/tankontank/game/ObjectiveSet.java new file mode 100644 index 0000000..2a4f3ee --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/ObjectiveSet.java @@ -0,0 +1,90 @@ +package ch.asynk.tankontank.game; + +import java.util.Collection; +import java.util.HashMap; + +import ch.asynk.tankontank.engine.gfx.Moveable; +import ch.asynk.tankontank.engine.gfx.animations.MoveToAnimation.MoveToAnimationCb; + +public class ObjectiveSet extends HashMap<Hex, Objective> implements MoveToAnimationCb +{ + private final Map map; + private final HashMap<Objective, Hex> modified; + + public ObjectiveSet(Map map, int n) + { + super(n); + this.map = map; + this.modified = new HashMap<Objective, Hex>(10); + } + + public void add(Hex hex, Army army, boolean persistent) + { + put(hex, new Objective(army, persistent)); + map.showObjective(hex, army); + } + + public int count(Army army) + { + int n = 0; + for (Objective objective : values()) { + if (objective.is(army)) + n += 1; + } + return n; + } + + @Override + public void moveToAnimationEnter(Moveable moveable, float x, float y, float r) + { + claim(map.getHexAt(x, y), (Army) moveable.getFaction()); + } + + @Override + public void moveToAnimationLeave(Moveable moveable, float x, float y, float r) + { + unclaim(map.getHexAt(x, y)); + } + + @Override + public void moveToAnimationDone(Moveable moveable, float x, float y, float r) + { + } + + public Army claim(Hex hex, Army army) + { + Objective objective = get(hex); + if (objective == null) + return Army.NONE; + if (objective.set(army)) { + modified.put(objective, hex); + map.showObjective(hex, army); + } + return army; + } + + public void unclaim(Hex hex) + { + Objective objective = get(hex); + if (objective == null) + return; + if (objective.unset()) { + modified.remove(objective); + map.showObjective(hex, objective.army()); + } + } + + public void forget() + { + modified.clear(); + } + + public void revert() + { + for (Objective objective : modified.keySet()) { + objective.revert(); + map.showObjective(modified.get(objective), objective.army()); + } + modified.clear(); + } +} |