summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/zproject/GameBoard.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:12:03 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-09-13 16:12:03 +0200
commitfa8345b7c6c7c22620117f34ef9fbd63f1004b41 (patch)
tree9e69ebc092f194c261cc73203957c3e48783dd54 /core/src/ch/asynk/zproject/GameBoard.java
parent43147c8440ca5bc0b81e01d14f487811f18d093b (diff)
downloadgdx-boardgame-fa8345b7c6c7c22620117f34ef9fbd63f1004b41.zip
gdx-boardgame-fa8345b7c6c7c22620117f34ef9fbd63f1004b41.tar.gz
Game : add a State, drive board and hud with it
Diffstat (limited to 'core/src/ch/asynk/zproject/GameBoard.java')
-rw-r--r--core/src/ch/asynk/zproject/GameBoard.java59
1 files changed, 39 insertions, 20 deletions
diff --git a/core/src/ch/asynk/zproject/GameBoard.java b/core/src/ch/asynk/zproject/GameBoard.java
index 2b95f47..4d3f774 100644
--- a/core/src/ch/asynk/zproject/GameBoard.java
+++ b/core/src/ch/asynk/zproject/GameBoard.java
@@ -3,24 +3,30 @@ package ch.asynk.zproject;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.Disposable;
+import com.badlogic.gdx.math.Vector2;
import ch.asynk.zproject.engine.Touchable;
+import ch.asynk.zproject.engine.Board;
+import ch.asynk.zproject.engine.board.BoardFactory;
public class GameBoard implements Disposable, Touchable
{
private final Texture map;
+ private Board board;
private int dx;
private int dy;
private int w;
private int h;
private float r;
- private boolean rotate = false;
+
+ private Vector2 v;
public GameBoard(final Assets assets)
{
this.map = assets.getTexture(assets.MAP_00);
- computeValues();
+ this.v = new Vector2();
+ setState(GameScreen.State.UI);
}
@Override public void dispose()
@@ -30,31 +36,44 @@ public class GameBoard implements Disposable, Touchable
@Override public boolean touch(float x, float y)
{
- ZProject.debug("GameBoard", String.format("touchDown : %f %f", x, y));
+ board.toBoard(x, y, v);
+ ZProject.debug("BoardGame", String.format("touchDown [%d;%d] => [%d;%d]", (int)x, (int)y, (int)v.x, (int)v.y));
+ board.centerOf((int)v.x, (int)v.y, v);
+ ZProject.debug("BoardGame", String.format(" => [%d;%d]", (int)v.x, (int)v.y));
return true;
}
- public void setRotate(boolean rotate)
+ public void setState(GameScreen.State state)
{
- this.rotate = rotate;
- computeValues();
+ switch (state) {
+ case UI:
+ case HEX_V:
+ setHEX_V();
+ break;
+ case HEX_H:
+ setHEX_H();
+ break;
+ }
}
- private void computeValues()
+ private void setHEX_V()
{
- if (rotate) {
- r = 90;
- dx = - ( map.getWidth() - map.getHeight() ) / 2;
- dy = - dx;
- w = map.getHeight();
- h = map.getWidth();
- } else {
- r = 0;
- dx = 0;
- dy = 0;
- w = map.getWidth();
- h = map.getHeight();
- }
+ r = 0;
+ dx = 0;
+ dy = 0;
+ w = map.getWidth();
+ h = map.getHeight();
+ this.board = BoardFactory.getBoard(BoardFactory.BoardType.HEX, 10, 9, 110, 50, 103, BoardFactory.BoardOrientation.VERTICAL);
+ }
+
+ private void setHEX_H()
+ {
+ r = 90;
+ dx = - ( map.getWidth() - map.getHeight() ) / 2;
+ dy = - dx;
+ w = map.getHeight();
+ h = map.getWidth();
+ this.board = BoardFactory.getBoard(BoardFactory.BoardType.HEX, 9, 10, 110, 103, 50, BoardFactory.BoardOrientation.HORIZONTAL);
}
public int getWidth()