summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-03 10:09:26 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-03 10:09:26 +0200
commitaf5583f825ac4d358d2205f7823d9acdabf6abc2 (patch)
tree7b752402161f06c1ecc744171c8c60eaed79f02f /core/src
parentd00bd315ff06f9b1a30fb988ce3c183c2cfd3b19 (diff)
downloadRustAndDust-af5583f825ac4d358d2205f7823d9acdabf6abc2.zip
RustAndDust-af5583f825ac4d358d2205f7823d9acdabf6abc2.tar.gz
Orientation: add Orientation fromMove(int col0, int row0, int col1, int row1)
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Orientation.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Orientation.java b/core/src/ch/asynk/tankontank/engine/Orientation.java
index 59314dd..d985b9c 100644
--- a/core/src/ch/asynk/tankontank/engine/Orientation.java
+++ b/core/src/ch/asynk/tankontank/engine/Orientation.java
@@ -79,4 +79,22 @@ public enum Orientation
else if ((r > (NORTH_WEST.r - delta)) && (r < (NORTH_WEST.r + delta))) return NORTH_WEST;
else return KEEP;
}
+
+ public static Orientation fromMove(int col0, int row0, int col1, int row1)
+ {
+ int dx = col1 - col0;
+ int dy = row1 - row0;
+
+ if (dy == 0) {
+ if (dx > 0) return Orientation.NORTH;
+ return Orientation.SOUTH;
+ }
+ if (dy > 0) {
+ if (dx > 0) return Orientation.NORTH_WEST;
+ return Orientation.SOUTH_WEST;
+ } else {
+ if (dx > 0) return Orientation.NORTH_EAST;
+ return Orientation.SOUTH_EAST;
+ }
+ }
}