From a745392ca2863e2f5036207e5c4a75e851016737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 12 Oct 2014 11:44:12 +0200 Subject: rename GameFactory -> Factory --- core/src/ch/asynk/tankontank/game/Ctrl.java | 6 +- core/src/ch/asynk/tankontank/game/Factory.java | 181 +++++++++++++++++++++ core/src/ch/asynk/tankontank/game/GameFactory.java | 181 --------------------- core/src/ch/asynk/tankontank/game/Map.java | 2 +- core/src/ch/asynk/tankontank/game/MapA.java | 2 +- core/src/ch/asynk/tankontank/game/MapB.java | 2 +- 6 files changed, 187 insertions(+), 187 deletions(-) create mode 100644 core/src/ch/asynk/tankontank/game/Factory.java delete mode 100644 core/src/ch/asynk/tankontank/game/GameFactory.java diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index bcf41c9..b2920c2 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -34,7 +34,7 @@ public class Ctrl implements Disposable private final TankOnTank game; - private GameFactory factory; + private Factory factory; public Map map; public Hud hud; public Config cfg; @@ -57,8 +57,8 @@ public class Ctrl implements Disposable this.cfg = new Config(); - this.factory = new GameFactory(game.manager); - this.map = factory.getMap(this, game.manager, GameFactory.MapType.MAP_A); + this.factory = new Factory(game.manager); + this.map = factory.getMap(this, game.manager, Factory.MapType.MAP_A); this.usPlayer = factory.getPlayer(Army.US); this.gePlayer = factory.getPlayer(Army.GE); diff --git a/core/src/ch/asynk/tankontank/game/Factory.java b/core/src/ch/asynk/tankontank/game/Factory.java new file mode 100644 index 0000000..5e36f7e --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/Factory.java @@ -0,0 +1,181 @@ +package ch.asynk.tankontank.game; + +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +import com.badlogic.gdx.math.GridPoint2; + +import ch.asynk.tankontank.engine.Board; +import ch.asynk.tankontank.engine.Orientation; + +public class Factory implements Board.TileBuilder, Disposable +{ + private TextureAtlas pawnAtlas; + + public Factory(AssetManager manager) + { + pawnAtlas = manager.get("data/assets.atlas", TextureAtlas.class); + } + + @Override + public void dispose() + { + pawnAtlas.dispose(); + } + + public enum UnitType + { + GE_AT_GUN, + GE_INFANTRY, + GE_KINGTIGER, + GE_PANZER_IV, + GE_PANZER_IV_HQ, + GE_TIGER, + GE_WESPE, + + US_AT_GUN, + US_INFANTRY, + US_PERSHING, + US_PERSHING_HQ, + US_PRIEST, + US_SHERMAN, + US_SHERMAN_HQ, + US_WOLVERINE + } + + public Unit getUnit(UnitType t) + { + Unit u = null; + switch(t) { + case GE_AT_GUN: + u = new Unit(Army.GE, false, 3, 8, 9, 1, pawnAtlas, "ge-at-gun", "head"); + break; + case GE_INFANTRY: + u = new Unit(Army.GE, false, 1, 7, 10, 1, pawnAtlas, "ge-infantry", "head"); + break; + case GE_KINGTIGER: + u = new Unit(Army.GE, false, 3, 12, 1, pawnAtlas, "ge-kingtiger", "head"); + break; + case GE_PANZER_IV: + u = new Unit(Army.GE, false, 2, 9, 2, pawnAtlas, "ge-panzer-iv", "head"); + break; + case GE_PANZER_IV_HQ: + u = new Unit(Army.GE, true, 2, 9, 2, pawnAtlas, "ge-panzer-iv-hq", "head"); + break; + case GE_TIGER: + u = new Unit(Army.GE, false, 3, 11, 1, pawnAtlas, "ge-tiger", "head"); + break; + case GE_WESPE: + u = new Unit(Army.GE, false, 5, 8, 1, pawnAtlas, "ge-wespe", "head"); + break; + case US_AT_GUN: + u = new Unit(Army.US, false, 1, 7, 10, 1, pawnAtlas, "us-at-gun", "head"); + break; + case US_INFANTRY: + u = new Unit(Army.US, false, 1, 7, 10, 1, pawnAtlas, "us-infantry", "head"); + break; + case US_PERSHING: + u = new Unit(Army.US, false, 3, 10, 2, pawnAtlas, "us-pershing", "head"); + break; + case US_PERSHING_HQ: + u = new Unit(Army.US, true, 3, 10, 2, pawnAtlas, "us-pershing-hq", "head"); + break; + case US_PRIEST: + u = new Unit(Army.US, false, 5, 8, 1, pawnAtlas, "us-priest", "head"); + break; + case US_SHERMAN: + u = new Unit(Army.US, false, 2, 9, 2, pawnAtlas, "us-sherman", "us-sherman-head"); + break; + case US_SHERMAN_HQ: + u = new Unit(Army.US, true, 2, 9, 2, pawnAtlas, "us-sherman-hq", "head"); + break; + case US_WOLVERINE: + u = new Unit(Army.US, false, 3, 8, 3, pawnAtlas, "us-wolverine", "head"); + break; + } + + return u; + } + + public enum MapType + { + MAP_A, + MAP_B + } + + private Board.Config config() + { + Board.Config cfg = new Board.Config(); + cfg.cols = 10; + cfg.rows = 9; + cfg.x0 = 272; + cfg.y0 = 182; + cfg.w = 189; + cfg.dw = 94; + cfg.s = 110; + cfg.dh = 53.6f; + cfg.h = cfg.s + cfg.dh; + cfg.slope = (cfg.dh / (float) cfg.dw); + + return cfg; + } + + public Map getMap(Ctrl ctrl, AssetManager manager, MapType t) + { + Board.Config cfg = config(); + + Map m = null; + switch(t) { + case MAP_A: + m = new MapA(ctrl, this, config(), manager.get("data/map_a.png", Texture.class)); + break; + case MAP_B: + m = new MapB(ctrl, this, config(), manager.get("data/map_b.png", Texture.class)); + break; + } + + return m; + } + + public Player getPlayer(Army army) + { + if (army == Army.US) + return new Player(Army.US, pawnAtlas, "us-flag", 10); + else + return new Player(Army.GE, pawnAtlas, "ge-flag", 10); + } + + public Hex getNewTile(float cx, float cy) + { + return new Hex(cx, cy, pawnAtlas); + } + + public Player fakeSetup(Map map, Player gePlayer, Player usPlayer) + { + Orientation o = Orientation.NORTH; + GridPoint2 p = new GridPoint2(); + + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_AT_GUN), p.set(4, 7), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_INFANTRY), p.set(3, 6), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_KINGTIGER), p.set(3, 5), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_PANZER_IV), p.set(2, 4), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_PANZER_IV_HQ), p.set(2, 3), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_TIGER), p.set(1, 2), o)); + gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_WESPE), p.set(1, 1), o)); + + o = Orientation.SOUTH; + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_AT_GUN), p.set(12, 7), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_INFANTRY), p.set(11, 6), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PERSHING), p.set(11, 5), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PERSHING_HQ), p.set(10, 4), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PRIEST), p.set(10, 3), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_SHERMAN), p.set(9, 2), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_SHERMAN_HQ), p.set(9, 1), o)); + usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_WOLVERINE), p.set(8, 0), o)); + + return usPlayer; + } +} diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java deleted file mode 100644 index 3335b20..0000000 --- a/core/src/ch/asynk/tankontank/game/GameFactory.java +++ /dev/null @@ -1,181 +0,0 @@ -package ch.asynk.tankontank.game; - -import com.badlogic.gdx.utils.Disposable; -import com.badlogic.gdx.assets.AssetManager; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.TextureRegion; - -import com.badlogic.gdx.math.GridPoint2; - -import ch.asynk.tankontank.engine.Board; -import ch.asynk.tankontank.engine.Orientation; - -public class GameFactory implements Board.TileBuilder, Disposable -{ - private TextureAtlas pawnAtlas; - - public GameFactory(AssetManager manager) - { - pawnAtlas = manager.get("data/assets.atlas", TextureAtlas.class); - } - - @Override - public void dispose() - { - pawnAtlas.dispose(); - } - - public enum UnitType - { - GE_AT_GUN, - GE_INFANTRY, - GE_KINGTIGER, - GE_PANZER_IV, - GE_PANZER_IV_HQ, - GE_TIGER, - GE_WESPE, - - US_AT_GUN, - US_INFANTRY, - US_PERSHING, - US_PERSHING_HQ, - US_PRIEST, - US_SHERMAN, - US_SHERMAN_HQ, - US_WOLVERINE - } - - public Unit getUnit(UnitType t) - { - Unit u = null; - switch(t) { - case GE_AT_GUN: - u = new Unit(Army.GE, false, 3, 8, 9, 1, pawnAtlas, "ge-at-gun", "head"); - break; - case GE_INFANTRY: - u = new Unit(Army.GE, false, 1, 7, 10, 1, pawnAtlas, "ge-infantry", "head"); - break; - case GE_KINGTIGER: - u = new Unit(Army.GE, false, 3, 12, 1, pawnAtlas, "ge-kingtiger", "head"); - break; - case GE_PANZER_IV: - u = new Unit(Army.GE, false, 2, 9, 2, pawnAtlas, "ge-panzer-iv", "head"); - break; - case GE_PANZER_IV_HQ: - u = new Unit(Army.GE, true, 2, 9, 2, pawnAtlas, "ge-panzer-iv-hq", "head"); - break; - case GE_TIGER: - u = new Unit(Army.GE, false, 3, 11, 1, pawnAtlas, "ge-tiger", "head"); - break; - case GE_WESPE: - u = new Unit(Army.GE, false, 5, 8, 1, pawnAtlas, "ge-wespe", "head"); - break; - case US_AT_GUN: - u = new Unit(Army.US, false, 1, 7, 10, 1, pawnAtlas, "us-at-gun", "head"); - break; - case US_INFANTRY: - u = new Unit(Army.US, false, 1, 7, 10, 1, pawnAtlas, "us-infantry", "head"); - break; - case US_PERSHING: - u = new Unit(Army.US, false, 3, 10, 2, pawnAtlas, "us-pershing", "head"); - break; - case US_PERSHING_HQ: - u = new Unit(Army.US, true, 3, 10, 2, pawnAtlas, "us-pershing-hq", "head"); - break; - case US_PRIEST: - u = new Unit(Army.US, false, 5, 8, 1, pawnAtlas, "us-priest", "head"); - break; - case US_SHERMAN: - u = new Unit(Army.US, false, 2, 9, 2, pawnAtlas, "us-sherman", "us-sherman-head"); - break; - case US_SHERMAN_HQ: - u = new Unit(Army.US, true, 2, 9, 2, pawnAtlas, "us-sherman-hq", "head"); - break; - case US_WOLVERINE: - u = new Unit(Army.US, false, 3, 8, 3, pawnAtlas, "us-wolverine", "head"); - break; - } - - return u; - } - - public enum MapType - { - MAP_A, - MAP_B - } - - private Board.Config config() - { - Board.Config cfg = new Board.Config(); - cfg.cols = 10; - cfg.rows = 9; - cfg.x0 = 272; - cfg.y0 = 182; - cfg.w = 189; - cfg.dw = 94; - cfg.s = 110; - cfg.dh = 53.6f; - cfg.h = cfg.s + cfg.dh; - cfg.slope = (cfg.dh / (float) cfg.dw); - - return cfg; - } - - public Map getMap(Ctrl ctrl, AssetManager manager, MapType t) - { - Board.Config cfg = config(); - - Map m = null; - switch(t) { - case MAP_A: - m = new MapA(ctrl, this, config(), manager.get("data/map_a.png", Texture.class)); - break; - case MAP_B: - m = new MapB(ctrl, this, config(), manager.get("data/map_b.png", Texture.class)); - break; - } - - return m; - } - - public Player getPlayer(Army army) - { - if (army == Army.US) - return new Player(Army.US, pawnAtlas, "us-flag", 10); - else - return new Player(Army.GE, pawnAtlas, "ge-flag", 10); - } - - public Hex getNewTile(float cx, float cy) - { - return new Hex(cx, cy, pawnAtlas); - } - - public Player fakeSetup(Map map, Player gePlayer, Player usPlayer) - { - Orientation o = Orientation.NORTH; - GridPoint2 p = new GridPoint2(); - - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_AT_GUN), p.set(4, 7), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_INFANTRY), p.set(3, 6), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_KINGTIGER), p.set(3, 5), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_PANZER_IV), p.set(2, 4), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_PANZER_IV_HQ), p.set(2, 3), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_TIGER), p.set(1, 2), o)); - gePlayer.addUnit(map.setPawnAt(getUnit(UnitType.GE_WESPE), p.set(1, 1), o)); - - o = Orientation.SOUTH; - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_AT_GUN), p.set(12, 7), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_INFANTRY), p.set(11, 6), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PERSHING), p.set(11, 5), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PERSHING_HQ), p.set(10, 4), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_PRIEST), p.set(10, 3), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_SHERMAN), p.set(9, 2), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_SHERMAN_HQ), p.set(9, 1), o)); - usPlayer.addUnit(map.setPawnAt(getUnit(UnitType.US_WOLVERINE), p.set(8, 0), o)); - - return usPlayer; - } -} diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java index 85a4f59..7c1bdbe 100644 --- a/core/src/ch/asynk/tankontank/game/Map.java +++ b/core/src/ch/asynk/tankontank/game/Map.java @@ -30,7 +30,7 @@ public abstract class Map extends Board protected abstract void setup(); - public Map(Ctrl ctrl, GameFactory factory, Board.Config cfg, Texture texture) + public Map(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture) { super(factory, cfg, texture); this.ctrl = ctrl; diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java index d76192e..ea3c964 100644 --- a/core/src/ch/asynk/tankontank/game/MapA.java +++ b/core/src/ch/asynk/tankontank/game/MapA.java @@ -8,7 +8,7 @@ import ch.asynk.tankontank.engine.Orientation; public class MapA extends Map { - public MapA(Ctrl ctrl, GameFactory factory, Board.Config cfg, Texture texture) + public MapA(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture) { super(ctrl, factory, cfg, texture); } diff --git a/core/src/ch/asynk/tankontank/game/MapB.java b/core/src/ch/asynk/tankontank/game/MapB.java index 46927a6..34f8fe9 100644 --- a/core/src/ch/asynk/tankontank/game/MapB.java +++ b/core/src/ch/asynk/tankontank/game/MapB.java @@ -8,7 +8,7 @@ import ch.asynk.tankontank.engine.Orientation; public class MapB extends Map { - public MapB(Ctrl ctrl, GameFactory factory, Board.Config cfg, Texture texture) + public MapB(Ctrl ctrl, Factory factory, Board.Config cfg, Texture texture) { super(ctrl, factory, cfg, texture); } -- cgit v1.1-2-g2b99