From 5fc05067bfcb75add378b93df3886a1c621d2ea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 31 May 2020 17:17:07 +0200 Subject: TriangleBoard : fix horizontal negative index --- .../ch/asynk/gdx/boardgame/boards/TriangleBoard.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java index 9b7c4bc..1a16772 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java @@ -47,7 +47,7 @@ public class TriangleBoard implements Board this.adjacents = new Tile[3]; } - @Override public int size() { return 0; } // FIXME + @Override public int size() { return cols * rows; } @Override public int[] getAngles() { @@ -64,17 +64,14 @@ public class TriangleBoard implements Board { } - @Override public int genKey(int x, int y) { return -1; } // FIXME + @Override public int genKey(int x, int y) + { + return (y * cols + x); + } @Override public boolean isOnMap(int x, int y) { - if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) { - if ((y < 0) || (y >= rows)) return false; - if ((x < 0) || (x >= cols)) return false; - } else { - if ((y < 0) || (y >= rows)) return false; - if ((x < -1) || (x >= (cols - 1))) return false; - } + if (x < 0 || x >= cols || y < 0 || y >= rows) return false; return true; } @@ -87,8 +84,8 @@ public class TriangleBoard implements Board cy += (y * this.d); cx += ((x * this.h) + (((x + y) % 2 == 0) ? this.h23 : this.h13)); } else { - cx += (this.d + (x * this.d)); - cy += ((y * this.h) + (((x + y) % 2 == 0) ? this.h13 : this.h23)); + cx += (this.d + ((x -1) * this.d)); + cy += ((y * this.h) + (((x + y) % 2 == 0) ? this.h23 : this.h13)); } v.set(cx, cy); @@ -146,6 +143,7 @@ public class TriangleBoard implements Board col -= 1; } } + col += 1; } v.set(col, row); -- cgit v1.1-2-g2b99