diff options
Diffstat (limited to 'core/src/ch/asynk')
7 files changed, 101 insertions, 89 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/Battle.java b/core/src/ch/asynk/rustanddust/game/Battle.java index 6101b37..93f8ab6 100644 --- a/core/src/ch/asynk/rustanddust/game/Battle.java +++ b/core/src/ch/asynk/rustanddust/game/Battle.java @@ -15,13 +15,11 @@ public interface Battle public Position getHudPosition(); - public void setPlayerIds(int a, int b); - public Player getPlayer(); public Player getOpponent(); - public void init(Ctrl ctrl); + public void init(Ctrl ctrl, int idA, int idB); public boolean actionDone(); diff --git a/core/src/ch/asynk/rustanddust/game/Factory.java b/core/src/ch/asynk/rustanddust/game/Factory.java index 4d67eb5..1d2579a 100644 --- a/core/src/ch/asynk/rustanddust/game/Factory.java +++ b/core/src/ch/asynk/rustanddust/game/Factory.java @@ -103,12 +103,12 @@ public class Factory implements Board.TileBuilder, Disposable return m; } - public Player getPlayer(Army army) + public Player getPlayer(int id, Army army) { if (army == Army.US) - return new Player(game, Army.US, 10); + return new Player(game, id, Army.US, 10); else - return new Player(game, Army.GE, 10); + return new Player(game, id, Army.GE, 10); } public Unit getUnit(UnitId id, boolean hq, boolean ace) diff --git a/core/src/ch/asynk/rustanddust/game/Player.java b/core/src/ch/asynk/rustanddust/game/Player.java index 01ba89f..9ee087a 100644 --- a/core/src/ch/asynk/rustanddust/game/Player.java +++ b/core/src/ch/asynk/rustanddust/game/Player.java @@ -6,7 +6,7 @@ public class Player { private static final float MOVE_TIME = 0.4f; - public int _id; + private int id; private int turn; private int apSpent; private int actionPoints; @@ -23,8 +23,9 @@ public class Player public int engagementWon; public int engagementLost; - public Player(final RustAndDust game, Army army, int n) + public Player(final RustAndDust game, int id, Army army, int n) { + this.id = id; this.army = army; this.units = new UnitList(n); this.casualties = new UnitList(n); @@ -40,6 +41,11 @@ public class Player this.engagementLost = 0; } + public int getId() + { + return id; + } + public String getName() { return army.toString(); diff --git a/core/src/ch/asynk/rustanddust/game/battles/Battle00.java b/core/src/ch/asynk/rustanddust/game/battles/Battle00.java index a345e02..4381303 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/Battle00.java +++ b/core/src/ch/asynk/rustanddust/game/battles/Battle00.java @@ -25,6 +25,13 @@ public class Battle00 extends BattleCommon } @Override + protected void setPlayers(int idA, int idB) + { + a = factory.getPlayer(idA, Army.US); + b = factory.getPlayer(idB, Army.GE); + } + + @Override public Position getHudPosition() { return (currentPlayer.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); @@ -43,12 +50,6 @@ public class Battle00 extends BattleCommon } @Override - protected Player getFirstPlayer() - { - return usPlayer; - } - - @Override protected void setupMap() { map.addHoldObjective(5, 2, Army.NONE); @@ -56,9 +57,17 @@ public class Battle00 extends BattleCommon } @Override - protected void setupUS() + protected void setupPlayer() + { + if (currentPlayer.army == Army.US) + setupUS(currentPlayer); + else + setupGE(currentPlayer); + } + + private void setupUS(final Player p) { - setUnit(map, usPlayer, UnitId.US_AT_GUN, 11, 7, Orientation.SOUTH, null); + setUnit(map, p, UnitId.US_AT_GUN, 11, 7, Orientation.SOUTH, null); Zone usEntry = new Zone(map, 10); usEntry.orientation = Orientation.SOUTH; @@ -73,18 +82,17 @@ public class Battle00 extends BattleCommon usEntry.add(10, 4); usEntry.add(11, 4); addEntryZone(usEntry); - addReinforcement(usPlayer, usEntry, UnitId.US_SHERMAN, true, false); - addReinforcement(usPlayer, usEntry, UnitId.US_SHERMAN); - addReinforcement(usPlayer, usEntry, UnitId.US_SHERMAN); - addReinforcement(usPlayer, usEntry, UnitId.US_SHERMAN); - addReinforcement(usPlayer, usEntry, UnitId.US_WOLVERINE, true, false); - addReinforcement(usPlayer, usEntry, UnitId.US_WOLVERINE); - addReinforcement(usPlayer, usEntry, UnitId.US_PERSHING); - addReinforcement(usPlayer, usEntry, UnitId.US_PRIEST); + addReinforcement(p, usEntry, UnitId.US_SHERMAN, true, false); + addReinforcement(p, usEntry, UnitId.US_SHERMAN); + addReinforcement(p, usEntry, UnitId.US_SHERMAN); + addReinforcement(p, usEntry, UnitId.US_SHERMAN); + addReinforcement(p, usEntry, UnitId.US_WOLVERINE, true, false); + addReinforcement(p, usEntry, UnitId.US_WOLVERINE); + addReinforcement(p, usEntry, UnitId.US_PERSHING); + addReinforcement(p, usEntry, UnitId.US_PRIEST); } - @Override - protected void setupGE() + private void setupGE(final Player p) { Zone geEntry = new Zone(map, 8); geEntry.orientation = Orientation.NORTH; @@ -97,12 +105,12 @@ public class Battle00 extends BattleCommon geEntry.add(3, 5); geEntry.add(4, 5); addEntryZone(geEntry); - addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV, true, false); - addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV); - addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV); - addReinforcement(gePlayer, geEntry, UnitId.GE_PANZER_IV, true, false); - addReinforcement(gePlayer, geEntry, UnitId.GE_TIGER); - addReinforcement(gePlayer, geEntry, UnitId.GE_TIGER); - addReinforcement(gePlayer, geEntry, UnitId.GE_WESPE); + addReinforcement(p, geEntry, UnitId.GE_PANZER_IV, true, false); + addReinforcement(p, geEntry, UnitId.GE_PANZER_IV); + addReinforcement(p, geEntry, UnitId.GE_PANZER_IV); + addReinforcement(p, geEntry, UnitId.GE_PANZER_IV, true, false); + addReinforcement(p, geEntry, UnitId.GE_TIGER); + addReinforcement(p, geEntry, UnitId.GE_TIGER); + addReinforcement(p, geEntry, UnitId.GE_WESPE); } } diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java index a6a5c50..dd62093 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java @@ -30,8 +30,8 @@ public abstract class BattleCommon implements Battle protected String description; protected Map map; protected Player currentPlayer; - protected Player usPlayer; - protected Player gePlayer; + protected Player a; + protected Player b; protected IterableArray<Zone> entryZones = new IterableArray<Zone>(10); protected IterableArray<Zone> exitZones = new IterableArray<Zone>(10); protected HashMap<Unit, Zone> unitEntry = new HashMap<Unit, Zone>(); @@ -39,9 +39,8 @@ public abstract class BattleCommon implements Battle protected abstract Player getWinner(); protected abstract void setupMap(); - protected abstract void setupUS(); - protected abstract void setupGE(); - protected abstract Player getFirstPlayer(); + protected abstract void setupPlayer(); + protected abstract void setPlayers(int idA, int idB); private int d6() { @@ -95,27 +94,26 @@ public abstract class BattleCommon implements Battle } @Override - public void init(Ctrl ctrl) + public void init(Ctrl ctrl, int idA, int idB) { ctrl.map = this.map = factory.getMap(getMapType()); - this.usPlayer = factory.getPlayer(Army.US); - this.gePlayer = factory.getPlayer(Army.GE); + setPlayers(idA, idB); setupMap(); - this.currentPlayer = this.usPlayer; - setupUS(); + this.currentPlayer = this.a; + setupPlayer(); map.actionDone(); map.turnDone(); currentPlayer.turnEnd(); - this.currentPlayer = this.gePlayer; - setupGE(); + this.currentPlayer = this.b; + setupPlayer(); map.actionDone(); map.turnDone(); currentPlayer.turnEnd(); - this.currentPlayer = getFirstPlayer(); + this.currentPlayer = this.a; } @Override @@ -154,32 +152,26 @@ public abstract class BattleCommon implements Battle if (!turnDoneForBoth()) return null; - if (gePlayer.unitsLeft() == 0) - return usPlayer; - if (usPlayer.unitsLeft() == 0) - return gePlayer; + if (a.unitsLeft() == 0) + return b; + if (b.unitsLeft() == 0) + return a; - if (gePlayer.getTurn() <= minTurns) + if (a.getTurn() <= minTurns) return null; - usPlayer.objectivesWon = map.objectivesCount(Army.US); - gePlayer.objectivesWon = map.objectivesCount(Army.GE); + a.objectivesWon = map.objectivesCount(a.army); + b.objectivesWon = map.objectivesCount(b.army); - if (usPlayer.objectivesWon > gePlayer.objectivesWon) - return usPlayer; - else if (usPlayer.objectivesWon < gePlayer.objectivesWon) - return gePlayer; + if (a.objectivesWon > b.objectivesWon) + return a; + else if (a.objectivesWon < b.objectivesWon) + return b; return null; } - public void setPlayerIds(int a, int b) - { - usPlayer._id = a; - gePlayer._id = b; - } - @Override public Player getPlayer() { @@ -189,7 +181,7 @@ public abstract class BattleCommon implements Battle @Override public Player getOpponent() { - return ((currentPlayer == usPlayer) ? gePlayer : usPlayer); + return ((currentPlayer == a) ? b : a); } @Override diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java index f54ed43..8f65575 100644 --- a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java +++ b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java @@ -22,21 +22,22 @@ public class BattleTest extends BattleCommon } @Override - public Position getHudPosition() + protected void setPlayers(int idA, int idB) { - return (currentPlayer.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); + a = factory.getPlayer(idA, Army.GE); + b = factory.getPlayer(idB, Army.US); } @Override - public Player getWinner() + public Position getHudPosition() { - return getWinner(4); + return (currentPlayer.is(Army.US) ? Position.TOP_RIGHT: Position.TOP_LEFT); } @Override - protected Player getFirstPlayer() + public Player getWinner() { - return gePlayer; + return getWinner(4); } @Override @@ -51,7 +52,7 @@ public class BattleTest extends BattleCommon usEntry.allowedMoves = (Orientation.SOUTH.s | Orientation.SOUTH_EAST.s | Orientation.SOUTH_WEST.s); usEntry.add(map.getHex(12, 6)); addEntryZone(usEntry); - addReinforcement(usPlayer, usEntry, usExit, UnitId.US_WOLVERINE); + addReinforcement(currentPlayer, usEntry, usExit, UnitId.US_WOLVERINE); return true; } @@ -66,13 +67,21 @@ public class BattleTest extends BattleCommon } @Override - protected void setupGE() + protected void setupPlayer() + { + if (currentPlayer.army == Army.US) + setupUS(currentPlayer); + else + setupGE(currentPlayer); + } + + private void setupGE(final Player p) { - setUnit(map, gePlayer, UnitId.GE_WESPE, 6, 8, Orientation.NORTH, null); - setUnit(map, gePlayer, UnitId.GE_TIGER, 5, 2, Orientation.NORTH, null); - setUnit(map, gePlayer, UnitId.GE_PANZER_IV, 4, 5, Orientation.NORTH_WEST, null); - setUnit(map, gePlayer, UnitId.GE_INFANTRY, 1, 2, Orientation.NORTH_WEST, null); - setUnit(map, gePlayer, UnitId.GE_KINGTIGER, 1, 1, Orientation.NORTH_WEST, null); + setUnit(map, p, UnitId.GE_WESPE, 6, 8, Orientation.NORTH, null); + setUnit(map, p, UnitId.GE_TIGER, 5, 2, Orientation.NORTH, null); + setUnit(map, p, UnitId.GE_PANZER_IV, 4, 5, Orientation.NORTH_WEST, null); + setUnit(map, p, UnitId.GE_INFANTRY, 1, 2, Orientation.NORTH_WEST, null); + setUnit(map, p, UnitId.GE_KINGTIGER, 1, 1, Orientation.NORTH_WEST, null); Zone geEntry = new Zone(map, 6); geEntry.orientation = Orientation.NORTH; @@ -81,11 +90,10 @@ public class BattleTest extends BattleCommon geEntry.add(3, 3); geEntry.add(3, 4); addEntryZone(geEntry); - addReinforcement(gePlayer, geEntry, UnitId.GE_AT_GUN); + addReinforcement(p, geEntry, UnitId.GE_AT_GUN); } - @Override - protected void setupUS() + private void setupUS(final Player p) { usExit = new Zone(map, 9); usExit.orientation = Orientation.NORTH; @@ -94,13 +102,13 @@ public class BattleTest extends BattleCommon usExit.add(12, 6); addExitZone(usExit); - usPlayer.casualty(factory.getUnit(UnitId.US_SHERMAN, true, false)); - setUnit(map, usPlayer, UnitId.US_PRIEST, 7, 6, Orientation.SOUTH_EAST, usExit); - setUnit(map, usPlayer, UnitId.US_SHERMAN, 8, 4, Orientation.SOUTH, false, true, usExit); - setUnit(map, usPlayer, UnitId.US_SHERMAN, 7, 3, Orientation.SOUTH, true, false, usExit); - setUnit(map, usPlayer, UnitId.US_WOLVERINE, 11, 7, Orientation.SOUTH_EAST, usExit); - setUnit(map, usPlayer, UnitId.US_PERSHING, 6, 5, Orientation.SOUTH, usExit); - setUnit(map, usPlayer, UnitId.US_INFANTRY, 5, 3, Orientation.NORTH_EAST, usExit); - setUnit(map, usPlayer, UnitId.US_AT_GUN, 6, 1, Orientation.SOUTH, usExit); + p.casualty(factory.getUnit(UnitId.US_SHERMAN, true, false)); + setUnit(map, p, UnitId.US_PRIEST, 7, 6, Orientation.SOUTH_EAST, usExit); + setUnit(map, p, UnitId.US_SHERMAN, 8, 4, Orientation.SOUTH, false, true, usExit); + setUnit(map, p, UnitId.US_SHERMAN, 7, 3, Orientation.SOUTH, true, false, usExit); + setUnit(map, p, UnitId.US_WOLVERINE, 11, 7, Orientation.SOUTH_EAST, usExit); + setUnit(map, p, UnitId.US_PERSHING, 6, 5, Orientation.SOUTH, usExit); + setUnit(map, p, UnitId.US_INFANTRY, 5, 3, Orientation.NORTH_EAST, usExit); + setUnit(map, p, UnitId.US_AT_GUN, 6, 1, Orientation.SOUTH, usExit); } } diff --git a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java index a2b5be1..9d5a20d 100644 --- a/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java +++ b/core/src/ch/asynk/rustanddust/game/ctrl/Solo.java @@ -14,7 +14,7 @@ public class Solo extends Ctrl @Override public void init() { - battle.init(this); + battle.init(this, 0, 1); } @Override |