summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-17 00:06:23 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-17 00:06:23 +0200
commit6331ff9a4aeb99a16026c4f3f82f5c5965e26c6f (patch)
tree469974695add6b844de342ad4f8e627843a53b41 /core
parent7251086910912202b31a2a2c0318e7869bc1654d (diff)
downloadRustAndDust-6331ff9a4aeb99a16026c4f3f82f5c5965e26c6f.zip
RustAndDust-6331ff9a4aeb99a16026c4f3f82f5c5965e26c6f.tar.gz
rename
interfaces: Map Tile Pawn implementations: MapImage Hex PawnImage
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/GameFactory.java6
-rw-r--r--core/src/ch/asynk/tankontank/game/Hex.java75
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java (renamed from core/src/ch/asynk/tankontank/game/HexMap.java)6
-rw-r--r--core/src/ch/asynk/tankontank/game/MapHex.java69
-rw-r--r--core/src/ch/asynk/tankontank/game/MapImage.java (renamed from core/src/ch/asynk/tankontank/game/HexMapImage.java)14
-rw-r--r--core/src/ch/asynk/tankontank/game/Pawn.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/PawnImage.java6
-rw-r--r--core/src/ch/asynk/tankontank/game/Tile.java37
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java22
9 files changed, 127 insertions, 110 deletions
diff --git a/core/src/ch/asynk/tankontank/game/GameFactory.java b/core/src/ch/asynk/tankontank/game/GameFactory.java
index 9dfdd6d..961a39a 100644
--- a/core/src/ch/asynk/tankontank/game/GameFactory.java
+++ b/core/src/ch/asynk/tankontank/game/GameFactory.java
@@ -123,13 +123,13 @@ public class GameFactory
{
Map.Config cfg = config();
- Hex[][] board = new Hex[cfg.rows][];
+ Tile[][] board = new Tile[cfg.rows][];
for (int i = 0; i < cfg.rows; i++) {
int c = cfg.cols;
if ((i % 2) == 1) c -= 1;
- board[i] = new Hex[c];
+ board[i] = new Tile[c];
for ( int j = 0; j < c; j ++)
- board[i][j] = new MapHex(MapHex.Terrain.CLEAR);
+ board[i][j] = new Hex(Hex.Terrain.CLEAR);
}
Map m = null;
diff --git a/core/src/ch/asynk/tankontank/game/Hex.java b/core/src/ch/asynk/tankontank/game/Hex.java
index b659b45..e3889f9 100644
--- a/core/src/ch/asynk/tankontank/game/Hex.java
+++ b/core/src/ch/asynk/tankontank/game/Hex.java
@@ -1,24 +1,69 @@
package ch.asynk.tankontank.game;
-public interface Hex
+import java.util.ArrayDeque;
+
+public class Hex implements Tile
{
- public int push(Pawn pawn);
+ public enum Terrain
+ {
+ CLEAR,
+ HILLS,
+ WOODS,
+ TOWN
+ }
+
+ public Terrain terrain;
+ public int roads;
+ private ArrayDeque<Pawn> stack;
+
+ public Hex(Terrain t)
+ {
+ this.terrain = t;
+ this.roads = 0;
+ this.stack = null;
+ }
- public void remove(Pawn pawn);
+ public Hex(Terrain t, int roads)
+ {
+ this.terrain = t;
+ this.roads = roads;
+ this.stack = null;
+ }
- public Pawn getTop();
+ public int costFrom(Side side)
+ {
+ if (side.v == (roads & side.v)) return 1;
+
+ int c = 0;
+ switch(terrain) {
+ case CLEAR:
+ case HILLS:
+ c = 1;
+ break;
+ case WOODS:
+ case TOWN:
+ c = 2;
+ break;
+ }
+
+ return c;
+ }
+
+ public int push(Pawn pawn)
+ {
+ if (stack == null) stack = new ArrayDeque<Pawn>();
+ stack.push(pawn);
+ return stack.size();
+ }
+
+ public void remove(Pawn pawn)
+ {
+ stack.remove(pawn);
+ }
- public enum Orientation
+ public Pawn getTop()
{
- KEEP(0),
- WEST(-90),
- NORTH_WEST(-30),
- NORTH_EAST (30),
- EAST(90),
- SOUTH_EAST(150),
- SOUTH_WEST(-150);
-
- public final int v;
- Orientation(int v) { this.v = v; }
+ if ((stack == null) || (stack.size() == 0)) return null;
+ return stack.getFirst();
}
}
diff --git a/core/src/ch/asynk/tankontank/game/HexMap.java b/core/src/ch/asynk/tankontank/game/Map.java
index 1d751a6..d410502 100644
--- a/core/src/ch/asynk/tankontank/game/HexMap.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -4,7 +4,7 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.GridPoint2;
-public interface HexMap
+public interface Map
{
// libgdx
@@ -23,9 +23,9 @@ public interface HexMap
public void movePawnTo(Pawn pawn, Vector3 coords);
- public void setPawnAt(Pawn pawn, int col, int row, Hex.Orientation o);
+ public void setPawnAt(Pawn pawn, int col, int row, Tile.Orientation o);
- public void movePawnTo(Pawn pawn, int col, int row, Hex.Orientation o);
+ public void movePawnTo(Pawn pawn, int col, int row, Tile.Orientation o);
public class Config
{
diff --git a/core/src/ch/asynk/tankontank/game/MapHex.java b/core/src/ch/asynk/tankontank/game/MapHex.java
deleted file mode 100644
index 6bf9893..0000000
--- a/core/src/ch/asynk/tankontank/game/MapHex.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package ch.asynk.tankontank.game;
-
-import java.util.ArrayDeque;
-
-public class MapHex implements Hex
-{
- public enum Terrain
- {
- CLEAR,
- HILLS,
- WOODS,
- TOWN
- }
-
- public Terrain terrain;
- public int roads;
- private ArrayDeque<Pawn> stack;
-
- public MapHex(Terrain t)
- {
- this.terrain = t;
- this.roads = 0;
- this.stack = null;
- }
-
- public MapHex(Terrain t, int roads)
- {
- this.terrain = t;
- this.roads = roads;
- this.stack = null;
- }
-
- public int costFrom(Side side)
- {
- if (side.v == (roads & side.v)) return 1;
-
- int c = 0;
- switch(terrain) {
- case CLEAR:
- case HILLS:
- c = 1;
- break;
- case WOODS:
- case TOWN:
- c = 2;
- break;
- }
-
- return c;
- }
-
- public int push(Pawn pawn)
- {
- if (stack == null) stack = new ArrayDeque<Pawn>();
- stack.push(pawn);
- return stack.size();
- }
-
- public void remove(Pawn pawn)
- {
- stack.remove(pawn);
- }
-
- public Pawn getTop()
- {
- if ((stack == null) || (stack.size() == 0)) return null;
- return stack.getFirst();
- }
-}
diff --git a/core/src/ch/asynk/tankontank/game/HexMapImage.java b/core/src/ch/asynk/tankontank/game/MapImage.java
index 59e35c3..2bb330d 100644
--- a/core/src/ch/asynk/tankontank/game/HexMapImage.java
+++ b/core/src/ch/asynk/tankontank/game/MapImage.java
@@ -9,15 +9,15 @@ import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.GridPoint2;
-public class HexMapImage extends Image implements HexMap
+public class MapImage extends Image implements Map
{
- private HexMap.Config cfg;
+ private Map.Config cfg;
private int cols;
private int rows;
- private Hex[][] board;
+ private Tile[][] board;
@SuppressWarnings("unchecked")
- public HexMapImage(HexMap.Config cfg, Hex[][] board, Texture texture)
+ public MapImage(Map.Config cfg, Tile[][] board, Texture texture)
{
super(texture);
this.cfg = cfg;
@@ -73,17 +73,17 @@ public class HexMapImage extends Image implements HexMap
public void movePawnTo(Pawn pawn, Vector3 coords)
{
GridPoint2 p = getHexAt(null, coords.x, coords.y);
- movePawnTo(pawn, p.x, p.y, Hex.Orientation.KEEP);
+ movePawnTo(pawn, p.x, p.y, Tile.Orientation.KEEP);
}
- public void setPawnAt(final Pawn pawn, final int col, final int row, Hex.Orientation o)
+ public void setPawnAt(final Pawn pawn, final int col, final int row, Tile.Orientation o)
{
int z = pushPawnAt(pawn, col, row);
Vector2 pos = getPawnPosAt(pawn, col, row);
pawn.pushMove(pos.x, pos.y, z, o);
}
- public void movePawnTo(final Pawn pawn, final int col, final int row, Hex.Orientation o)
+ public void movePawnTo(final Pawn pawn, final int col, final int row, Tile.Orientation o)
{
GridPoint2 prev = getHexAt(pawn.getLastPosition());
// if (prev == null) throw new ();
diff --git a/core/src/ch/asynk/tankontank/game/Pawn.java b/core/src/ch/asynk/tankontank/game/Pawn.java
index 71e225a..8bbdec4 100644
--- a/core/src/ch/asynk/tankontank/game/Pawn.java
+++ b/core/src/ch/asynk/tankontank/game/Pawn.java
@@ -16,7 +16,7 @@ public interface Pawn
public void moveBy(float x, float y);
- public void pushMove(float x, float y, int z, Hex.Orientation o);
+ public void pushMove(float x, float y, int z, Tile.Orientation o);
public void resetMoves(Runnable cb);
diff --git a/core/src/ch/asynk/tankontank/game/PawnImage.java b/core/src/ch/asynk/tankontank/game/PawnImage.java
index 7f06504..d8b6d56 100644
--- a/core/src/ch/asynk/tankontank/game/PawnImage.java
+++ b/core/src/ch/asynk/tankontank/game/PawnImage.java
@@ -28,10 +28,10 @@ public class PawnImage extends Image implements Pawn
return path.getFirst();
}
- public void pushMove(float x, float y, int z, Hex.Orientation r)
+ public void pushMove(float x, float y, int z, Tile.Orientation r)
{
setPosition(x, y);
- if (r != Hex.Orientation.KEEP) setRotation(r.v);
+ if (r != Tile.Orientation.KEEP) setRotation(r.v);
setZIndex(z);
path.push(new Vector3(x, y, r.v));
}
@@ -45,7 +45,7 @@ public class PawnImage extends Image implements Pawn
while(path.size() != 0) {
Vector3 v = path.pop();
seq.addAction(Actions.moveTo(v.x, v.y, MOVE_TIME));
- if (v.z != Hex.Orientation.KEEP.v)
+ if (v.z != Tile.Orientation.KEEP.v)
seq.addAction(Actions.rotateTo(v.z, ROTATE_TIME));
}
diff --git a/core/src/ch/asynk/tankontank/game/Tile.java b/core/src/ch/asynk/tankontank/game/Tile.java
new file mode 100644
index 0000000..a52e728
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/Tile.java
@@ -0,0 +1,37 @@
+package ch.asynk.tankontank.game;
+
+public interface Tile
+{
+ public int push(Pawn pawn);
+
+ public void remove(Pawn pawn);
+
+ public Pawn getTop();
+
+ public enum Orientation
+ {
+ KEEP(0),
+ WEST(-90),
+ NORTH_WEST(-30),
+ NORTH_EAST (30),
+ EAST(90),
+ SOUTH_EAST(150),
+ SOUTH_WEST(-150);
+
+ public final int v;
+ Orientation(int v) { this.v = v; }
+ }
+
+ public enum Side
+ {
+ WEST(1),
+ NORTH_WEST(2),
+ NORTH_EAST (4),
+ EAST(8),
+ SOUTH_EAST(16),
+ SOUTH_WEST(32);
+
+ public final int v;
+ Side(int v) { this.v = v; }
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index 8118489..731db63 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -25,13 +25,17 @@ import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.ScreenViewport;
import ch.asynk.tankontank.TankOnTank;
+
import ch.asynk.tankontank.game.GameFactory;
import ch.asynk.tankontank.game.GameFactory.UnitType;
+
+// interfaces
+import ch.asynk.tankontank.game.Map;
+import ch.asynk.tankontank.game.Tile;
import ch.asynk.tankontank.game.Pawn;
-import ch.asynk.tankontank.game.HexMap;
-import ch.asynk.tankontank.game.Hex;
-import ch.asynk.tankontank.game.HexMapImage;
-import ch.asynk.tankontank.game.Unit;
+
+import ch.asynk.tankontank.game.MapImage; // addActor
+import ch.asynk.tankontank.game.Unit; // addActor
public class GameScreen extends AbstractScreen
{
@@ -43,7 +47,7 @@ public class GameScreen extends AbstractScreen
private float maxZoomOut;
final OrthographicCamera cam;
- private HexMap map;
+ private Map map;
private Image selectedHex;
private Label fps;
@@ -75,11 +79,11 @@ public class GameScreen extends AbstractScreen
// cam.position.set((map.getWidth()/2), (map.getHeight()/2), 0);
gameStage = new Stage(new FitViewport(map.getWidth(), map.getHeight(), cam));
- gameStage.addActor((HexMapImage) map);
+ gameStage.addActor((MapImage) map);
gameStage.addActor(selectedHex);
- Hex.Orientation o = Hex.Orientation.SOUTH_EAST;
+ Tile.Orientation o = Tile.Orientation.SOUTH_EAST;
addUnit(gameStage, UnitType.GE_AT_GUN, 1, 4, o);
addUnit(gameStage, UnitType.GE_INFANTRY, 2, 4, o);
addUnit(gameStage, UnitType.GE_KINGTIGER, 3, 4, o);
@@ -88,7 +92,7 @@ public class GameScreen extends AbstractScreen
addUnit(gameStage, UnitType.GE_TIGER, 6, 4, o);
addUnit(gameStage, UnitType.GE_WESPE, 7, 4, o);
- o = Hex.Orientation.NORTH_WEST;
+ o = Tile.Orientation.NORTH_WEST;
addUnit(gameStage, UnitType.US_AT_GUN, 1, 3, o);
addUnit(gameStage, UnitType.US_INFANTRY, 2, 3, o);
addUnit(gameStage, UnitType.US_PERSHING, 3, 3, o);
@@ -104,7 +108,7 @@ public class GameScreen extends AbstractScreen
Gdx.input.setInputProcessor(getMultiplexer());
}
- private void addUnit(Stage stage, UnitType t, int col, int row, Hex.Orientation o)
+ private void addUnit(Stage stage, UnitType t, int col, int row, Tile.Orientation o)
{
Unit u = GameFactory.getUnit(t);
map.setPawnAt((Pawn) u, col, row, o);