summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/boards
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-10 06:44:07 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-10 06:44:07 +0200
commitf5c6b7a9b4cc6be2db93ff1f274216b90116fec6 (patch)
treecd04bc836250284ad94824d10b516c6a878d44ec /core/src/ch/asynk/gdx/boardgame/boards
parent909d7771fa7a5e65bc7b11b8674a147620f3350d (diff)
downloadgdx-boardgame-f5c6b7a9b4cc6be2db93ff1f274216b90116fec6.zip
gdx-boardgame-f5c6b7a9b4cc6be2db93ff1f274216b90116fec6.tar.gz
add Orientation
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/boards')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/Board.java1
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java20
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java12
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java7
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java12
5 files changed, 47 insertions, 5 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/Board.java b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
index ab12ce6..1037842 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/Board.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/Board.java
@@ -4,6 +4,7 @@ import com.badlogic.gdx.math.Vector2;
public interface Board
{
+ public int[] getAngles();
public void centerOf(int x, int y, Vector2 v);
public void toBoard(float x, float y, Vector2 v);
}
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java b/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
index ff5ba08..8eba838 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/BoardFactory.java
@@ -1,5 +1,7 @@
package ch.asynk.gdx.boardgame.boards;
+import ch.asynk.gdx.boardgame.Orientation;
+
public class BoardFactory
{
public enum BoardType
@@ -25,16 +27,24 @@ public class BoardFactory
public static Board getBoard(BoardType boardType, float side, float x0, float y0, BoardOrientation boardOrientation)
{
+ Board board = null;
switch(boardType)
{
case HEX:
- return new HexBoard(side, x0, y0, boardOrientation);
+ board = new HexBoard(side, x0, y0, boardOrientation);
+ break;
case SQUARE:
- return new SquareBoard(side, x0, y0);
+ board = new SquareBoard(side, x0, y0);
+ break;
case TRIANGLE:
- return new TriangleBoard(side, x0, y0, boardOrientation);
- default:
- throw new RuntimeException( String.format("%s board type is not implemented yet.", boardType) );
+ board = new TriangleBoard(side, x0, y0, boardOrientation);
+ break;
+ }
+ if (board == null) {
+ throw new RuntimeException( String.format("%s board type is not implemented yet.", boardType) );
}
+ Orientation.setValues(board.getAngles());
+
+ return board;
}
}
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index cd66e5a..30aef0b 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -33,6 +33,9 @@ public class HexBoard implements Board
// rows are vertical°
// bottom left is the left vertice of the most bottom-left horizontal hex side of the map
+ private static final int [] vAngles = {330, -1, 30, 90, 150, -1, 210, 270, 330};
+ private static final int [] hAngles = { 0, 0, 60, -1, 120, 180, 240, -1, 300};
+
public HexBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{
this.side = side;
@@ -47,6 +50,15 @@ public class HexBoard implements Board
this.slope = dh / dw;
}
+ @Override public int[] getAngles()
+ {
+ if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
+ return vAngles;
+ } else {
+ return hAngles;
+ }
+ }
+
@Override public void centerOf(int x, int y, Vector2 v)
{
float cx = this.x0;
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
index 8ad98f7..bfe23a7 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
@@ -8,6 +8,8 @@ public class SquareBoard implements Board
private final float x0; // bottom left x offset
private final float y0; // bottom left y offset
+ private static final int [] angles = { 0, 0, -1, 90, -1, 180, -1, 270, -1};
+
public SquareBoard(float side, float x0, float y0)
{
this.side = side;
@@ -15,6 +17,11 @@ public class SquareBoard implements Board
this.y0 = y0;
}
+ @Override public int[] getAngles()
+ {
+ return angles;
+ }
+
@Override public void centerOf(int x, int y, Vector2 v)
{
float cx = this.x0 + (this.side / 2) + (this.side * x);
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
index dcb6324..f49550d 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
@@ -16,6 +16,9 @@ public class TriangleBoard implements Board
private final float h23; // 2/3 height of the triangle
private final float h43; // 4/3 height of the triangle
+ private static final int [] vAngles = {330, -1, 30, 90, 150, -1, 210, 270, 330};
+ private static final int [] hAngles = { 0, 0, 60, -1, 120, 180, 240, -1, 300};
+
public TriangleBoard(float side, float x0, float y0, BoardFactory.BoardOrientation boardOrientation)
{
this.side = side;
@@ -31,6 +34,15 @@ public class TriangleBoard implements Board
this.h43 = this.h * 1.33333f;
}
+ @Override public int[] getAngles()
+ {
+ if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) {
+ return vAngles;
+ } else {
+ return hAngles;
+ }
+ }
+
@Override public void centerOf(int x, int y, Vector2 v)
{
float cx = this.x0;