diff options
Diffstat (limited to 'core/src/ch')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/GameCtrl.java | 29 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/GameFactory.java | 43 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Hud.java | 22 |
3 files changed, 62 insertions, 32 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameCtrl.java b/core/src/ch/asynk/tankontank/game/GameCtrl.java index e18b99d..af0f788 100644 --- a/core/src/ch/asynk/tankontank/game/GameCtrl.java +++ b/core/src/ch/asynk/tankontank/game/GameCtrl.java @@ -38,6 +38,9 @@ public class GameCtrl implements Disposable public Map map; public Hud hud; public Config cfg; + public Player gePlayer; + public Player usPlayer; + public Player currentPlayer; private GameState selectState; private GameState pathState; @@ -55,8 +58,9 @@ public class GameCtrl implements Disposable this.cfg = new Config(); this.factory = new GameFactory(game.manager); - this.hud = new Hud(this, game); this.map = factory.getMap(this, game.manager, GameFactory.MapType.MAP_A); + this.usPlayer = factory.getPlayer(Army.US); + this.gePlayer = factory.getPlayer(Army.GE); this.selectState = new GameStateSelect(this, map); this.pathState = new GameStateMove(); @@ -64,8 +68,9 @@ public class GameCtrl implements Disposable this.animationState = new GameStateAnimation(); this.state = selectState; + this.currentPlayer = factory.fakeSetup(map, gePlayer, usPlayer); - factory.fakeSetup(map); + this.hud = new Hud(this, game); } @Override @@ -101,6 +106,15 @@ public class GameCtrl implements Disposable } } + private void nextPlayer() + { + currentPlayer.turnEnd(); + currentPlayer = ((currentPlayer == usPlayer) ? gePlayer : usPlayer); + currentPlayer.turnStart(); + hud.updatePlayer(); + + } + public void setState(GameState.State state) { setState(state, true); @@ -113,6 +127,7 @@ public class GameCtrl implements Disposable switch(state) { case SELECT: this.state = selectState; + checkTurnEnd(); break; case MOVE: this.state = pathState; @@ -130,6 +145,16 @@ public class GameCtrl implements Disposable this.state.enter(normal); } + private void checkTurnEnd() + { + System.err.println(" current player : " + currentPlayer.toString()); + if (map.activatedPawnsCount() > 0) { + currentPlayer.burnDownOneAp(); + } + if (currentPlayer.apExhausted()) + nextPlayer(); + } + public void abort() { state.abort(); diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java index bd4294a..b84715d 100644 --- a/core/src/ch/asynk/tankontank/game/GameFactory.java +++ b/core/src/ch/asynk/tankontank/game/GameFactory.java @@ -140,31 +140,42 @@ public class GameFactory implements Board.TileBuilder, Disposable 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 void fakeSetup(Map map) + public Player fakeSetup(Map map, Player gePlayer, Player usPlayer) { Orientation o = Orientation.NORTH; GridPoint2 p = new GridPoint2(); - map.setPawnAt(getUnit(UnitType.GE_AT_GUN), p.set(4, 7), o); - map.setPawnAt(getUnit(UnitType.GE_INFANTRY), p.set(3, 6), o); - map.setPawnAt(getUnit(UnitType.GE_KINGTIGER), p.set(3, 5), o); - map.setPawnAt(getUnit(UnitType.GE_PANZER_IV), p.set(2, 4), o); - map.setPawnAt(getUnit(UnitType.GE_PANZER_IV_HQ), p.set(2, 3), o); - map.setPawnAt(getUnit(UnitType.GE_TIGER), p.set(1, 2), o); - map.setPawnAt(getUnit(UnitType.GE_WESPE), p.set(1, 1), o); + + 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; - map.setPawnAt(getUnit(UnitType.US_AT_GUN), p.set(12, 7), o); - map.setPawnAt(getUnit(UnitType.US_INFANTRY), p.set(11, 6), o); - map.setPawnAt(getUnit(UnitType.US_PERSHING), p.set(11, 5), o); - map.setPawnAt(getUnit(UnitType.US_PERSHING_HQ), p.set(10, 4), o); - map.setPawnAt(getUnit(UnitType.US_PRIEST), p.set(10, 3), o); - map.setPawnAt(getUnit(UnitType.US_SHERMAN), p.set(9, 2), o); - map.setPawnAt(getUnit(UnitType.US_SHERMAN_HQ), p.set(9, 1), o); - map.setPawnAt(getUnit(UnitType.US_WOLVERINE), p.set(8, 0), o); + 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/Hud.java b/core/src/ch/asynk/tankontank/game/Hud.java index 2273724..ee01a18 100644 --- a/core/src/ch/asynk/tankontank/game/Hud.java +++ b/core/src/ch/asynk/tankontank/game/Hud.java @@ -21,8 +21,6 @@ public class Hud implements Disposable private final TankOnTank game; private final GameCtrl ctrl; - private Image usFlag; - private Image geFlag; private Image flag; public Button moveBtn; @@ -46,18 +44,15 @@ public class Hud implements Disposable TextureAtlas atlas = game.manager.get("data/assets.atlas", TextureAtlas.class); - usFlag = new Image(atlas.findRegion("us-flag")); - geFlag = new Image(atlas.findRegion("ge-flag")); moveBtn = new Button(atlas, "btn-move"); rotateBtn = new Button(atlas, "btn-rotate"); attackBtn = new Button(atlas, "btn-attack"); checkBtn = new Button(atlas, "btn-check"); cancelBtn = new Button(atlas, "btn-cancel"); - flag = usFlag; + updatePlayer(); - usFlag.setPosition(OFFSET, (Gdx.graphics.getHeight() - flag.getHeight() - OFFSET)); - geFlag.setPosition(flag.getX(), flag.getY()); + flag.setPosition(OFFSET, (Gdx.graphics.getHeight() - flag.getHeight() - OFFSET)); // TODO add counters for // - Action Points // - Turn @@ -71,8 +66,6 @@ public class Hud implements Disposable @Override public void dispose() { - usFlag.dispose(); - geFlag.dispose(); moveBtn.dispose(); rotateBtn.dispose(); attackBtn.dispose(); @@ -82,11 +75,6 @@ public class Hud implements Disposable public void animate(float delta) { - elapsed += delta; - if (elapsed > 5f) { - elapsed = 0f; - flag = ((flag == usFlag) ? geFlag : usFlag); - } } public void draw(Batch batch) @@ -99,6 +87,12 @@ public class Hud implements Disposable if (cancelBtn.visible) cancelBtn.getImage().draw(batch); } + public void updatePlayer() + { + flag = ctrl.currentPlayer.getFlag(); + flag.setPosition(OFFSET, (Gdx.graphics.getHeight() - flag.getHeight() - OFFSET)); + } + private float setButton(Button btn, float x, float y) { // btn.setOff(); |