- Revision
- 645
- Author
- sirenian
- Date
- 2007-01-02 11:22:53 -0600 (Tue, 02 Jan 2007)
Log Message
[EK] Some more stuff working in Hellbound
Modified Paths
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/glyph/StubHeartbeat.java
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/Hellbound.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/AcceleratingHeartbeat.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/GameKeys.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/HellboundEvent.java
Diff
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/glyph/StubHeartbeat.java (644 => 645)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/glyph/StubHeartbeat.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/glyph/StubHeartbeat.java 2007-01-02 17:22:53 UTC (rev 645) @@ -4,6 +4,7 @@ private HeartbeatListener listener; private boolean beating; + private boolean skipped; public void addListener(HeartbeatListener listener) { this.listener = listener; @@ -26,6 +27,10 @@ } public void skipNextBeat() { - + skipped = true; } + + public boolean wasSkipped() { + return skipped; + } }
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java (644 => 645)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java 2007-01-02 17:22:53 UTC (rev 645) @@ -36,6 +36,7 @@ verifyMocks(); } + public void shouldRunOnRequestStartAndStartHeartbeatAndInformListeners() throws Exception { @@ -119,6 +120,18 @@ verifyMocks(); } + + public void shouldMoveGlyphDownAndSkipNextHeartbeat() { + + StubHeartbeat stubHeartbeat = new StubHeartbeat(); + + Game game = new Game(new PseudoRandomGlyphFactory(7, 13), stubHeartbeat, 7, 13); + game.requestStartGame(); + game.requestGlyphMovement(GlyphMovement.DOWN); + ensureThat(stubHeartbeat.wasSkipped()); + + } + public void shouldCauseGlyphSegmentsToBeAddedToPitThenCreateNewGlyphWhenGlyphCannotMoveDown() { // Given...
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/Hellbound.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/Hellbound.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/Hellbound.java 2007-01-02 17:22:53 UTC (rev 645) @@ -36,6 +36,9 @@ Color.MAGENTA, Color.GRAY, Color.BLACK }); private HellboundFrame frame; + private final EngineQueue engineQueue; + private final GuiQueue guiQueue; + private final Heartbeat heartbeat; public Hellbound() { this( @@ -49,14 +52,17 @@ public Hellbound(EngineQueue engineQueue, GuiQueue guiQueue, Heartbeat heartbeat, PitPanel pitPanel, GlyphFactory factory) { + this.engineQueue = engineQueue; + this.guiQueue = guiQueue; + this.heartbeat = heartbeat; Logger.debug(this, "Creating Hellbound instance..."); frame = createFrameForGui(engineQueue, pitPanel); Game game = createEngineForGame(heartbeat, factory); - connectQueues(engineQueue, guiQueue, pitPanel, frame, game); - bindThreadsToFrame(engineQueue, guiQueue, heartbeat, frame); - startHellbound(frame); + connectQueues(game, pitPanel); + bindThreadsToFrame(); + startHellbound(); } public static void main(String[] args) { @@ -64,22 +70,20 @@ new Hellbound(); } - private void startHellbound(HellboundFrame frame) { + private void startHellbound() { frame.pack(); frame.setVisible(true); } public void stopHellbound() { frame.dispose(); + stopThreads(); // Swing cannot be trusted to do this asynchronously Logger.debug(this, "Hellbound stopped."); } private void connectQueues( - EngineQueue engineQueue, - GuiQueue guiQueue, - GlyphListener pitPanel, - HellboundFrame frame, - Game game) { + Game game, + GlyphListener pitPanel) { game.addGameListener(guiQueue); game.addGlyphListener(guiQueue); frame.setGameRequestListener(engineQueue); @@ -90,19 +94,24 @@ } - private void bindThreadsToFrame(final EngineQueue engineQueue, final GuiQueue guiQueue, final Heartbeat heartbeat, HellboundFrame frame) { + private void bindThreadsToFrame() { + Logger.debug(this, "Binding threads to frame"); WindowAdapter queueLife = new WindowAdapter() { public void windowClosing(WindowEvent e) { Logger.debug(this, "Window closing; stopping threads"); - engineQueue.stop(); - guiQueue.stop(); - heartbeat.stop(); + stopThreads(); } }; frame.addWindowListener(queueLife); } + + private void stopThreads() { + engineQueue.stop(); + guiQueue.stop(); + heartbeat.stop(); + } private Game createEngineForGame(Heartbeat heartbeat, GlyphFactory factory) { return new Game(factory, heartbeat, WIDTH, HEIGHT);
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/AcceleratingHeartbeat.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/AcceleratingHeartbeat.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/AcceleratingHeartbeat.java 2007-01-02 17:22:53 UTC (rev 645) @@ -9,11 +9,16 @@ public class AcceleratingHeartbeat implements Heartbeat { + private static final String RUNNING = "Running"; + private static final String STOPPED = "Stopped"; + private static final String SKIPPING = "Skipping"; + private static final String SKIPPED = "Skipped"; + private ListenerSet listenerSet; private ListenerNotifier pulse; private long timeBetweenBeats; private boolean beating; - private boolean skipping; + private String state; public AcceleratingHeartbeat() { listenerSet = new ListenerSet(); @@ -38,6 +43,7 @@ }; new Thread(pulseTimer).start(); + state = RUNNING; } private synchronized void waitForTheBeat() { @@ -45,9 +51,14 @@ wait(timeBetweenBeats); } catch (InterruptedException e) { } - if (!skipping) { + if (state == SKIPPING) { + state = SKIPPED; + } else { Logger.debug(this, "Beating"); listenerSet.notifyListeners(pulse); + if (state == SKIPPED) { + state = RUNNING; + } } } @@ -64,6 +75,7 @@ synchronized (this) { notifyAll(); } + state = STOPPED; } public boolean isBeating() { @@ -71,10 +83,9 @@ } public void skipNextBeat() { - skipping = true; + state = SKIPPING; synchronized(this) { this.notifyAll(); } - skipping = false; } }
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java 2007-01-02 17:22:53 UTC (rev 645) @@ -107,10 +107,14 @@ Logger.debug(this, "Glyph movement " + movement + " requested"); boolean result = movement.performOn(glyph); - if (result == false && movement == GlyphMovement.DOWN) { - Logger.debug(this, "Could not move glyph down; junking it"); - junk.absorb(glyph); - resetGlyph(); + if (movement == GlyphMovement.DOWN) { + if(!result) { + Logger.debug(this, "Could not move glyph down; junking it"); + junk.absorb(glyph); + resetGlyph(); + } else { + heartbeat.skipNextBeat(); + } } } }
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/ActionFactory.java 2007-01-02 17:22:53 UTC (rev 645) @@ -12,9 +12,10 @@ public class ActionFactory { public Action createAction(final GameRequestListener gameRequestListener, final GlyphMovement movement) { - Logger.debug(this, "Creating " + movement + " action "); + Logger.debug(this, "Creating " + movement + " action"); return new AbstractAction() { public void actionPerformed(ActionEvent e) { + Logger.debug(this, "Performing " + movement + " action"); gameRequestListener.requestGlyphMovement(movement); } };
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/GameKeys.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/GameKeys.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/gui/GameKeys.java 2007-01-02 17:22:53 UTC (rev 645) @@ -1,9 +1,7 @@ package com.sirenian.hellbound.gui; -import java.awt.event.KeyEvent; - public class GameKeys { - public static final int DROP_GLYPH = KeyEvent.VK_SPACE; + public static final char DROP_GLYPH = ' '; }
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java (644 => 645)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/util/ThreadedQueue.java 2007-01-02 17:22:53 UTC (rev 645) @@ -50,8 +50,8 @@ Logger.debug(this, "Stopping queue " + queueName); synchronized (eventList) { shouldRun = false; + eventList.notifyAll(); } - eventList.notifyAll(); } private void waitForNextRequest() {
Modified: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/HellboundEvent.java (644 => 645)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/HellboundEvent.java 2007-01-02 16:05:39 UTC (rev 644) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/HellboundEvent.java 2007-01-02 17:22:53 UTC (rev 645) @@ -42,5 +42,14 @@ throw new RuntimeException(e); } } + + protected void pressKey(char keychar, World world) { + WindowWrapper wrapper = (WindowWrapper) world.get(WorldKey.WINDOW_WRAPPER, null); + try { + wrapper.pressKeychar(keychar); + } catch (SwingBehaviourException e) { + throw new RuntimeException(e); + } + } }
To unsubscribe from this list please visit:
