summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-06-02 12:32:42 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-06-02 12:32:42 +0200
commit783bfb7a8b085f4373cdcc28fbbac53063ccf68d (patch)
tree6395afa2c90e75a8afb55589c95c1dc06b449ff0 /core/src/ch/asynk
parentf90c02f54895ca34cdc3b391587435262a66a3ec (diff)
downloadgdx-boardgame-783bfb7a8b085f4373cdcc28fbbac53063ccf68d.zip
gdx-boardgame-783bfb7a8b085f4373cdcc28fbbac53063ccf68d.tar.gz
Board,TileStorage : use Tile.OffMap
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java23
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java5
-rw-r--r--core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java5
-rw-r--r--core/src/ch/asynk/gdx/boardgame/tilestorages/TileStorage.java2
4 files changed, 18 insertions, 17 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
index 691382b..7c3febb 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/HexBoard.java
@@ -72,6 +72,8 @@ public class HexBoard implements Board
}
this.adjacents = new Tile[6];
+ for (int i = 0; i < 6; i++)
+ this.adjacents[i] = Tile.OffMap;
}
@Override public int size()
@@ -85,8 +87,7 @@ public class HexBoard implements Board
@Override public Tile getTile(int x, int y)
{
- if (!isOnMap(x, y)) return null;
- return tileProvider.getTile(x, y);
+ return tileProvider.getTile(x, y, isOnMap(x, y));
}
@Override public int[] getAngles()
@@ -350,7 +351,6 @@ public class HexBoard implements Board
int y = y0;
- Tile t = null;
Tile from = getTile(x0, y0);
Tile to = getTile(x1, y1);
tiles.add(from);
@@ -359,8 +359,8 @@ public class HexBoard implements Board
boolean blocked = losBlocked;
y += d;
- t = getTile(x, y);
- if (t != null) {
+ Tile t = getTile(x, y);
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
blocked = (blocked || t.blockLos(from, to));
@@ -368,7 +368,7 @@ public class HexBoard implements Board
x += d;
t = getTile(x, y);
- if (t != null) {
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
blocked = (blocked && t.blockLos(from, to));
@@ -376,7 +376,7 @@ public class HexBoard implements Board
y += d;
t = getTile(x, y);
- if (t != null) {
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = (losBlocked || blocked);
losBlocked = (t.blocked || t.blockLos(from, to));
@@ -395,7 +395,6 @@ public class HexBoard implements Board
int x = x0;
int y = y0;
- Tile t = null;
Tile from = getTile(x0, y0);
Tile to = getTile(x1, y1);
tiles.add(from);
@@ -404,8 +403,8 @@ public class HexBoard implements Board
boolean blocked = losBlocked;
x += dx;
- t = getTile(x, y);
- if (t != null) {
+ Tile t = getTile(x, y);
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
blocked = (blocked || t.blockLos(from, to));
@@ -415,7 +414,7 @@ public class HexBoard implements Board
if (!sig)
x -= dx;
t = getTile(x, y);
- if (t != null) {
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = losBlocked;
blocked = (blocked && t.blockLos(from, to));
@@ -423,7 +422,7 @@ public class HexBoard implements Board
x += dx;
t = getTile(x, y);
- if (t != null) {
+ if (t.isOnMap()) {
tiles.add(t);
t.blocked = (losBlocked || blocked);
losBlocked = (t.blocked || t.blockLos(from, to));
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
index 84eee34..ae3e18b 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/SquareBoard.java
@@ -31,14 +31,15 @@ public class SquareBoard implements Board
this.tileProvider = tileProvider;
this.adjacents = new Tile[8];
+ for (int i = 0; i < 8; i++)
+ this.adjacents[i] = Tile.OffMap;
}
@Override public int size() { return cols * rows; }
@Override public Tile getTile(int x, int y)
{
- if (!isOnMap(x, y)) return null;
- return tileProvider.getTile(x, y);
+ return tileProvider.getTile(x, y, isOnMap(x, y));
}
@Override public int[] getAngles() { return angles; }
diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
index cf3ef07..42bd378 100644
--- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
+++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java
@@ -46,14 +46,15 @@ public class TriangleBoard implements Board
this.h23 = this.h * 0.66666f;
this.adjacents = new Tile[3];
+ for (int i = 0; i < 3; i++)
+ this.adjacents[i] = Tile.OffMap;
}
@Override public int size() { return cols * rows; }
@Override public Tile getTile(int x, int y)
{
- if (!isOnMap(x, y)) return null;
- return tileProvider.getTile(x, y);
+ return tileProvider.getTile(x, y, isOnMap(x, y));
}
@Override public int[] getAngles()
diff --git a/core/src/ch/asynk/gdx/boardgame/tilestorages/TileStorage.java b/core/src/ch/asynk/gdx/boardgame/tilestorages/TileStorage.java
index 405ef2f..0b1f17d 100644
--- a/core/src/ch/asynk/gdx/boardgame/tilestorages/TileStorage.java
+++ b/core/src/ch/asynk/gdx/boardgame/tilestorages/TileStorage.java
@@ -19,7 +19,7 @@ public interface TileStorage
@FunctionalInterface
public interface TileProvider
{
- public Tile getTile(int x, int y);
+ public Tile getTile(int x, int y, boolean isOffMap);
}
Tile getTile(int x, int y, int k, TileFactory tileFactory);