From 7171798052557dab8b3e6febfc027bf5b1b52941 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 28 Jan 2009 16:45:55 -0500 Subject: Fixed off-screen bug If an Event is adjacent to a Map boundary, then it could accidentally walk off the screen during the following circumstance: When a MoveEvent() action tells said Event to move off-screen while the Event is already moving, collision checking will be bypassed and the Event will proceed to walk off the screen, after which an Exception will be thrown when said Event attempts to move again. This bug has been fixed. --- src/com/fourisland/fourpuzzle/Audio.java | 7 +++++++ .../fourpuzzle/gamestate/mapview/MapViewGameState.java | 2 +- .../fourpuzzle/gamestate/mapview/event/AbstractEvent.java | 11 ++++++++++- .../fourpuzzle/gamestate/mapview/event/Event.java | 2 +- .../fourpuzzle/gamestate/mapview/event/LayerEvent.java | 2 +- .../mapview/event/specialmove/StepMoveEvent.java | 15 ++++++++------- 6 files changed, 28 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java index bc34eda..b364342 100644 --- a/src/com/fourisland/fourpuzzle/Audio.java +++ b/src/com/fourisland/fourpuzzle/Audio.java @@ -37,6 +37,13 @@ public class Audio { } })); } catch (MidiUnavailableException ex) { + /* TODO Because of the frequent MIDI unavailability, when + * a MIDI sequencer is unavailable, instead of breaking down, + * the application should display a message that something + * went wrong with the sound and that they should attempt + * the game again. + */ + Logger.getLogger(Audio.class.getName()).log(Level.SEVERE, null, ex); } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 65d2d2d..36406af 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -147,7 +147,7 @@ public class MapViewGameState implements GameState { { if (!EventHandler.isRunningEvent()) { - ev.startMoving(currentMap); + ev.startMoving(); } } } else { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java index a0f4e10..c0ea634 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AbstractEvent.java @@ -41,8 +41,13 @@ public abstract class AbstractEvent implements Event { } private int moveTimer; - public void startMoving(Direction toMove) + public boolean startMoving(Direction toMove) { + if (isMoving()) + { + return false; + } + setDirection(toMove); if (!getParentMap().checkForCollision(this, toMove)) @@ -50,6 +55,10 @@ public abstract class AbstractEvent implements Event { setAnimationStep(2); moveTimer = 4; setMoving(true); + + return true; + } else { + return false; } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java index e614167..310c2a2 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/Event.java @@ -32,7 +32,7 @@ public interface Event { public void setDirection(Direction direction); public boolean isMoving(); - public void startMoving(Direction direction); + public boolean startMoving(Direction direction); public Layer getLayer(); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 6201fc8..c88c42b 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java @@ -90,7 +90,7 @@ public class LayerEvent extends AbstractEvent implements Event { } } - public void startMoving(Map map) + public void startMoving() { Direction toMove = getPossibleEvent().getMovement().nextMovement(); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java index 74affc4..2f55816 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/StepMoveEvent.java @@ -24,14 +24,15 @@ public class StepMoveEvent implements MoveEvent { public void doAction(Event ev) { - ev.startMoving(direction); - - while (ev.isMoving()) + if (ev.startMoving(direction)) { - try { - Thread.sleep(2); - } catch (InterruptedException ex) { - Logger.getLogger(StepMoveEvent.class.getName()).log(Level.SEVERE, null, ex); + while (ev.isMoving()) + { + try { + Thread.sleep(2); + } catch (InterruptedException ex) { + Logger.getLogger(StepMoveEvent.class.getName()).log(Level.SEVERE, null, ex); + } } } } -- cgit 1.4.1