diff options
-rw-r--r-- | core/src/ch/asynk/zproject/engine/board/BoardFactory.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/zproject/engine/board/SquareBoard.java | 35 |
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); + } +} |