summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-27 14:28:43 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-27 14:28:43 -0500
commit9ca53b553cfaf488f7e8e678721bf9e655fa377e (patch)
treefa110584eb1b083fbe0e005ab9f235f3a8f931f1
parentcd6b39590b8aced78fc2f6ed0c345fb9af1960c0 (diff)
downloadfourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.tar.gz
fourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.tar.bz2
fourpuzzle-9ca53b553cfaf488f7e8e678721bf9e655fa377e.zip
Fixed "walk-thru-me" bug
Previously, Map's checkForCollision did not properly check collision and would allow an event to initiate movement to a location another event was already moving to (but wasn't at yet).
-rw-r--r--build-before-profiler.xml69
-rw-r--r--build.xml3
-rw-r--r--nbproject/genfiles.properties3
-rw-r--r--nbproject/profiler-build-impl.xml131
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java67
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java8
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java2
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java20
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java16
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java14
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java1
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java18
-rw-r--r--src/com/fourisland/fourpuzzle/util/Functions.java30
13 files changed, 338 insertions, 44 deletions
diff --git a/build-before-profiler.xml b/build-before-profiler.xml new file mode 100644 index 0000000..6fa8e66 --- /dev/null +++ b/build-before-profiler.xml
@@ -0,0 +1,69 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!-- You may freely edit this file. See commented blocks below for -->
3<!-- some examples of how to customize the build. -->
4<!-- (If you delete it and reopen the project it will be recreated.) -->
5<project name="Four_Puzzle_Library" default="default" basedir=".">
6 <description>Builds, tests, and runs the project Four Puzzle Library.</description>
7 <import file="nbproject/build-impl.xml"/>
8 <!--
9
10 There exist several targets which are by default empty and which can be
11 used for execution of your tasks. These targets are usually executed
12 before and after some main targets. They are:
13
14 -pre-init: called before initialization of project properties
15 -post-init: called after initialization of project properties
16 -pre-compile: called before javac compilation
17 -post-compile: called after javac compilation
18 -pre-compile-single: called before javac compilation of single file
19 -post-compile-single: called after javac compilation of single file
20 -pre-compile-test: called before javac compilation of JUnit tests
21 -post-compile-test: called after javac compilation of JUnit tests
22 -pre-compile-test-single: called before javac compilation of single JUnit test
23 -post-compile-test-single: called after javac compilation of single JUunit test
24 -pre-jar: called before JAR building
25 -post-jar: called after JAR building
26 -post-clean: called after cleaning build products
27
28 (Targets beginning with '-' are not intended to be called on their own.)
29
30 Example of inserting an obfuscator after compilation could look like this:
31
32 <target name="-post-compile">
33 <obfuscate>
34 <fileset dir="${build.classes.dir}"/>
35 </obfuscate>
36 </target>
37
38 For list of available properties check the imported
39 nbproject/build-impl.xml file.
40
41
42 Another way to customize the build is by overriding existing main targets.
43 The targets of interest are:
44
45 -init-macrodef-javac: defines macro for javac compilation
46 -init-macrodef-junit: defines macro for junit execution
47 -init-macrodef-debug: defines macro for class debugging
48 -init-macrodef-java: defines macro for class execution
49 -do-jar-with-manifest: JAR building (if you are using a manifest)
50 -do-jar-without-manifest: JAR building (if you are not using a manifest)
51 run: execution of project
52 -javadoc-build: Javadoc generation
53 test-report: JUnit report generation
54
55 An example of overriding the target for project execution could look like this:
56
57 <target name="run" depends="Four_Puzzle_Library-impl.jar">
58 <exec dir="bin" executable="launcher.exe">
59 <arg file="${dist.jar}"/>
60 </exec>
61 </target>
62
63 Notice that the overridden target depends on the jar target and not only on
64 the compile target as the regular run target does. Again, for a list of available
65 properties which you can use, check the target you are overriding in the
66 nbproject/build-impl.xml file.
67
68 -->
69</project>
diff --git a/build.xml b/build.xml index 6fa8e66..55cda1a 100644 --- a/build.xml +++ b/build.xml
@@ -5,7 +5,8 @@
5<project name="Four_Puzzle_Library" default="default" basedir="."> 5<project name="Four_Puzzle_Library" default="default" basedir=".">
6 <description>Builds, tests, and runs the project Four Puzzle Library.</description> 6 <description>Builds, tests, and runs the project Four Puzzle Library.</description>
7 <import file="nbproject/build-impl.xml"/> 7 <import file="nbproject/build-impl.xml"/>
8 <!-- 8
9 <import file="nbproject/profiler-build-impl.xml"/> <!--
9 10
10 There exist several targets which are by default empty and which can be 11 There exist several targets which are by default empty and which can be
11 used for execution of your tasks. These targets are usually executed 12 used for execution of your tasks. These targets are usually executed
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 5921ab8..391a3ec 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties
@@ -6,3 +6,6 @@ build.xml.stylesheet.CRC32=be360661
6nbproject/build-impl.xml.data.CRC32=15d90fc1 6nbproject/build-impl.xml.data.CRC32=15d90fc1
7nbproject/build-impl.xml.script.CRC32=3013fcc1 7nbproject/build-impl.xml.script.CRC32=3013fcc1
8nbproject/build-impl.xml.stylesheet.CRC32=487672f9 8nbproject/build-impl.xml.stylesheet.CRC32=487672f9
9nbproject/profiler-build-impl.xml.data.CRC32=15d90fc1
10nbproject/profiler-build-impl.xml.script.CRC32=abda56ed
11nbproject/profiler-build-impl.xml.stylesheet.CRC32=42cb6bcf
diff --git a/nbproject/profiler-build-impl.xml b/nbproject/profiler-build-impl.xml new file mode 100644 index 0000000..7c8995d --- /dev/null +++ b/nbproject/profiler-build-impl.xml
@@ -0,0 +1,131 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3*** GENERATED FROM project.xml - DO NOT EDIT ***
4*** EDIT ../build.xml INSTEAD ***
5
6For the purpose of easier reading the script
7is divided into following sections:
8
9 - initialization
10 - profiling
11 - applet profiling
12
13-->
14<project name="-profiler-impl" default="profile" basedir="..">
15 <target name="default" depends="profile" description="Build and profile the project."/>
16 <!--
17 ======================
18 INITIALIZATION SECTION
19 ======================
20 -->
21 <target name="profile-init" depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile, -profile-init-check"/>
22 <target name="-profile-pre-init">
23 <!-- Empty placeholder for easier customization. -->
24 <!-- You can override this target in the ../build.xml file. -->
25 </target>
26 <target name="-profile-post-init">
27 <!-- Empty placeholder for easier customization. -->
28 <!-- You can override this target in the ../build.xml file. -->
29 </target>
30 <target name="-profile-init-macrodef-profile">
31 <macrodef name="resolve">
32 <attribute name="name"/>
33 <attribute name="value"/>
34 <sequential>
35 <property name="@{name}" value="${env.@{value}}"/>
36 </sequential>
37 </macrodef>
38 <macrodef name="profile">
39 <attribute name="classname" default="${main.class}"/>
40 <element name="customize" optional="true"/>
41 <sequential>
42 <property environment="env"/>
43 <resolve name="profiler.current.path" value="${profiler.info.pathvar}"/>
44 <java fork="true" classname="@{classname}" dir="${profiler.info.dir}" jvm="${profiler.info.jvm}">
45 <jvmarg value="${profiler.info.jvmargs.agent}"/>
46 <jvmarg line="${profiler.info.jvmargs}"/>
47 <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
48 <arg line="${application.args}"/>
49 <classpath>
50 <path path="${run.classpath}"/>
51 </classpath>
52 <syspropertyset>
53 <propertyref prefix="run-sys-prop."/>
54 <mapper type="glob" from="run-sys-prop.*" to="*"/>
55 </syspropertyset>
56 <customize/>
57 </java>
58 </sequential>
59 </macrodef>
60 </target>
61 <target name="-profile-init-check" depends="-profile-pre-init, init, -profile-post-init, -profile-init-macrodef-profile">
62 <fail unless="profiler.info.jvm">Must set JVM to use for profiling in profiler.info.jvm</fail>
63 <fail unless="profiler.info.jvmargs.agent">Must set profiler agent JVM arguments in profiler.info.jvmargs.agent</fail>
64 </target>
65 <!--
66 =================
67 PROFILING SECTION
68 =================
69 -->
70 <target name="profile" if="netbeans.home" depends="profile-init,compile" description="Profile a project in the IDE.">
71 <nbprofiledirect>
72 <classpath>
73 <path path="${run.classpath}"/>
74 </classpath>
75 </nbprofiledirect>
76 <profile/>
77 </target>
78 <target name="profile-single" if="netbeans.home" depends="profile-init,compile-single" description="Profile a selected class in the IDE.">
79 <fail unless="profile.class">Must select one file in the IDE or set profile.class</fail>
80 <nbprofiledirect>
81 <classpath>
82 <path path="${run.classpath}"/>
83 </classpath>
84 </nbprofiledirect>
85 <profile classname="${profile.class}"/>
86 </target>
87 <!--
88 =========================
89 APPLET PROFILING SECTION
90 =========================
91 -->
92 <target name="profile-applet" if="netbeans.home" depends="profile-init,compile-single">
93 <nbprofiledirect>
94 <classpath>
95 <path path="${run.classpath}"/>
96 </classpath>
97 </nbprofiledirect>
98 <profile classname="sun.applet.AppletViewer">
99 <customize>
100 <arg value="${applet.url}"/>
101 </customize>
102 </profile>
103 </target>
104 <!--
105 =========================
106 TESTS PROFILING SECTION
107 =========================
108 -->
109 <target name="profile-test-single" if="netbeans.home" depends="profile-init,compile-test-single">
110 <nbprofiledirect>
111 <classpath>
112 <path path="${run.test.classpath}"/>
113 </classpath>
114 </nbprofiledirect>
115 <junit showoutput="true" fork="true" dir="${profiler.info.dir}" jvm="${profiler.info.jvm}" failureproperty="tests.failed" errorproperty="tests.failed">
116 <env key="${profiler.info.pathvar}" path="${profiler.info.agentpath}:${profiler.current.path}"/>
117 <jvmarg value="${profiler.info.jvmargs.agent}"/>
118 <jvmarg line="${profiler.info.jvmargs}"/>
119 <test name="${profile.class}"/>
120 <classpath>
121 <path path="${run.test.classpath}"/>
122 </classpath>
123 <syspropertyset>
124 <propertyref prefix="test-sys-prop."/>
125 <mapper type="glob" from="test-sys-prop.*" to="*"/>
126 </syspropertyset>
127 <formatter type="brief" usefile="false"/>
128 <formatter type="xml"/>
129 </junit>
130 </target>
131</project>
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 3e9c717..62270bf 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java
@@ -20,7 +20,7 @@ public abstract class Map {
20 20
21 public abstract void initalize(); 21 public abstract void initalize();
22 22
23 public void initalize(Dimension size) 23 protected void initalize(Dimension size)
24 { 24 {
25 setSize(size); 25 setSize(size);
26 mapData = new Vector<HashMap<Integer,Integer>>(); 26 mapData = new Vector<HashMap<Integer,Integer>>();
@@ -31,7 +31,7 @@ public abstract class Map {
31 { 31 {
32 return size; 32 return size;
33 } 33 }
34 public void setSize(Dimension size) 34 private void setSize(Dimension size)
35 { 35 {
36 if ((size.width < 20) || (size.height < 15)) 36 if ((size.width < 20) || (size.height < 15))
37 { 37 {
@@ -58,7 +58,7 @@ public abstract class Map {
58 58
59 return null; 59 return null;
60 } 60 }
61 61
62 public boolean checkForCollision(int x, int y, Direction toMove) 62 public boolean checkForCollision(int x, int y, Direction toMove)
63 { 63 {
64 if ((toMove == Direction.North) && (y == 0)) 64 if ((toMove == Direction.North) && (y == 0))
@@ -75,48 +75,22 @@ public abstract class Map {
75 return true; 75 return true;
76 } 76 }
77 77
78 for (LayerEvent ev : events) 78 if ((toMove == Direction.North) && (checkForEventCollision(x, y-1)))
79 {
80 if (ev.getLayer() == Layer.Middle)
81 {
82 if ((ev.getLocation().y == (y - 1)) && (ev.getLocation().x == x) && (toMove == Direction.North))
83 {
84 return true;
85 }
86
87 if ((ev.getLocation().x == (x - 1)) && (ev.getLocation().y == y) && (toMove == Direction.West))
88 {
89 return true;
90 }
91
92 if ((ev.getLocation().y == (y + 1)) && (ev.getLocation().x == x) && (toMove == Direction.South))
93 {
94 return true;
95 }
96
97 if ((ev.getLocation().x == (x + 1)) && (ev.getLocation().y == y) && (toMove == Direction.East))
98 {
99 return true;
100 }
101 }
102 }
103
104 if ((Game.getHeroEvent().getLocation().y == (y - 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.North))
105 { 79 {
106 return true; 80 return true;
107 } 81 }
108 82
109 if ((Game.getHeroEvent().getLocation().x == (x - 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.West)) 83 if ((toMove == Direction.West) && (checkForEventCollision(x-1, y)))
110 { 84 {
111 return true; 85 return true;
112 } 86 }
113 87
114 if ((Game.getHeroEvent().getLocation().y == (y + 1)) && (Game.getHeroEvent().getLocation().x == x) && (toMove == Direction.South)) 88 if ((toMove == Direction.South) && (checkForEventCollision(x, y+1)))
115 { 89 {
116 return true; 90 return true;
117 } 91 }
118 92
119 if ((Game.getHeroEvent().getLocation().x == (x + 1)) && (Game.getHeroEvent().getLocation().y == y) && (toMove == Direction.East)) 93 if ((toMove == Direction.East) && (checkForEventCollision(x+1, y)))
120 { 94 {
121 return true; 95 return true;
122 } 96 }
@@ -156,6 +130,27 @@ public abstract class Map {
156 130
157 return false; 131 return false;
158 } 132 }
133
134 private boolean checkForEventCollision(int x, int y)
135 {
136 for (LayerEvent ev : events)
137 {
138 if (ev.getLayer() == Layer.Middle)
139 {
140 if (ev.isOccupyingSpace(x, y))
141 {
142 return true;
143 }
144 }
145 }
146
147 if (Game.getHeroEvent().isOccupyingSpace(x, y))
148 {
149 return true;
150 }
151
152 return false;
153 }
159 154
160 private String chipSet; 155 private String chipSet;
161 public String getChipSet() { 156 public String getChipSet() {
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 3d8d15d..48653c0 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -159,6 +159,14 @@ public class MapViewGameState implements GameState {
159 159
160 public void render(Graphics2D g) 160 public void render(Graphics2D g)
161 { 161 {
162 /* TODO Add code that checks to see if the map has been switched
163 * or if the hero has moved in such a way so as to move the
164 * viewpoint. If one or more of these conditions are filled, the
165 * already existing below code should run along with a snippet that
166 * saves a cache of the current viewpoint. If not, the previously
167 * mentioned cache should be displayed rather than re-rendering the
168 * map.
169 */
162 ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet()); 170 ChipSet chipSet = ChipSet.getChipSet(currentMap.getChipSet());
163 int i,x,y; 171 int i,x,y;
164 for (i=0;i<currentMap.getMapData().size();i++) 172 for (i=0;i<currentMap.getMapData().size();i++)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index fbcfd7a..71b507f 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java
@@ -32,4 +32,6 @@ public interface Event {
32 public void startMoving(Direction direction); 32 public void startMoving(Direction direction);
33 33
34 public Layer getLayer(); 34 public Layer getLayer();
35
36 public boolean isOccupyingSpace(int x, int y);
35} 37}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 50e16c8..6e8c359 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
@@ -12,6 +12,7 @@ import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.Game; 12import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.GameCharacter; 13import com.fourisland.fourpuzzle.GameCharacter;
14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet; 14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet;
15import com.fourisland.fourpuzzle.util.Functions;
15 16
16/** 17/**
17 * 18 *
@@ -65,6 +66,10 @@ public class HeroEvent implements Event {
65 } 66 }
66 } 67 }
67 68
69 /* TODO Change the specification of GameCharacter
70 * to require an EventGraphic instead of a graphic name
71 * and offset
72 */
68 GameCharacter toDraw = Game.getSaveFile().getParty().getLeader(); 73 GameCharacter toDraw = Game.getSaveFile().getParty().getLeader();
69 if (!toDraw.getGraphic().equals("blank")) 74 if (!toDraw.getGraphic().equals("blank"))
70 { 75 {
@@ -147,5 +152,20 @@ public class HeroEvent implements Event {
147 { 152 {
148 return Layer.Middle; 153 return Layer.Middle;
149 } 154 }
155
156 public boolean isOccupyingSpace(int x, int y)
157 {
158 if (getLocation().equals(new Point(x,y)))
159 {
160 return true;
161 }
162
163 if (Functions.isMovingTo(this, x, y))
164 {
165 return true;
166 }
167
168 return false;
169 }
150 170
151} 171}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 05192ce..4f8b51c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java
@@ -11,6 +11,7 @@ import java.awt.Point;
11import java.util.ArrayList; 11import java.util.ArrayList;
12import com.fourisland.fourpuzzle.Direction; 12import com.fourisland.fourpuzzle.Direction;
13import com.fourisland.fourpuzzle.gamestate.mapview.Map; 13import com.fourisland.fourpuzzle.gamestate.mapview.Map;
14import com.fourisland.fourpuzzle.util.Functions;
14 15
15/** 16/**
16 * 17 *
@@ -209,4 +210,19 @@ public class LayerEvent implements Event {
209 this.label = string; 210 this.label = string;
210 } 211 }
211 212
213 public boolean isOccupyingSpace(int x, int y)
214 {
215 if (getLocation().equals(new Point(x,y)))
216 {
217 return true;
218 }
219
220 if (Functions.isMovingTo(this, x, y))
221 {
222 return true;
223 }
224
225 return false;
226 }
227
212} \ No newline at end of file 228} \ No newline at end of file
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 077f42e..52b75de 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -17,6 +17,14 @@ import java.util.logging.Logger;
17 * @author hatkirby 17 * @author hatkirby
18 */ 18 */
19public class SpecialEvent { 19public class SpecialEvent {
20
21 /* TODO Create a manager for SpecialEvent action threads that
22 * controls when they are executed and allows MapViewGameState
23 * to poll it to see if it is currently managing any action
24 * threads. If it is, MapViewGameState should be able to prevent
25 * certain actions from occuring (unless the action thread is
26 * ParallelProcess) such as keyboard input.
27 */
20 28
21 /** 29 /**
22 * Display a message on the screen. 30 * Display a message on the screen.
@@ -120,11 +128,7 @@ public class SpecialEvent {
120 */ 128 */
121 public void MoveEventWait() 129 public void MoveEventWait()
122 { 130 {
123 try { 131 MoveEventThread.moveAll();
124 MoveEventThread.moveEventWait.await();
125 } catch (InterruptedException ex) {
126 Logger.getLogger(SpecialEvent.class.getName()).log(Level.SEVERE, null, ex);
127 }
128 } 132 }
129 133
130 /** 134 /**
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java index 5d5822e..7b9ee0c 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/MovementType.java
@@ -13,6 +13,7 @@ import com.fourisland.fourpuzzle.Direction;
13 */ 13 */
14public interface MovementType { 14public interface MovementType {
15 15
16 // TODO Rename the following method to getNextDirection
16 public Direction startMoving(); 17 public Direction startMoving();
17 18
18} 19}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index ab160f1..2ee4dca 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java
@@ -20,9 +20,10 @@ import java.util.logging.Logger;
20 */ 20 */
21public class MoveEventThread implements Runnable { 21public class MoveEventThread implements Runnable {
22 22
23 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
24 public static volatile int countMoveEventThreads = 0; 23 public static volatile int countMoveEventThreads = 0;
25 public static volatile List<Event> events = new Vector<Event>(); 24
25 static volatile List<Event> events = new Vector<Event>();
26 static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
26 27
27 Event ev; 28 Event ev;
28 MoveEvent[] actions; 29 MoveEvent[] actions;
@@ -51,6 +52,10 @@ public class MoveEventThread implements Runnable {
51 moveEventWait.countDown(); 52 moveEventWait.countDown();
52 } 53 }
53 54
55 /* TODO Rename the two following methods (isHeroMoving and isOtherMoving)
56 * to isHeroActive and isOtherActive respectively.
57 */
58
54 public static boolean isHeroMoving() 59 public static boolean isHeroMoving()
55 { 60 {
56 return (events.contains(Game.getHeroEvent())); 61 return (events.contains(Game.getHeroEvent()));
@@ -60,5 +65,14 @@ public class MoveEventThread implements Runnable {
60 { 65 {
61 return (events.contains(event)); 66 return (events.contains(event));
62 } 67 }
68
69 public static void moveAll()
70 {
71 try {
72 moveEventWait.await();
73 } catch (InterruptedException ex) {
74 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex);
75 }
76 }
63 77
64} 78}
diff --git a/src/com/fourisland/fourpuzzle/util/Functions.java b/src/com/fourisland/fourpuzzle/util/Functions.java index 038ca46..9966a2f 100644 --- a/src/com/fourisland/fourpuzzle/util/Functions.java +++ b/src/com/fourisland/fourpuzzle/util/Functions.java
@@ -48,6 +48,36 @@ public class Functions {
48 48
49 return false; 49 return false;
50 } 50 }
51
52 public static boolean isMovingTo(Event ev, int x, int y)
53 {
54 if (ev.isMoving() == false)
55 {
56 return false;
57 }
58
59 if ((ev.getDirection() == Direction.North) && ((ev.getLocation().y-1) == y) && (ev.getLocation().x == x))
60 {
61 return true;
62 }
63
64 if ((ev.getDirection() == Direction.West) && (ev.getLocation().y == y) && ((ev.getLocation().x-1) == x))
65 {
66 return true;
67 }
68
69 if ((ev.getDirection() == Direction.South) && ((ev.getLocation().y+1) == y) && (ev.getLocation().x == x))
70 {
71 return true;
72 }
73
74 if ((ev.getDirection() == Direction.East) && (ev.getLocation().y == y) && ((ev.getLocation().x+1) == x))
75 {
76 return true;
77 }
78
79 return false;
80 }
51 81
52 public static Direction oppositeDirection(Direction dir) 82 public static Direction oppositeDirection(Direction dir)
53 { 83 {