summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-01-23 17:14:05 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2020-01-23 17:14:05 +0100
commit23d0b36568ddd29f799a35f9419e3e132a23ae5c (patch)
treed52dd0c68d34f14921f6865a00ccfb679b480977 /core/src
parent6616325d41ad5a757b1c790974e9a27a0758d70c (diff)
downloadgdx-boardgame-23d0b36568ddd29f799a35f9419e3e132a23ae5c.zip
gdx-boardgame-23d0b36568ddd29f799a35f9419e3e132a23ae5c.tar.gz
Board : add adjacents API, implement it for HEX and Square boards
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/Board.java5
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java19
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java22
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java13
4 files changed, 57 insertions, 2 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/Board.java b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
index 4089e65..38deac7 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/Board.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
@@ -2,6 +2,8 @@ package ch.asynk.gdx.boardgame.boards;
import com.badlogic.gdx.math.Vector2;
+import ch.asynk.gdx.boardgame.Tile;
+import ch.asynk.gdx.boardgame.TileStorage.TileProvider;
import ch.asynk.gdx.boardgame.TileStorage.TileKeyGenerator;
public interface Board extends TileKeyGenerator
@@ -13,6 +15,9 @@ public interface Board extends TileKeyGenerator
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);
+
enum Geometry
{
EUCLIDEAN,
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index 8ab660b..8aba831 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -2,6 +2,9 @@ package ch.asynk.gdx.boardgame.boards;
import com.badlogic.gdx.math.Vector2;
+import ch.asynk.gdx.boardgame.Tile;
+import ch.asynk.gdx.boardgame.TileStorage.TileProvider;
+
public class HexBoard implements Board
{
private final float side; // length of the side of the hex
@@ -42,6 +45,8 @@ public class HexBoard implements Board
private static final int [] vAngles = { 0, 60, -1, 120, 180, 240, -1, 300, 60};
private static final int [] hAngles = { -1, 30, 90, 150, -1, 210, 270, 330, 30};
+ private final Tile[] adjacents;
+
public HexBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{
this.cols = cols;
@@ -62,6 +67,8 @@ public class HexBoard implements Board
} else {
this.tl = (2 * rows - 1);
}
+
+ this.adjacents = new Tile[6];
}
@Override public int size()
@@ -82,6 +89,18 @@ public class HexBoard implements Board
}
}
+ @Override public Tile[] getAdjacents() { return adjacents; }
+
+ @Override public void buildAdjacents(int x, int y, TileProvider tileProvider)
+ {
+ 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);
+ }
+
@Override public int genKey(int x, int y)
{
if (!isOnMap(x, y)) return -1;
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
index b9e2426..2481530 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
@@ -2,6 +2,9 @@ package ch.asynk.gdx.boardgame.boards;
import com.badlogic.gdx.math.Vector2;
+import ch.asynk.gdx.boardgame.Tile;
+import ch.asynk.gdx.boardgame.TileStorage.TileProvider;
+
public class SquareBoard implements Board
{
private final int cols; // # colmuns
@@ -14,6 +17,8 @@ public class SquareBoard implements Board
// [8] is default
private static final int [] angles = {0, -1, 90, -1, 180, -1, 270, -1, 90};
+ private final Tile[] adjacents;
+
public SquareBoard(int cols, int rows, float side, float x0, float y0)
{
this.cols = cols;
@@ -21,13 +26,26 @@ public class SquareBoard implements Board
this.side = side;
this.x0 = x0;
this.y0 = y0;
+
+ this.adjacents = new Tile[8];
}
@Override public int size() { return cols * rows; }
- @Override public int[] getAngles()
+ @Override public int[] getAngles() { return angles; }
+
+ @Override public Tile[] getAdjacents() { return adjacents; }
+
+ @Override public void buildAdjacents(int x, int y, TileProvider tileProvider)
{
- return angles;
+ 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);
}
@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 6cbc69f..eec16ce 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
@@ -2,6 +2,9 @@ package ch.asynk.gdx.boardgame.boards;
import com.badlogic.gdx.math.Vector2;
+import ch.asynk.gdx.boardgame.Tile;
+import ch.asynk.gdx.boardgame.TileStorage.TileProvider;
+
public class TriangleBoard implements Board
{
private final int cols; // # colmuns
@@ -23,6 +26,8 @@ public class TriangleBoard implements Board
private static final int [] vAngles = { 0, 60, -1, 120, 180, 240, -1, 300, 0};
private static final int [] hAngles = { -1, 30, 90, 150, -1, 210, 270, 330, 30};
+ private final Tile[] adjacents;
+
public TriangleBoard(int cols, int rows, float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{
this.cols = cols;
@@ -38,6 +43,8 @@ public class TriangleBoard implements Board
this.h13 = this.h * 0.33333f;
this.h23 = this.h * 0.66666f;
this.h43 = this.h * 1.33333f;
+
+ this.adjacents = new Tile[3];
}
@Override public int size() { return 0; } // FIXME
@@ -51,6 +58,12 @@ public class TriangleBoard implements Board
}
}
+ @Override public Tile[] getAdjacents() { return adjacents; }
+
+ @Override public void buildAdjacents(int x, int y, TileProvider tileProvider) // FIXME
+ {
+ }
+
@Override public int genKey(int x, int y) { return -1; } // FIXME
@Override public boolean isOnMap(int x, int y)