summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-08 10:57:22 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-08 10:57:22 -0400
commiteeee11b2ace3af986173bf7b6d2bc2a1eae97a1b (patch)
tree5f64bb0f7b7224df3627edb8608eb6ecdc72d042 /src/com/fourisland
parentc8806150aae0f1d5f54b285ed773d1521ded20a5 (diff)
downloadfourpuzzle-eeee11b2ace3af986173bf7b6d2bc2a1eae97a1b.tar.gz
fourpuzzle-eeee11b2ace3af986173bf7b6d2bc2a1eae97a1b.tar.bz2
fourpuzzle-eeee11b2ace3af986173bf7b6d2bc2a1eae97a1b.zip
Engine: Added a to() method to Direction
to() takes a Point and returns a Point one unit in the specified direction from the original point.
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Direction.java44
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java31
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java2
3 files changed, 63 insertions, 14 deletions
diff --git a/src/com/fourisland/fourpuzzle/Direction.java b/src/com/fourisland/fourpuzzle/Direction.java index 72ea595..658d3ff 100755 --- a/src/com/fourisland/fourpuzzle/Direction.java +++ b/src/com/fourisland/fourpuzzle/Direction.java
@@ -5,6 +5,8 @@
5 5
6package com.fourisland.fourpuzzle; 6package com.fourisland.fourpuzzle;
7 7
8import java.awt.Point;
9
8/** 10/**
9 * 11 *
10 * @author hatkirby 12 * @author hatkirby
@@ -26,6 +28,14 @@ public enum Direction {
26 { 28 {
27 return Direction.East; 29 return Direction.East;
28 } 30 }
31
32 public Point to(Point original)
33 {
34 Point temp = new Point(original);
35 temp.translate(0, -1);
36
37 return temp;
38 }
29 }, 39 },
30 East 40 East
31 { 41 {
@@ -43,6 +53,14 @@ public enum Direction {
43 { 53 {
44 return Direction.South; 54 return Direction.South;
45 } 55 }
56
57 public Point to(Point original)
58 {
59 Point temp = new Point(original);
60 temp.translate(1, 0);
61
62 return temp;
63 }
46 }, 64 },
47 South 65 South
48 { 66 {
@@ -60,6 +78,14 @@ public enum Direction {
60 { 78 {
61 return Direction.West; 79 return Direction.West;
62 } 80 }
81
82 public Point to(Point original)
83 {
84 Point temp = new Point(original);
85 temp.translate(0, 1);
86
87 return temp;
88 }
63 }, 89 },
64 West 90 West
65 { 91 {
@@ -77,6 +103,14 @@ public enum Direction {
77 { 103 {
78 return Direction.North; 104 return Direction.North;
79 } 105 }
106
107 public Point to(Point original)
108 {
109 Point temp = new Point(original);
110 temp.translate(-1, 0);
111
112 return temp;
113 }
80 }; 114 };
81 115
82 /** 116 /**
@@ -99,4 +133,14 @@ public enum Direction {
99 * @return A Direction representing the wanted direction 133 * @return A Direction representing the wanted direction
100 */ 134 */
101 public abstract Direction right(); 135 public abstract Direction right();
136
137 /**
138 * Returns a point one unit in the specified direction away from the
139 * specified point
140 *
141 * @param original The point to move away from
142 * @return A Point representing a space one unit away from the original
143 */
144 public abstract Point to(Point original);
145
102} 146}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index 2933fff..a2616e5 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java
@@ -9,6 +9,8 @@ import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.Map; 9import com.fourisland.fourpuzzle.gamestate.mapview.Map;
10import com.fourisland.fourpuzzle.util.Functions; 10import com.fourisland.fourpuzzle.util.Functions;
11import java.awt.Point; 11import java.awt.Point;
12import java.util.ArrayList;
13import java.util.List;
12 14
13/** 15/**
14 * 16 *
@@ -79,20 +81,7 @@ public abstract class AbstractEvent implements Event {
79 { 81 {
80 setAnimationStep(1); 82 setAnimationStep(1);
81 setMoving(false); 83 setMoving(false);
82 84 setLocation(getDirection().to(getLocation()));
83 if (getDirection() == Direction.North)
84 {
85 setLocation(getLocation().x,getLocation().y-1);
86 } else if (getDirection() == Direction.West)
87 {
88 setLocation(getLocation().x-1,getLocation().y);
89 } else if (getDirection() == Direction.South)
90 {
91 setLocation(getLocation().x,getLocation().y+1);
92 } else if (getDirection() == Direction.East)
93 {
94 setLocation(getLocation().x+1,getLocation().y);
95 }
96 } 85 }
97 } 86 }
98 } 87 }
@@ -112,6 +101,20 @@ public abstract class AbstractEvent implements Event {
112 return false; 101 return false;
113 } 102 }
114 103
104 public List<Direction> getLegalMoves()
105 {
106 List<Direction> temp = new ArrayList<Direction>();
107 for (Direction d : Direction.values())
108 {
109 if (!getParentMap().checkForCollision(this, d))
110 {
111 temp.add(d);
112 }
113 }
114
115 return temp;
116 }
117
115 private Map parentMap = null; 118 private Map parentMap = null;
116 public Map getParentMap() 119 public Map getParentMap()
117 { 120 {
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index 887e52b..e6443c6 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java
@@ -10,6 +10,7 @@ import com.fourisland.fourpuzzle.Layer;
10import com.fourisland.fourpuzzle.gamestate.mapview.Map; 10import com.fourisland.fourpuzzle.gamestate.mapview.Map;
11import java.awt.Graphics; 11import java.awt.Graphics;
12import java.awt.Point; 12import java.awt.Point;
13import java.util.List;
13 14
14/** 15/**
15 * 16 *
@@ -40,6 +41,7 @@ public interface Event {
40 public Layer getLayer(); 41 public Layer getLayer();
41 42
42 public boolean isOccupyingSpace(int x, int y); 43 public boolean isOccupyingSpace(int x, int y);
44 public List<Direction> getLegalMoves();
43 45
44 public void setAnimationStep(int animStep); 46 public void setAnimationStep(int animStep);
45 public int getAnimationStep(); 47 public int getAnimationStep();