diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-05-11 14:46:11 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-05-11 14:46:11 +0200 |
commit | a5cef081cee24e162d18d48ff798612f4dafbbd5 (patch) | |
tree | 590b378e3f0880c648248ff1753c52625be68973 /core/src/ch/asynk/rustanddust | |
parent | a8d65bb1bc3b419a8b301720f11f851609d71a60 (diff) | |
download | RustAndDust-a5cef081cee24e162d18d48ff798612f4dafbbd5.zip RustAndDust-a5cef081cee24e162d18d48ff798612f4dafbbd5.tar.gz |
Unit: add IterableSet<Unit> that keeps ref to the instances
Diffstat (limited to 'core/src/ch/asynk/rustanddust')
-rw-r--r-- | core/src/ch/asynk/rustanddust/game/Unit.java | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Unit.java b/core/src/ch/asynk/rustanddust/game/Unit.java index 38b1d7e..43125a2 100644 --- a/core/src/ch/asynk/rustanddust/game/Unit.java +++ b/core/src/ch/asynk/rustanddust/game/Unit.java @@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion; import ch.asynk.rustanddust.engine.Pawn; import ch.asynk.rustanddust.engine.Tile; import ch.asynk.rustanddust.engine.HeadedPawn; +import ch.asynk.rustanddust.engine.util.Collection; +import ch.asynk.rustanddust.engine.util.IterableSet; import ch.asynk.rustanddust.game.Hex.Terrain; import ch.asynk.rustanddust.RustAndDust; @@ -25,6 +27,17 @@ public class Unit extends HeadedPawn public static boolean blockId = false; public static int unitId = 1; + private static Collection<Unit> units = new IterableSet<Unit>(20); + + public static void clear() { units.clear(); } + public static Unit findById(int id) + { + for (Unit u : units) { + if (u.id() == id) + return u; + } + return null; + } public enum UnitType implements Pawn.PawnType { @@ -81,6 +94,7 @@ public class Unit extends HeadedPawn } this.entryZone = null; this.exitZone = null; + units.add(this); } private void commonSetup() |