summary refs log tree commit diff stats
path: root/src/com
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-24 09:13:16 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-24 09:13:16 -0400
commitde019d1faf3daa90898bb194d1aac64409ca8824 (patch)
tree09ca87bd0c7c6cd2e8e3df1353fc8d6504c3703d /src/com
parentaf19fd5898d839e1976f34960b21f8dfc2dd77eb (diff)
downloadfourpuzzle-de019d1faf3daa90898bb194d1aac64409ca8824.tar.gz
fourpuzzle-de019d1faf3daa90898bb194d1aac64409ca8824.tar.bz2
fourpuzzle-de019d1faf3daa90898bb194d1aac64409ca8824.zip
Engine: Fixed MessageWindow non-closure
Added code to MapViewGameState's deinitalize() that cancells the callbacks of all currently running events. Also added code to SpecialEvent's displayMessage() that allows an InterruptedException to kill the message.

With the problem with the Title Screen, it turned out that this bug had nothing to do with it, the Title Screen's interval was just too fast.

Fixes #18
Diffstat (limited to 'src/com')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java6
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java18
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/FollowMovementType.java15
3 files changed, 31 insertions, 8 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index d3bd101..6cf9b10 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -71,7 +71,11 @@ public class MapViewGameState implements GameState {
71 71
72 public void deinitalize() 72 public void deinitalize()
73 { 73 {
74 // Do nothing, yet 74 // If an event is running when the game state is closing, kill it
75 for (LayerEvent ev : currentMap.getEvents())
76 {
77 ev.getCallback().cancel();
78 }
75 } 79 }
76 80
77 public void processInput(KeyInput key) 81 public void processInput(KeyInput key)
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 30db7a2..2daefab 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -63,21 +63,27 @@ public class SpecialEvent {
63 public void DisplayMessage(String message) throws InterruptedException 63 public void DisplayMessage(String message) throws InterruptedException
64 { 64 {
65 MessageWindow mw; 65 MessageWindow mw;
66 66
67 if (faceSet.equals("")) 67 if (faceSet.equals(""))
68 { 68 {
69 mw = new MessageWindow(message); 69 mw = new MessageWindow(message);
70 } else { 70 } else {
71 mw = new MessageWindow(message, faceSet, face); 71 mw = new MessageWindow(message, faceSet, face);
72 } 72 }
73 73
74 Display.registerRenderable(mw); 74 Display.registerRenderable(mw);
75 KeyboardInput.registerInputable(mw); 75 KeyboardInput.registerInputable(mw);
76
77 mw.waitForCompletion();
78 76
79 Display.unregisterRenderable(mw); 77 try {
80 KeyboardInput.unregisterInputable(mw); 78 mw.waitForCompletion();
79 } catch (InterruptedException ex) {
80 /* The special event has been cancelled, kill the message and then
81 * propogate the exception to the EventHandler */
82 throw ex;
83 } finally {
84 Display.unregisterRenderable(mw);
85 KeyboardInput.unregisterInputable(mw);
86 }
81 } 87 }
82 88
83 /** 89 /**
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/FollowMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/FollowMovementType.java index b84fc4a..bbe9d82 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/FollowMovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/FollowMovementType.java
@@ -40,6 +40,9 @@ public class FollowMovementType implements MovementType {
40 40
41 private boolean search(ImmutableEvent ev) 41 private boolean search(ImmutableEvent ev)
42 { 42 {
43 /* Iterate over all of the directions and check if moving in that
44 * direction would place the event on the destination event. If so, the
45 * correct path has been aquired and thus we can return */
43 for (Direction d : Direction.values()) 46 for (Direction d : Direction.values())
44 { 47 {
45 Point loc = d.to(ev.getLocation()); 48 Point loc = d.to(ev.getLocation());
@@ -49,6 +52,9 @@ public class FollowMovementType implements MovementType {
49 } 52 }
50 } 53 }
51 54
55 /* Calculate the directions to attempt and the order in which to do so
56 * based on proximity to the destination event */
57
52 List<Direction> ds = ev.getLegalMoves(); 58 List<Direction> ds = ev.getLegalMoves();
53 List<Direction> tempd = new ArrayList<Direction>(); 59 List<Direction> tempd = new ArrayList<Direction>();
54 60
@@ -80,18 +86,25 @@ public class FollowMovementType implements MovementType {
80 } 86 }
81 } 87 }
82 88
89 // Remove calculated directions that aren't legal movements
83 tempd.retainAll(ds); 90 tempd.retainAll(ds);
91
92 // Randomize directions so movement is more fluid
84 Collections.shuffle(tempd); 93 Collections.shuffle(tempd);
85 94
95 // Iterate over the suggested directions
86 for (Direction d : tempd) 96 for (Direction d : tempd)
87 { 97 {
98 /* If the position in the suggested direction has already been
99 * covered, try the next direction */
88 Point loc = d.to(ev.getLocation()); 100 Point loc = d.to(ev.getLocation());
89
90 if (attempts.contains(loc)) 101 if (attempts.contains(loc))
91 { 102 {
92 continue; 103 continue;
93 } 104 }
94 105
106 /* Create a dummy event and use it to search from the position in
107 * the suggested direction */
95 Event temp = new LayerEvent(loc.x, loc.y); 108 Event temp = new LayerEvent(loc.x, loc.y);
96 temp.setParentMap(ev.getParentMap()); 109 temp.setParentMap(ev.getParentMap());
97 attempts.add(loc); 110 attempts.add(loc);