summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/Board.java4
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java17
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java24
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java28
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java12
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java2
-rw-r--r--test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java13
7 files changed, 62 insertions, 38 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/Board.java b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
index 7c72c25..0a7acf1 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/Board.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
@@ -4,20 +4,20 @@ import com.badlogic.gdx.math.Vector2;
import ch.asynk.gdx.boardgame.Piece;
import ch.asynk.gdx.boardgame.Tile;
-import ch.asynk.gdx.boardgame.tilestorages.TileStorage.TileProvider;
import ch.asynk.gdx.boardgame.tilestorages.TileStorage.TileKeyGenerator;
public interface Board extends TileKeyGenerator
{
public int size();
public int[] getAngles();
+ public Tile getTile(int x, int y);
public boolean isOnMap(int x, int y);
public void centerOf(int x, int y, Vector2 v);
public void toBoard(float x, float y, Vector2 v);
public Tile[] getAdjacents();
- public void buildAdjacents(int x, int y, TileProvider tileProvider);
+ public void buildAdjacents(int x, int y);
enum Geometry
{
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java b/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
index 7813de8..8b17efe 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
@@ -1,6 +1,7 @@
package ch.asynk.gdx.boardgame.boards;
import ch.asynk.gdx.boardgame.Orientation;
+import ch.asynk.gdx.boardgame.tilestorages.TileStorage.TileProvider;
public class BoardFactory
{
@@ -15,29 +16,29 @@ public class BoardFactory
HORIZONTAL,
}
- public static Board getBoard(int cols, int rows, BoardType boardType, float side)
+ public static Board getBoard(int cols, int rows, BoardType boardType, float side, TileProvider tileProvider)
{
- return getBoard(cols, rows, boardType, side, 0f, 0f, BoardOrientation.VERTICAL);
+ return getBoard(cols, rows, boardType, side, 0f, 0f, BoardOrientation.VERTICAL, tileProvider);
}
- public static Board getBoard(int cols, int rows, BoardType boardType, float side, float x0, float y0)
+ public static Board getBoard(int cols, int rows, BoardType boardType, float side, float x0, float y0, TileProvider tileProvider)
{
- return getBoard(cols, rows, boardType, side, x0, y0, BoardOrientation.VERTICAL);
+ return getBoard(cols, rows, boardType, side, x0, y0, BoardOrientation.VERTICAL, tileProvider);
}
- public static Board getBoard(int cols, int rows, BoardType boardType, float side, float x0, float y0, BoardOrientation boardOrientation)
+ public static Board getBoard(int cols, int rows, BoardType boardType, float side, float x0, float y0, BoardOrientation boardOrientation, TileProvider tileProvider)
{
Board board = null;
switch(boardType)
{
case HEX:
- board = new HexBoard(cols, rows, side, x0, y0, boardOrientation);
+ board = new HexBoard(cols, rows, side, x0, y0, boardOrientation, tileProvider);
break;
case SQUARE:
- board = new SquareBoard(cols, rows, side, x0, y0);
+ board = new SquareBoard(cols, rows, side, x0, y0, tileProvider);
break;
case TRIANGLE:
- board = new TriangleBoard(cols, rows, side, x0, y0, boardOrientation);
+ board = new TriangleBoard(cols, rows, side, x0, y0, boardOrientation, tileProvider);
break;
}
if (board == null) {
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index 362efdf..86347d1 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -46,8 +46,9 @@ public class HexBoard implements Board
private static final int [] hAngles = { -1, 30, 90, 150, -1, 210, 270, 330, 30};
private final Tile[] adjacents;
+ private final TileProvider tileProvider;
- public HexBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
+ public HexBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation, TileProvider tileProvider)
{
this.cols = cols;
this.rows = rows;
@@ -55,6 +56,7 @@ public class HexBoard implements Board
this.x0 = x0;
this.y0 = y0;
this.orientation = boardOrientation;
+ this.tileProvider = tileProvider;
this.w = side * 1.73205f;
this.dw = w / 2.0f;
@@ -80,6 +82,12 @@ public class HexBoard implements Board
}
}
+ @Override public Tile getTile(int x, int y)
+ {
+ if (!isOnMap(x, y)) return null;
+ return tileProvider.getTile(x, y);
+ }
+
@Override public int[] getAngles()
{
if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
@@ -91,14 +99,14 @@ public class HexBoard implements Board
@Override public Tile[] getAdjacents() { return adjacents; }
- @Override public void buildAdjacents(int x, int y, TileProvider tileProvider)
+ @Override public void buildAdjacents(int x, int y)
{
- adjacents[0] = tileProvider.getTile(x + 1, y);
- adjacents[1] = tileProvider.getTile(x + 1, y + 1);
- adjacents[2] = tileProvider.getTile(x , y + 1);
- adjacents[3] = tileProvider.getTile(x - 1, y);
- adjacents[4] = tileProvider.getTile(x - 1, y - 1);
- adjacents[5] = tileProvider.getTile(x , y - 1);
+ adjacents[0] = getTile(x + 1, y);
+ adjacents[1] = getTile(x + 1, y + 1);
+ adjacents[2] = getTile(x , y + 1);
+ adjacents[3] = getTile(x - 1, y);
+ adjacents[4] = getTile(x - 1, y - 1);
+ adjacents[5] = getTile(x , y - 1);
}
@Override public int genKey(int x, int y)
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
index d09a39d..3997c1c 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
@@ -18,34 +18,42 @@ public class SquareBoard implements Board
private static final int [] angles = {0, -1, 90, -1, 180, -1, 270, -1, 90};
private final Tile[] adjacents;
+ private final TileProvider tileProvider;
- public SquareBoard(int cols, int rows, float side, float x0, float y0)
+ public SquareBoard(int cols, int rows, float side, float x0, float y0, TileProvider tileProvider)
{
this.cols = cols;
this.rows = rows;
this.side = side;
this.x0 = x0;
this.y0 = y0;
+ this.tileProvider = tileProvider;
this.adjacents = new Tile[8];
}
@Override public int size() { return cols * rows; }
+ @Override public Tile getTile(int x, int y)
+ {
+ if (!isOnMap(x, y)) return null;
+ return tileProvider.getTile(x, y);
+ }
+
@Override public int[] getAngles() { return angles; }
@Override public Tile[] getAdjacents() { return adjacents; }
- @Override public void buildAdjacents(int x, int y, TileProvider tileProvider)
+ @Override public void buildAdjacents(int x, int y)
{
- adjacents[0] = tileProvider.getTile(x + 1, y);
- adjacents[1] = tileProvider.getTile(x + 1, y + 1);
- adjacents[2] = tileProvider.getTile(x , y + 1);
- adjacents[3] = tileProvider.getTile(x - 1, y + 1);
- adjacents[4] = tileProvider.getTile(x - 1, y);
- adjacents[5] = tileProvider.getTile(x - 1, y - 1);
- adjacents[6] = tileProvider.getTile(x , y - 1);
- adjacents[7] = tileProvider.getTile(x + 1, y - 1);
+ adjacents[0] = getTile(x + 1, y);
+ adjacents[1] = getTile(x + 1, y + 1);
+ adjacents[2] = getTile(x , y + 1);
+ adjacents[3] = getTile(x - 1, y + 1);
+ adjacents[4] = getTile(x - 1, y);
+ adjacents[5] = getTile(x - 1, y - 1);
+ adjacents[6] = getTile(x , y - 1);
+ adjacents[7] = getTile(x + 1, y - 1);
}
@Override public int genKey(int x, int y)
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
index c90d351..db3cb5d 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
@@ -26,8 +26,9 @@ public class TriangleBoard implements Board
private static final int [] hAngles = { -1, 30, 90, 150, -1, 210, 270, 330, 30};
private final Tile[] adjacents;
+ private final TileProvider tileProvider;
- public TriangleBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
+ public TriangleBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation, TileProvider tileProvider)
{
this.cols = cols;
this.rows = rows;
@@ -35,6 +36,7 @@ public class TriangleBoard implements Board
this.x0 = x0;
this.y0 = y0;
this.orientation = boardOrientation;
+ this.tileProvider = tileProvider;
this.d = side / 2f;
this.h = side * 0.866f;
@@ -47,6 +49,12 @@ public class TriangleBoard implements Board
@Override public int size() { return cols * rows; }
+ @Override public Tile getTile(int x, int y)
+ {
+ if (!isOnMap(x, y)) return null;
+ return tileProvider.getTile(x, y);
+ }
+
@Override public int[] getAngles()
{
if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
@@ -58,7 +66,7 @@ public class TriangleBoard implements Board
@Override public Tile[] getAdjacents() { return adjacents; }
- @Override public void buildAdjacents(int x, int y, TileProvider tileProvider)
+ @Override public void buildAdjacents(int x, int y)
{
// FIXME
}
diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java
index fc6fc30..b964668 100644
--- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java
+++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java
@@ -40,7 +40,7 @@ public class AnimationsScreen extends AbstractScreen
super(app, "");
this.map = app.assets.getTexture(app.assets.MAP_00);
- this.board = BoardFactory.getBoard(0, 0, BoardFactory.BoardType.HEX, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL);
+ this.board = BoardFactory.getBoard(0, 0, BoardFactory.BoardType.HEX, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL, null);
this.camera = this.cam = new Camera(10, map.getWidth(), map.getHeight(), 1.0f, 0.3f, false);
Piece.angleCorrection = 90;
diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java
index 6d762fa..b48c953 100644
--- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java
+++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java
@@ -130,7 +130,7 @@ public class BoardScreen extends AbstractScreen
private void handleAdjacents()
{
clearAdjacents();
- board.buildAdjacents((int)v.x, (int)v.y, this::getTile);
+ board.buildAdjacents((int)v.x, (int)v.y);
for (Tile tile : board.getAdjacents()) {
if (tile != null) {
tilesToDraw.add(tile);
@@ -146,7 +146,6 @@ public class BoardScreen extends AbstractScreen
private Tile getTile(int x, int y)
{
- if (!board.isOnMap(x, y)) return null;
return tileStorage.getTile(x, y, board::genKey, this::buildTile);
}
@@ -165,7 +164,7 @@ public class BoardScreen extends AbstractScreen
dy = 0;
w = map.getWidth();
h = map.getHeight();
- board = BoardFactory.getBoard(10, 9, BoardFactory.BoardType.HEX, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL);
+ board = BoardFactory.getBoard(10, 9, BoardFactory.BoardType.HEX, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL, this::getTile);
tileStorage = new ArrayTileStorage(board.size());
}
@@ -177,7 +176,7 @@ public class BoardScreen extends AbstractScreen
dy = - dx;
w = map.getHeight();
h = map.getWidth();
- board = BoardFactory.getBoard(9, 10, BoardFactory.BoardType.HEX, 110, 103, 50, BoardFactory.BoardOrientation.HORIZONTAL);
+ board = BoardFactory.getBoard(9, 10, BoardFactory.BoardType.HEX, 110, 103, 50, BoardFactory.BoardOrientation.HORIZONTAL, this::getTile);
tileStorage = new ArrayTileStorage(board.size());
}
@@ -189,7 +188,7 @@ public class BoardScreen extends AbstractScreen
dy = 0;
w = map.getWidth();
h = map.getHeight();
- board = BoardFactory.getBoard(8, 8, BoardFactory.BoardType.SQUARE, 83, 5, 5);
+ board = BoardFactory.getBoard(8, 8, BoardFactory.BoardType.SQUARE, 83, 5, 5, this::getTile);
tileStorage = new ArrayTileStorage(board.size());
}
@@ -201,7 +200,7 @@ public class BoardScreen extends AbstractScreen
dy = 0;
w = map.getWidth();
h = map.getHeight();
- board = BoardFactory.getBoard(21, 8, BoardFactory.BoardType.TRIANGLE, 150, 109, 53, BoardFactory.BoardOrientation.HORIZONTAL);
+ board = BoardFactory.getBoard(21, 8, BoardFactory.BoardType.TRIANGLE, 150, 109, 53, BoardFactory.BoardOrientation.HORIZONTAL, this::getTile);
tileStorage = new ArrayTileStorage(board.size());
}
@@ -213,7 +212,7 @@ public class BoardScreen extends AbstractScreen
dy = - dx;
w = map.getHeight();
h = map.getWidth();
- board = BoardFactory.getBoard(8, 21, BoardFactory.BoardType.TRIANGLE, 150, 16, 110, BoardFactory.BoardOrientation.VERTICAL);
+ board = BoardFactory.getBoard(8, 21, BoardFactory.BoardType.TRIANGLE, 150, 16, 110, BoardFactory.BoardOrientation.VERTICAL, this::getTile);
tileStorage = new ArrayTileStorage(board.size());
}
}