summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:39:52 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:39:52 +0200
commit8dd8abf9372b35e2cc01cbad3e683d13979a1631 (patch)
treefe6646ed3659d241fea817f7ec34217b3c45e7a2 /core
parent3ff7f6af6e3653febd3a58ebb35f3a10b774ad73 (diff)
downloadgdx-boardgame-8dd8abf9372b35e2cc01cbad3e683d13979a1631.zip
gdx-boardgame-8dd8abf9372b35e2cc01cbad3e683d13979a1631.tar.gz
add engine/board/SquareBoard
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/zproject/engine/board/BoardFactory.java4
-rw-r--r--core/src/ch/asynk/zproject/engine/board/SquareBoard.java35
2 files changed, 38 insertions, 1 deletions
diff --git a/core/src/ch/asynk/zproject/engine/board/BoardFactory.java b/core/src/ch/asynk/zproject/engine/board/BoardFactory.java
index 695d33e..b2a39a9 100644
--- a/core/src/ch/asynk/zproject/engine/board/BoardFactory.java
+++ b/core/src/ch/asynk/zproject/engine/board/BoardFactory.java
@@ -6,7 +6,7 @@ public class BoardFactory
{
public enum BoardType
{
- HEX,
+ HEX, SQUARE,
}
public enum BoardOrientation
@@ -31,6 +31,8 @@ public class BoardFactory
{
case HEX:
return new HexBoard(side, x0, y0, boardOrientation);
+ case SQUARE:
+ return new SquareBoard(side, x0, y0);
default:
throw new RuntimeException( String.format("%s board type is not implemented yet.", boardType) );
}
diff --git a/core/src/ch/asynk/zproject/engine/board/SquareBoard.java b/core/src/ch/asynk/zproject/engine/board/SquareBoard.java
new file mode 100644
index 0000000..193329a
--- /dev/null
+++ b/core/src/ch/asynk/zproject/engine/board/SquareBoard.java
@@ -0,0 +1,35 @@
+package ch.asynk.zproject.engine.board;
+
+import com.badlogic.gdx.math.Vector2;
+
+import ch.asynk.zproject.engine.Board;
+
+public class SquareBoard implements Board
+{
+ private float side; // length of the side of a square
+ private float x0; // bottom left x offset
+ private float y0; // bottom left y offset
+
+ public SquareBoard(float side, float x0, float y0)
+ {
+ this.side = side;
+ this.x0 = x0;
+ this.y0 = y0;
+ }
+
+ @Override public void centerOf(int x, int y, Vector2 v)
+ {
+ float cx = this.x0 + (this.side / 2) + (this.side * x);
+ float cy = this.y0 + (this.side / 2) + (this.side * y);
+
+ v.set(cx, cy);
+ }
+
+ @Override public void toBoard(float x, float y, Vector2 v)
+ {
+ int col = (int) ((x - this.x0) / this.side);
+ int row = (int) ((y - this.y0) / this.side);
+
+ v.set(col, row);
+ }
+}