summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-05 11:15:26 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-05 11:15:26 +0200
commitcb35ef7704c53e5f269f700c988ddbcb31134b30 (patch)
treee240925831c907a1cdd0c53f35cea22a44bafa6a /core/src
parent633676e3ca84af32fbdfceb20309e53421ca01e1 (diff)
downloadRustAndDust-cb35ef7704c53e5f269f700c988ddbcb31134b30.zip
RustAndDust-cb35ef7704c53e5f269f700c988ddbcb31134b30.tar.gz
clean up GameState
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/game/GameCtrl.java15
-rw-r--r--core/src/ch/asynk/tankontank/game/GameState.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateCommon.java (renamed from core/src/ch/asynk/tankontank/game/GameStateCommon.java)31
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateDirection.java (renamed from core/src/ch/asynk/tankontank/game/GameStateDirection.java)4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStateNone.java (renamed from core/src/ch/asynk/tankontank/game/GameStateNone.java)8
-rw-r--r--core/src/ch/asynk/tankontank/game/states/GameStatePath.java (renamed from core/src/ch/asynk/tankontank/game/GameStatePath.java)2
6 files changed, 32 insertions, 32 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameCtrl.java b/core/src/ch/asynk/tankontank/game/GameCtrl.java
index cdbced1..577aa02 100644
--- a/core/src/ch/asynk/tankontank/game/GameCtrl.java
+++ b/core/src/ch/asynk/tankontank/game/GameCtrl.java
@@ -2,11 +2,16 @@ package ch.asynk.tankontank.game;
import ch.asynk.tankontank.game.Map;
+import ch.asynk.tankontank.game.states.GameStateCommon;
+import ch.asynk.tankontank.game.states.GameStateNone;
+import ch.asynk.tankontank.game.states.GameStatePath;
+import ch.asynk.tankontank.game.states.GameStateDirection;
+
public class GameCtrl
{
- private GameState noneState = new GameStateNone();
- private GameState pathState = new GameStatePath();
- private GameState directionState = new GameStateDirection();
+ private GameState noneState;
+ private GameState pathState;
+ private GameState directionState ;
private GameState state;
@@ -41,13 +46,13 @@ public class GameCtrl
public void touchDown(float x, float y)
{
- if (GameStateCommon.down(x, y))
+ if (state.downInMap(x, y))
state.touchDown();
}
public void touchUp(float x, float y)
{
- if (GameStateCommon.up(x, y))
+ if (state.upInMap(x, y))
state.touchUp();
}
}
diff --git a/core/src/ch/asynk/tankontank/game/GameState.java b/core/src/ch/asynk/tankontank/game/GameState.java
index af434ef..a66dba1 100644
--- a/core/src/ch/asynk/tankontank/game/GameState.java
+++ b/core/src/ch/asynk/tankontank/game/GameState.java
@@ -11,4 +11,8 @@ public interface GameState
public void touchDown();
public void touchUp();
+
+ public boolean downInMap(float x, float y);
+
+ public boolean upInMap(float x, float y);
}
diff --git a/core/src/ch/asynk/tankontank/game/GameStateCommon.java b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
index 79395eb..d02d345 100644
--- a/core/src/ch/asynk/tankontank/game/GameStateCommon.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateCommon.java
@@ -1,9 +1,13 @@
-package ch.asynk.tankontank.game;
+package ch.asynk.tankontank.game.states;
import com.badlogic.gdx.math.GridPoint2;
import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.Tile;
+import ch.asynk.tankontank.game.Map;
+import ch.asynk.tankontank.game.Hex;
+import ch.asynk.tankontank.game.GameCtrl;
+import ch.asynk.tankontank.game.GameState;
public abstract class GameStateCommon implements GameState
{
@@ -26,35 +30,29 @@ public abstract class GameStateCommon implements GameState
this.map = map;
}
- // downHex
-
- protected static boolean downHexInMap()
+ protected static boolean hexInMap(GridPoint2 hex)
{
- if (downHex.x == -1) return false;
- return !map.isOffMap(downHex);
+ if (hex.x == -1) return false;
+ return !map.isOffMap(hex);
}
- protected static boolean down(float x, float y)
+ public boolean downInMap(float x, float y)
{
map.getHexAt(downHex, x, y);
- return downHexInMap();
+ return hexInMap(downHex);
}
- protected static boolean up(float x, float y)
+ public boolean upInMap(float x, float y)
{
map.getHexAt(upHex, x, y);
- return downHexInMap();
+ return hexInMap(upHex);
}
- // pawn
-
protected void setPawn()
{
pawn = map.getTopPawnAt(hex);
}
- // hex
-
protected void setHex()
{
hex.set(downHex.x, downHex.y);
@@ -74,9 +72,4 @@ public abstract class GameStateCommon implements GameState
{
map.enableOverlayOn(hex, Hex.BLUE, true);
}
-
- // protected Hex getHex(int col, int row)
- // {
- // return (Hex) map.getTile(col, row);
- // }
}
diff --git a/core/src/ch/asynk/tankontank/game/GameStateDirection.java b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
index 1fefb3b..39f3743 100644
--- a/core/src/ch/asynk/tankontank/game/GameStateDirection.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateDirection.java
@@ -1,4 +1,4 @@
-package ch.asynk.tankontank.game;
+package ch.asynk.tankontank.game.states;
import ch.asynk.tankontank.engine.Orientation;
@@ -13,6 +13,7 @@ public class GameStateDirection extends GameStateCommon
public void touchUp()
{
Orientation o = Orientation.KEEP;;
+
if (downHex.y == hex.y) {
if (downHex.x == (hex.x - 1)) {
o = Orientation.SOUTH;
@@ -36,6 +37,7 @@ public class GameStateDirection extends GameStateCommon
if (o != Orientation.KEEP)
map.movePawn(pawn, o);
+
map.enableFinalPath(hex, false);
map.resetPaths();
ctrl.setState(State.NONE, false);
diff --git a/core/src/ch/asynk/tankontank/game/GameStateNone.java b/core/src/ch/asynk/tankontank/game/states/GameStateNone.java
index 6243091..bec92ee 100644
--- a/core/src/ch/asynk/tankontank/game/GameStateNone.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStateNone.java
@@ -1,14 +1,10 @@
-package ch.asynk.tankontank.game;
+package ch.asynk.tankontank.game.states;
import ch.asynk.tankontank.game.Map;
+import ch.asynk.tankontank.game.GameCtrl;
public class GameStateNone extends GameStateCommon
{
- public GameStateNone()
- {
- super();
- }
-
public GameStateNone(GameCtrl ctrl, Map map)
{
super(ctrl, map);
diff --git a/core/src/ch/asynk/tankontank/game/GameStatePath.java b/core/src/ch/asynk/tankontank/game/states/GameStatePath.java
index f9a6016..9ffd111 100644
--- a/core/src/ch/asynk/tankontank/game/GameStatePath.java
+++ b/core/src/ch/asynk/tankontank/game/states/GameStatePath.java
@@ -1,4 +1,4 @@
-package ch.asynk.tankontank.game;
+package ch.asynk.tankontank.game.states;
import com.badlogic.gdx.math.GridPoint2;