summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java19
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/GameFactory.java84
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java18
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/MapA.java71
6 files changed, 115 insertions, 94 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index dc6ce63..a78e3b0 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -58,7 +58,7 @@ public abstract class Board extends Image implements Disposable
}
private Config cfg;
- private Tile[][] board;
+ protected Tile[][] board;
boolean transform;
private Matrix4 prevTransform;
@@ -72,11 +72,24 @@ public abstract class Board extends Image implements Disposable
private final LinkedHashSet<Tile> tilesToDraw = new LinkedHashSet<Tile>();
protected final LinkedHashSet<Pawn> pawnsToDraw = new LinkedHashSet<Pawn>();
- public Board(Config cfg, Tile[][] board, Texture texture)
+ public Board(Config cfg, Texture texture, Tile tileBuilder)
{
super(texture);
this.cfg = cfg;
- this.board = board;
+
+ this.board = new Tile[cfg.rows][];
+ boolean evenRow = true;
+ for (int i = 0; i < cfg.rows; i++) {
+ float y = cfg.y0 + (i * cfg.h) - cfg.dh;
+ int c = (evenRow ? cfg.cols : cfg.cols - 1);
+ this.board[i] = new Tile[c];
+ for ( int j = 0; j < c; j ++) {
+ float x = cfg.x0 + (j * cfg.w);
+ if (!evenRow) x += cfg.dw;
+ this.board[i][j] = tileBuilder.getNewAt(x, y);
+ }
+ evenRow = !evenRow;
+ }
}
@Override
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java
index d517b27..85987d6 100644
--- a/core/src/ch/asynk/tankontank/engine/Tile.java
+++ b/core/src/ch/asynk/tankontank/engine/Tile.java
@@ -15,6 +15,8 @@ public abstract class Tile implements BasicDrawable
private StackedImages overlays;
private ArrayDeque<Pawn> stack;
+ public abstract Tile getNewAt(float x, float y);
+
public Tile(TextureAtlas atlas)
{
this.stack = null;
diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java
index 3131b67..43806cf 100644
--- a/core/src/ch/asynk/tankontank/game/GameFactory.java
+++ b/core/src/ch/asynk/tankontank/game/GameFactory.java
@@ -129,99 +129,21 @@ public class GameFactory implements Disposable
return cfg;
}
- public Hex[][] createEmptyBoard(Board.Config cfg)
- {
- Hex[][] board = new Hex[cfg.rows][];
- boolean evenRow = true;
- for (int i = 0; i < cfg.rows; i++) {
- float y = cfg.y0 + (i * cfg.h) - cfg.dh;
- int c = (evenRow ? cfg.cols : cfg.cols - 1);
- board[i] = new Hex[c];
- for ( int j = 0; j < c; j ++) {
- float x = cfg.x0 + (j * cfg.w);
- if (!evenRow) x += cfg.dw;
- Hex hex = new Hex(Hex.Terrain.CLEAR, hexAtlas);
- hex.setPosition(x, y, 0);
- board[i][j] = hex;
- }
- evenRow = !evenRow;
- }
- return board;
- }
-
public Map getMap(AssetManager manager, MapType t)
{
Board.Config cfg = config();
- Hex[][] board = createEmptyBoard(cfg);
-
Map m = null;
switch(t) {
case MAP_A:
- m = new Map(config(), board, manager.get("images/map_a.png", Texture.class));
+ m = new MapA(config(), manager.get("images/map_a.png", Texture.class), hexAtlas);
+ // m = new Map(config(), manager.get("images/map_a.png", Texture.class), hexAtlas);
break;
case MAP_B:
- m = new Map(config(), board, manager.get("images/map_b.png", Texture.class));
+ // m = new Map(config(), manager.get("images/map_b.png", Texture.class), hexAtlas);
break;
}
return m;
}
-
- public void feedMapA(Hex[][] board)
- {
- // board[ row ][ col ]
- board[1][4].terrain = Hex.Terrain.HILLS;
- board[3][5].terrain = Hex.Terrain.HILLS;
- board[8][3].terrain = Hex.Terrain.HILLS;
- board[8][4].terrain = Hex.Terrain.HILLS;
-
- board[0][5].terrain = Hex.Terrain.WOODS;
- board[0][6].terrain = Hex.Terrain.WOODS;
- board[3][1].terrain = Hex.Terrain.WOODS;
- board[3][2].terrain = Hex.Terrain.WOODS;
- board[7][6].terrain = Hex.Terrain.WOODS;
- board[7][7].terrain = Hex.Terrain.WOODS;
- board[8][7].terrain = Hex.Terrain.WOODS;
-
- board[1][5].terrain = Hex.Terrain.TOWN;
- board[2][1].terrain = Hex.Terrain.TOWN;
- board[4][4].terrain = Hex.Terrain.TOWN;
- board[5][7].terrain = Hex.Terrain.TOWN;
- board[6][1].terrain = Hex.Terrain.TOWN;
- board[7][3].terrain = Hex.Terrain.TOWN;
-
- int N = Map.Orientation.NORTH.s;
- int S = Map.Orientation.SOUTH.s;
- int NE = Map.Orientation.NORTH_EAST.s;
- int NW = Map.Orientation.NORTH_WEST.s;
- int SE = Map.Orientation.SOUTH_EAST.s;
- int SW = Map.Orientation.SOUTH_WEST.s;
-
- board[1][5].roads = (NW | SW);
- for (int i = 0; i < 10; i++) {
- if (i == 5)
- board[2][i].roads = (NE | S | SW);
- else if (i == 6)
- board[2][i].roads = (N | SE);
- else
- board[2][i].roads = (N | S);
- }
- board[3][4].roads = (NE | SW);
- board[4][4].roads = (N | NE | SW);
- board[4][5].roads = (N | S);
- board[4][6].roads = (NW | S);
- board[5][3].roads = (NE | SW);
- board[5][5].roads = (N | SW);
- board[5][6].roads = (N | S | NE);
- board[5][7].roads = (N | S);
- board[5][8].roads = (N | S);
- board[6][0].roads = (N | S);
- board[6][1].roads = (N | S);
- board[6][2].roads = (N | S);
- board[6][3].roads = (NE | NW | S);
- board[6][5].roads = (NE | SW);
- board[7][3].roads = (N | SE);
- board[7][4].roads = (NE | S);
- }
}
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index 0fa0587..eb02459 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -15,21 +15,25 @@ public class Hex extends Tile
TOWN
}
+ public static TextureAtlas atlas = null;
+
public Terrain terrain;
public int roads;
- public Hex(Terrain terrain, TextureAtlas atlas)
+ @Override
+ public Hex getNewAt(float x, float y)
{
- super(atlas);
- this.terrain = terrain;
- this.roads = 0;
+ Hex hex = new Hex(atlas);
+ hex.setPosition(x, y, 0);
+ return hex;
}
- public Hex(Terrain terrain, int roads, TextureAtlas atlas)
+ public Hex(TextureAtlas atlas)
{
super(atlas);
- this.terrain = terrain;
- this.roads = roads;
+ this.terrain = Terrain.CLEAR;
+ this.roads = 0;
+ Hex.atlas = atlas;
}
public int costFrom(Board.Orientation side)
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 7271f22..df31c15 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -1,19 +1,28 @@
package ch.asynk.tankontank.game;
import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.GridPoint2;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Pawn;
-public class Map extends Board
+public abstract class Map extends Board
{
private Pawn currentPawn;
private GridPoint2 currentHex = new GridPoint2(-1, -1);
- public Map(Board.Config cfg, Hex[][] board, Texture texture)
+ protected abstract void setup();
+
+ public Map(Board.Config cfg, Texture texture, TextureAtlas hexAtlas)
+ {
+ super(cfg, texture, new Hex(hexAtlas));
+ setup();
+ }
+
+ protected Hex getHex(int col, int row)
{
- super(cfg, board, texture);
+ return (Hex) board[row][col];
}
public boolean drag(float dx, float dy)
diff --git a/core/src/ch/asynk/tankontank/game/MapA.java b/core/src/ch/asynk/tankontank/game/MapA.java
new file mode 100644
index 0000000..bef711d
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/MapA.java
@@ -0,0 +1,71 @@
+package ch.asynk.tankontank.game;
+
+import com.badlogic.gdx.graphics.Texture;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+
+import ch.asynk.tankontank.engine.Board;
+
+public class MapA extends Map
+{
+ public MapA(Board.Config cfg, Texture texture, TextureAtlas hexAtlas)
+ {
+ super(cfg, texture, hexAtlas);
+ }
+
+ @Override
+ protected void setup()
+ {
+ getHex(4, 1).terrain = Hex.Terrain.HILLS;
+ getHex(5, 3).terrain = Hex.Terrain.HILLS;
+ getHex(3, 8).terrain = Hex.Terrain.HILLS;
+ getHex(4, 8).terrain = Hex.Terrain.HILLS;
+
+ getHex(5, 0).terrain = Hex.Terrain.WOODS;
+ getHex(6, 0).terrain = Hex.Terrain.WOODS;
+ getHex(1, 3).terrain = Hex.Terrain.WOODS;
+ getHex(2, 3).terrain = Hex.Terrain.WOODS;
+ getHex(6, 7).terrain = Hex.Terrain.WOODS;
+ getHex(7, 7).terrain = Hex.Terrain.WOODS;
+ getHex(7, 8).terrain = Hex.Terrain.WOODS;
+
+ getHex(5, 1).terrain = Hex.Terrain.TOWN;
+ getHex(1, 2).terrain = Hex.Terrain.TOWN;
+ getHex(4, 4).terrain = Hex.Terrain.TOWN;
+ getHex(7, 5).terrain = Hex.Terrain.TOWN;
+ getHex(1, 6).terrain = Hex.Terrain.TOWN;
+ getHex(3, 7).terrain = Hex.Terrain.TOWN;
+
+ int N = Map.Orientation.NORTH.s;
+ int S = Map.Orientation.SOUTH.s;
+ int NE = Map.Orientation.NORTH_EAST.s;
+ int NW = Map.Orientation.NORTH_WEST.s;
+ int SE = Map.Orientation.SOUTH_EAST.s;
+ int SW = Map.Orientation.SOUTH_WEST.s;
+
+ getHex(5, 1).roads = (NW | SW);
+ for (int i = 0; i < 10; i++) {
+ if (i == 5)
+ getHex(i, 2).roads = (NE | S | SW);
+ else if (i == 6)
+ getHex(i, 2).roads = (N | SE);
+ else
+ getHex(i, 2).roads = (N | S);
+ }
+ getHex(4, 3).roads = (NE | SW);
+ getHex(4, 4).roads = (N | NE | SW);
+ getHex(5, 4).roads = (N | S);
+ getHex(6, 4).roads = (NW | S);
+ getHex(3, 5).roads = (NE | SW);
+ getHex(5, 5).roads = (N | SW);
+ getHex(6, 5).roads = (N | S | NE);
+ getHex(7, 5).roads = (N | S);
+ getHex(8, 5).roads = (N | S);
+ getHex(0, 6).roads = (N | S);
+ getHex(1, 6).roads = (N | S);
+ getHex(2, 6).roads = (N | S);
+ getHex(3, 6).roads = (NE | NW | S);
+ getHex(5, 6).roads = (NE | SW);
+ getHex(3, 7).roads = (N | SE);
+ getHex(4, 7).roads = (NE | S);
+ }
+}