diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-20 13:38:51 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-20 13:38:51 +0100 |
commit | 4afc2ac7c837ae645733109a161305c804a1b45a (patch) | |
tree | 223875875e27031fc796192b4ab6c9a9b03aeafa | |
parent | 661409680c14f8999b5bb2c32e616a42be361fa2 (diff) | |
download | RustAndDust-4afc2ac7c837ae645733109a161305c804a1b45a.zip RustAndDust-4afc2ac7c837ae645733109a161305c804a1b45a.tar.gz |
engine.TileSet/Zone are dead: welcome game.HexSet/Zone
20 files changed, 97 insertions, 110 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 8dd0ce9..cc3b08f 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -32,12 +32,6 @@ public abstract class Board implements Disposable public Tile getNewTile(float x, float y, int col, int row, boolean offmap); } - public interface TileCollection extends Collection<Tile> - { - public Tile first(); - public void enable(int i, boolean enable); - } - public interface PawnCollection extends Collection<Pawn> { public Pawn first(); @@ -293,7 +287,7 @@ public abstract class Board implements Disposable debugShapes.setTransformMatrix(prevTransform); } - protected int collectPossibleMoves(Pawn pawn, TileCollection moves) + protected int collectPossibleMoves(Pawn pawn, Collection<Tile> moves) { return searchBoard.possibleMovesFrom(pawn, moves); } diff --git a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java index 91038da..30f63fd 100644 --- a/core/src/ch/asynk/tankontank/engine/PossiblePaths.java +++ b/core/src/ch/asynk/tankontank/engine/PossiblePaths.java @@ -1,9 +1,11 @@ package ch.asynk.tankontank.engine; -import java.util.List; import java.util.Iterator; import java.util.ArrayList; +import java.util.List; import java.util.LinkedList; +import java.util.HashSet; +import java.util.LinkedHashSet; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; @@ -20,12 +22,12 @@ public class PossiblePaths implements Iterable<Vector3> private List<Tile> ctrlTiles; private List<ArrayList<Tile>> paths; private List<ArrayList<Tile>> filteredPaths; - private Board.TileCollection tiles; + private HashSet<Tile> tiles; public PossiblePaths(Board board, int tSize, int stSize, int ftSize, int vectSize) { this.board = board; - this.tiles = new TileSet(board, tSize); + this.tiles = new LinkedHashSet<Tile>(tSize); this.stack = new ArrayList<Tile>(stSize); this.ctrlTiles = new ArrayList<Tile>(ftSize); this.paths = new LinkedList<ArrayList<Tile>>(); diff --git a/core/src/ch/asynk/tankontank/engine/SearchBoard.java b/core/src/ch/asynk/tankontank/engine/SearchBoard.java index a93bd67..227d19a 100644 --- a/core/src/ch/asynk/tankontank/engine/SearchBoard.java +++ b/core/src/ch/asynk/tankontank/engine/SearchBoard.java @@ -7,6 +7,7 @@ import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.ArrayDeque; import java.util.Iterator; +import java.util.Collection; public class SearchBoard { @@ -110,7 +111,7 @@ public class SearchBoard a[5] = getNode((src.col - 1), (src.row - 1)); } - public int possibleMovesFrom(Pawn pawn, Board.TileCollection moves) + public int possibleMovesFrom(Pawn pawn, Collection<Tile> moves) { moves.clear(); searchCount += 1; diff --git a/core/src/ch/asynk/tankontank/engine/TileSet.java b/core/src/ch/asynk/tankontank/engine/TileSet.java deleted file mode 100644 index c8897f3..0000000 --- a/core/src/ch/asynk/tankontank/engine/TileSet.java +++ /dev/null @@ -1,26 +0,0 @@ -package ch.asynk.tankontank.engine; - -import java.util.LinkedHashSet; - -public class TileSet extends LinkedHashSet<Tile> implements Board.TileCollection -{ - private final Board board; - - public TileSet(Board board, int n) - { - super(n); - this.board = board; - } - - public Tile first() - { - if (isEmpty()) return null; - return iterator().next(); - } - - public void enable(int i, boolean enable) - { - for (Tile tile : this) - board.enableOverlayOn(tile, i, enable); - } -} diff --git a/core/src/ch/asynk/tankontank/engine/Zone.java b/core/src/ch/asynk/tankontank/engine/Zone.java deleted file mode 100644 index f0c957b..0000000 --- a/core/src/ch/asynk/tankontank/engine/Zone.java +++ /dev/null @@ -1,12 +0,0 @@ -package ch.asynk.tankontank.engine; - -public class Zone extends TileSet -{ - public int allowedMoves; - public Orientation orientation; - - public Zone(Board board, int n) - { - super(board, n); - } -} diff --git a/core/src/ch/asynk/tankontank/game/Battle.java b/core/src/ch/asynk/tankontank/game/Battle.java index 9b1e502..0c2c3e3 100644 --- a/core/src/ch/asynk/tankontank/game/Battle.java +++ b/core/src/ch/asynk/tankontank/game/Battle.java @@ -1,6 +1,6 @@ package ch.asynk.tankontank.game; -import ch.asynk.tankontank.engine.Zone; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.hud.Position; diff --git a/core/src/ch/asynk/tankontank/game/HexSet.java b/core/src/ch/asynk/tankontank/game/HexSet.java new file mode 100644 index 0000000..436c727 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/HexSet.java @@ -0,0 +1,29 @@ +package ch.asynk.tankontank.game; + +import java.util.Collection; +import java.util.LinkedHashSet; + +import ch.asynk.tankontank.engine.Tile; + +public class HexSet extends LinkedHashSet<Hex> +{ + private final Map map; + + public HexSet(Map map, int n) + { + super(n); + this.map = map; + } + + public void enable(int i, boolean enable) + { + for (Hex hex : this) + map.enableOverlayOn(hex, i, enable); + } + + @SuppressWarnings("unchecked") + public Collection<Tile> hexAsTiles() + { + return (Collection) this; + } +} diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index e02073d..2a5ff2f 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -12,7 +12,6 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.tankontank.TankOnTank; import ch.asynk.tankontank.engine.Pawn; import ch.asynk.tankontank.engine.PawnSet; -import ch.asynk.tankontank.engine.TileSet; import ch.asynk.tankontank.engine.Board; import ch.asynk.tankontank.engine.Orientation; import ch.asynk.tankontank.engine.Meteorology; @@ -29,7 +28,7 @@ public abstract class Map extends Board private Random rand = new Random(); - public final Board.TileCollection possibleMoves; + public final HexSet possibleMoves; public final PossiblePaths possiblePaths; public final Board.PawnCollection moveablePawns; @@ -65,7 +64,7 @@ public abstract class Map extends Board setup(); - possibleMoves = new TileSet(this, 40); + possibleMoves = new HexSet(this, 40); possiblePaths = new PossiblePaths(this, 10, 20, 5, 10); moveablePawns = new PawnSet(this, 6); @@ -115,7 +114,7 @@ public abstract class Map extends Board possibleMoves.clear(); return 0; } - return collectPossibleMoves(unit, possibleMoves); + return collectPossibleMoves(unit, possibleMoves.hexAsTiles()); } public int togglePossiblePathHex(Hex hex) diff --git a/core/src/ch/asynk/tankontank/game/Zone.java b/core/src/ch/asynk/tankontank/game/Zone.java new file mode 100644 index 0000000..de3a0d9 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/Zone.java @@ -0,0 +1,14 @@ +package ch.asynk.tankontank.game; + +import ch.asynk.tankontank.engine.Orientation; + +public class Zone extends HexSet +{ + public int allowedMoves; + public Orientation orientation; + + public Zone(Map map, int n) + { + super(map, n); + } +} diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java index 4b536f1..a816799 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleCommon.java @@ -4,13 +4,13 @@ import java.util.Random; import java.util.HashMap; import java.util.ArrayList; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.game.Army; import ch.asynk.tankontank.game.Battle; import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.HexSet; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.State.StateType; @@ -28,7 +28,7 @@ public abstract class BattleCommon implements Battle protected ArrayList<Zone> exitZone = new ArrayList<Zone>(); protected HashMap<Unit, Zone> unitEntry = new HashMap<Unit, Zone>(); protected HashMap<Unit, Zone> unitExit = new HashMap<Unit, Zone>(); - protected TileSet objectives; + protected HexSet objectives; public BattleCommon(Factory factory) { diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleCounterAttack.java b/core/src/ch/asynk/tankontank/game/battles/BattleCounterAttack.java index 6b93f9e..324f187 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleCounterAttack.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleCounterAttack.java @@ -1,17 +1,13 @@ package ch.asynk.tankontank.game.battles; -import ch.asynk.tankontank.game.Ctrl; -import ch.asynk.tankontank.game.Map; -import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.Army; import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.Ctrl; +import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; public class BattleCounterAttack extends BattleCommon diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java index be5d820..173e719 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java @@ -1,17 +1,15 @@ package ch.asynk.tankontank.game.battles; +import ch.asynk.tankontank.game.Army; +import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Army; -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.HexSet; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; public class BattleFrontalAssault extends BattleCommon @@ -71,8 +69,8 @@ public class BattleFrontalAssault extends BattleCommon return null; int count = 0; - for (Tile tile : objectives) { - Unit unit = ((Hex) tile).getUnit(); + for (Hex hex : objectives) { + Unit unit = hex.getUnit(); if ((unit != null) && unit.is(Army.US)) count =+ 1; } @@ -87,7 +85,7 @@ public class BattleFrontalAssault extends BattleCommon public void setup(Ctrl ctrl, Map map) { // G9, E6, H4 - objectives = new TileSet(map, 3); + objectives = new HexSet(map, 3); objectives.add(map.getHex(2, 2)); objectives.add(map.getHex(6, 4)); objectives.add(map.getHex(6, 1)); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java index fd5c0d8..e3e9c80 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java @@ -1,17 +1,15 @@ package ch.asynk.tankontank.game.battles; +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.Army; +import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Army; -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.HexSet; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; public class BattleHeadToHead extends BattleCommon @@ -58,8 +56,8 @@ public class BattleHeadToHead extends BattleCommon int player = 0; int opponent = 0; - for (Tile tile : objectives) { - Unit unit = ((Hex) tile).getUnit(); + for (Hex hex : objectives) { + Unit unit = hex.getUnit(); if (unit != null) { if (ctrl.player.isEnemy(unit)) opponent += 1; @@ -83,7 +81,7 @@ public class BattleHeadToHead extends BattleCommon gePlayer.turnEnd(); // B6, E6, H4 - objectives = new TileSet(map, 3); + objectives = new HexSet(map, 3); objectives.add(map.getHex(7, 7)); objectives.add(map.getHex(6, 4)); objectives.add(map.getHex(6, 1)); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java b/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java index 38be856..3430d88 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleLastStand.java @@ -1,17 +1,15 @@ package ch.asynk.tankontank.game.battles; +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.Army; +import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Army; -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.HexSet; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; public class BattleLastStand extends BattleCommon @@ -60,8 +58,8 @@ public class BattleLastStand extends BattleCommon if (unit.isAce()) usPoints += 1; } - for (Tile tile : objectives) { - Unit unit = ((Hex) tile).getUnit(); + for (Hex hex: objectives) { + Unit unit = hex.getUnit(); if ((unit != null) && unit.is(Army.US)) usPoints += 1; } @@ -76,7 +74,7 @@ public class BattleLastStand extends BattleCommon public void setup(Ctrl ctrl, Map map) { // A7, E6, F6, G10 - objectives = new TileSet(map, 4); + objectives = new HexSet(map, 4); objectives.add(map.getHex(7, 8)); objectives.add(map.getHex(6, 4)); objectives.add(map.getHex(5, 3)); diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleNightAction.java b/core/src/ch/asynk/tankontank/game/battles/BattleNightAction.java index 800c884..e712e65 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleNightAction.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleNightAction.java @@ -1,17 +1,15 @@ package ch.asynk.tankontank.game.battles; +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.Army; +import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Army; -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.HexSet; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; import ch.asynk.tankontank.engine.Meteorology; diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java b/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java index 079b69c..9e8a61e 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleStabToTheFlank.java @@ -1,17 +1,15 @@ package ch.asynk.tankontank.game.battles; +import ch.asynk.tankontank.game.Zone; +import ch.asynk.tankontank.game.Army; +import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; -import ch.asynk.tankontank.game.Army; -import ch.asynk.tankontank.game.Player; -import ch.asynk.tankontank.game.State.StateType; +import ch.asynk.tankontank.game.HexSet; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; import ch.asynk.tankontank.game.hud.Position; -import ch.asynk.tankontank.engine.Tile; -import ch.asynk.tankontank.engine.TileSet; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.Orientation; public class BattleStabToTheFlank extends BattleCommon @@ -61,8 +59,8 @@ public class BattleStabToTheFlank extends BattleCommon else usPoints += escaped; - for (Tile tile : objectives) { - Unit unit = ((Hex) tile).getUnit(); + for (Hex hex : objectives) { + Unit unit = hex.getUnit(); if ((unit != null) && unit.is(Army.US)) usPoints += 1; } @@ -97,7 +95,7 @@ public class BattleStabToTheFlank extends BattleCommon public void setup(Ctrl ctrl, Map map) { // F6, E6 - objectives = new TileSet(map, 2); + objectives = new HexSet(map, 2); objectives.add(map.getHex(5, 3)); objectives.add(map.getHex(6, 4)); objectives.enable(Hex.OBJECTIVE, true); diff --git a/core/src/ch/asynk/tankontank/game/states/StateCommon.java b/core/src/ch/asynk/tankontank/game/states/StateCommon.java index e702ce4..2da80ae 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateCommon.java +++ b/core/src/ch/asynk/tankontank/game/states/StateCommon.java @@ -1,6 +1,6 @@ package ch.asynk.tankontank.game.states; -import ch.asynk.tankontank.engine.Zone; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Map; import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.Unit; diff --git a/core/src/ch/asynk/tankontank/game/states/StateDeployment.java b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java index c3944bc..89e97aa 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateDeployment.java +++ b/core/src/ch/asynk/tankontank/game/states/StateDeployment.java @@ -1,9 +1,9 @@ package ch.asynk.tankontank.game.states; import ch.asynk.tankontank.engine.Orientation; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.engine.PawnSet; import ch.asynk.tankontank.game.Hex; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.hud.ActionButtons.Buttons; diff --git a/core/src/ch/asynk/tankontank/game/states/StateEscape.java b/core/src/ch/asynk/tankontank/game/states/StateEscape.java index 7ff9fa8..30af8e5 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateEscape.java +++ b/core/src/ch/asynk/tankontank/game/states/StateEscape.java @@ -1,6 +1,6 @@ package ch.asynk.tankontank.game.states; -import ch.asynk.tankontank.engine.Zone; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; public class StateEscape extends StateCommon diff --git a/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java b/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java index 634ee00..686a388 100644 --- a/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java +++ b/core/src/ch/asynk/tankontank/game/states/StateReinforcement.java @@ -1,7 +1,7 @@ package ch.asynk.tankontank.game.states; -import ch.asynk.tankontank.engine.Zone; import ch.asynk.tankontank.game.Hex; +import ch.asynk.tankontank.game.Zone; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.hud.ActionButtons.Buttons; |