diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-03-08 10:57:22 -0400 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-03-08 10:57:22 -0400 |
commit | eeee11b2ace3af986173bf7b6d2bc2a1eae97a1b (patch) | |
tree | 5f64bb0f7b7224df3627edb8608eb6ecdc72d042 /src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | |
parent | c8806150aae0f1d5f54b285ed773d1521ded20a5 (diff) | |
download | fourpuzzle-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/fourpuzzle/gamestate/mapview/event/AbstractEvent.java')
-rwxr-xr-x | src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java | 31 |
1 files changed, 17 insertions, 14 deletions
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; | |||
9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; | 9 | import com.fourisland.fourpuzzle.gamestate.mapview.Map; |
10 | import com.fourisland.fourpuzzle.util.Functions; | 10 | import com.fourisland.fourpuzzle.util.Functions; |
11 | import java.awt.Point; | 11 | import java.awt.Point; |
12 | import java.util.ArrayList; | ||
13 | import 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 | { |