From de019d1faf3daa90898bb194d1aac64409ca8824 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 24 Mar 2009 09:13:16 -0400 Subject: 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 --- .../fourpuzzle/gamestate/mapview/MapViewGameState.java | 6 +++++- .../gamestate/mapview/event/SpecialEvent.java | 18 ++++++++++++------ .../mapview/event/movement/FollowMovementType.java | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'src') 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 { public void deinitalize() { - // Do nothing, yet + // If an event is running when the game state is closing, kill it + for (LayerEvent ev : currentMap.getEvents()) + { + ev.getCallback().cancel(); + } } 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 { public void DisplayMessage(String message) throws InterruptedException { MessageWindow mw; - + if (faceSet.equals("")) { mw = new MessageWindow(message); } else { mw = new MessageWindow(message, faceSet, face); } - + Display.registerRenderable(mw); KeyboardInput.registerInputable(mw); - - mw.waitForCompletion(); - Display.unregisterRenderable(mw); - KeyboardInput.unregisterInputable(mw); + try { + mw.waitForCompletion(); + } catch (InterruptedException ex) { + /* The special event has been cancelled, kill the message and then + * propogate the exception to the EventHandler */ + throw ex; + } finally { + Display.unregisterRenderable(mw); + KeyboardInput.unregisterInputable(mw); + } } /** 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 { private boolean search(ImmutableEvent ev) { + /* Iterate over all of the directions and check if moving in that + * direction would place the event on the destination event. If so, the + * correct path has been aquired and thus we can return */ for (Direction d : Direction.values()) { Point loc = d.to(ev.getLocation()); @@ -49,6 +52,9 @@ public class FollowMovementType implements MovementType { } } + /* Calculate the directions to attempt and the order in which to do so + * based on proximity to the destination event */ + List ds = ev.getLegalMoves(); List tempd = new ArrayList(); @@ -80,18 +86,25 @@ public class FollowMovementType implements MovementType { } } + // Remove calculated directions that aren't legal movements tempd.retainAll(ds); + + // Randomize directions so movement is more fluid Collections.shuffle(tempd); + // Iterate over the suggested directions for (Direction d : tempd) { + /* If the position in the suggested direction has already been + * covered, try the next direction */ Point loc = d.to(ev.getLocation()); - if (attempts.contains(loc)) { continue; } + /* Create a dummy event and use it to search from the position in + * the suggested direction */ Event temp = new LayerEvent(loc.x, loc.y); temp.setParentMap(ev.getParentMap()); attempts.add(loc); -- cgit 1.4.1