diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-02 12:32:42 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-02 12:32:42 +0200 |
commit | 783bfb7a8b085f4373cdcc28fbbac53063ccf68d (patch) | |
tree | 6395afa2c90e75a8afb55589c95c1dc06b449ff0 /test/src/ch/asynk | |
parent | f90c02f54895ca34cdc3b391587435262a66a3ec (diff) | |
download | gdx-boardgame-783bfb7a8b085f4373cdcc28fbbac53063ccf68d.zip gdx-boardgame-783bfb7a8b085f4373cdcc28fbbac53063ccf68d.tar.gz |
Board,TileStorage : use Tile.OffMap
Diffstat (limited to 'test/src/ch/asynk')
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java | 14 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/HexScreen.java | 11 |
2 files changed, 14 insertions, 11 deletions
diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index d20e52a..de70ce4 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -73,10 +73,10 @@ public class BoardScreen extends AbstractScreen public boolean touch(float x, float y, boolean down) { board.toBoard(x, y, v); - if (!board.isOnMap((int)v.x, (int)v.y)) + Tile tile = board.getTile((int)v.x, (int)v.y); + if (!tile.isOnMap()) return false; if (down) { - Tile tile = getTile((int)v.x, (int)v.y); if (!dragging && panzer.isOn(tile)) { dragging = true; clearAdjacents(); @@ -122,7 +122,7 @@ public class BoardScreen extends AbstractScreen private void clearAdjacents() { for (Tile tile : board.getAdjacents()) { - if (tile != null) { + if (tile.isOnMap()) { tilesToDraw.remove(tile); tile.enableOverlay(12, false); } @@ -134,16 +134,18 @@ public class BoardScreen extends AbstractScreen clearAdjacents(); board.buildAdjacents((int)v.x, (int)v.y); for (Tile tile : board.getAdjacents()) { - if (tile != null) { + if (tile.isOnMap()) { tilesToDraw.add(tile); tile.enableOverlay(12, true); } } } - private Tile getTile(int x, int y) + private Tile getTile(int x, int y, boolean isOnMap) { - return tileStorage.getTile(x, y, board::genKey, this::buildTile); + if (isOnMap) + return tileStorage.getTile(x, y, board::genKey, this::buildTile); + return Tile.OffMap; } private Tile buildTile(int x, int y) diff --git a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java index 2335d4e..ceb601f 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java @@ -149,10 +149,9 @@ public class HexScreen extends AbstractScreen public boolean touch(float x, float y, boolean down) { board.toBoard(x, y, v); - if (!board.isOnMap((int)v.x, (int)v.y)) { - return false; - } Hex hex = getHex((int)v.x, (int)v.y); + if (!hex.isOnMap()) + return false; if (down) { if (!panzer.dragging && panzer.isOn(hex)) { panzer.dragging = true; @@ -223,9 +222,11 @@ public class HexScreen extends AbstractScreen return (Hex) board.getTile(x, y); } - private Tile getTile(int x, int y) + private Tile getTile(int x, int y, boolean isOnMap) { - return tileStorage.getTile(x, y, board::genKey, this::buildTile); + if (isOnMap) + return tileStorage.getTile(x, y, board::genKey, this::buildTile); + return Tile.OffMap; } private Tile buildTile(int x, int y) |