From 591ede163eb28e6c74c584503050fda2a419e815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 23 Jan 2020 17:05:54 +0100 Subject: Board : extends TileKeyGenerator --- core/src/ch/asynk/gdx/boardgame/boards/Board.java | 5 +++-- core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java | 2 +- core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java | 2 +- core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java | 6 +++--- test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/boards/Board.java b/core/src/ch/asynk/gdx/boardgame/boards/Board.java index b1adf1c..f12391a 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/Board.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/Board.java @@ -2,11 +2,12 @@ package ch.asynk.gdx.boardgame.boards; import com.badlogic.gdx.math.Vector2; -public interface Board +import ch.asynk.gdx.boardgame.TileStorage.TileKeyGenerator; + +public interface Board extends TileKeyGenerator { public int[] getAngles(); public int size(); - public int getIdx(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); diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java index 5d7e401..8ab660b 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java @@ -82,7 +82,7 @@ public class HexBoard implements Board } } - @Override public int getIdx(int x, int y) + @Override public int genKey(int x, int y) { if (!isOnMap(x, y)) return -1; if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) { diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java index f7df4ff..b9e2426 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java @@ -30,7 +30,7 @@ public class SquareBoard implements Board return angles; } - @Override public int getIdx(int x, int y) + @Override public int genKey(int x, int y) { return (y * cols + x); } diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java index dfbd42d..6cbc69f 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java @@ -40,9 +40,7 @@ public class TriangleBoard implements Board this.h43 = this.h * 1.33333f; } - // FIXME size() getIdx(int, int) - @Override public int size() { return 1; } - @Override public int getIdx(int x, int y) { return -1; } + @Override public int size() { return 0; } // FIXME @Override public int[] getAngles() { @@ -53,6 +51,8 @@ public class TriangleBoard implements Board } } + @Override public int genKey(int x, int y) { return -1; } // FIXME + @Override public boolean isOnMap(int x, int y) { if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) { diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index 4fb9e6d..0714b8d 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -58,7 +58,7 @@ public class BoardScreen extends AbstractScreen public boolean touch(float x, float y) { board.toBoard(x, y, v); - GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.getIdx((int)v.x, (int)v.y))); + GdxBoardTest.debug("BoardScreen", String.format("touchDown [%d;%d] => [%d;%d] => %d", (int)x, (int)y, (int)v.x, (int)v.y, board.genKey((int)v.x, (int)v.y))); float d0 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TCHEBYCHEV); float d1 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.TAXICAB); float d2 = board.distance((int)pos.x, (int)pos.y, (int)v.x, (int)v.y, Board.Geometry.EUCLIDEAN); -- cgit v1.1-2-g2b99