- Revision
- 649
- Author
- sirenian
- Date
- 2007-01-03 05:54:20 -0600 (Wed, 03 Jan 2007)
Log Message
[EK] The Hellbound game now has a minimum feature set! All fully narrated in executable stories! Hurrah!
Modified Paths
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/SegmentsBehaviour.java
- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/domain/Segments.java
- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/ThePlayerMovesTheGlyph.java
Added Paths
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownKey.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/outcomes/TheGlyphShouldBeAgainstTheLeftWall.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheLeftWall.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheRightWall.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphShouldBeAgainstTheRightWall.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveLeft.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveRight.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphIsConstrainedByThePit.java
- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphWillNotMoveDown.java
Removed Paths
Diff
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/SegmentsBehaviour.java (648 => 649)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/SegmentsBehaviour.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/domain/SegmentsBehaviour.java 2007-01-03 11:54:20 UTC (rev 649) @@ -157,6 +157,26 @@ ensureThat(segments.lowest(), eq(4)); } + + public void shouldReturnTheLeftmostXPosition() { + Segments segments = new Segments( + new Segment(4, 1), + new Segment(3, 4), + new Segment(2, 3), + new Segment(5, 2)); + + ensureThat(segments.leftmost(), eq(2)); + } + + public void shouldReturnTheRightmostXPosition() { + Segments segments = new Segments( + new Segment(4, 1), + new Segment(3, 4), + new Segment(2, 3), + new Segment(5, 2)); + + ensureThat(segments.rightmost(), eq(5)); + } public void shouldReturnAddedSegments() { Segments segments1 = new Segments(new Segment[] {
Modified: trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java (648 => 649)
--- trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/behaviour/com/sirenian/hellbound/engine/GameBehaviour.java 2007-01-03 11:54:20 UTC (rev 649) @@ -162,6 +162,30 @@ verifyMocks(); } + public void shouldNotMoveGlyphLeftOrRightIfGlyphIsConstrainedByWalls() { + Junk junk = new Junk(3, 13); + class GlyphHolder { + private LivingGlyph glyph; + }; + final GlyphHolder holder = new GlyphHolder(); + + Game game = new Game(new PseudoRandomGlyphFactory(42, 3, 13) { + public LivingGlyph nextGlyph(CollisionDetector detector, ListenerSet glyphListeners) { + holder.glyph = super.nextGlyph(detector, glyphListeners); + return holder.glyph; + } + }, new StubHeartbeat(), 3, 13); + game.requestStartGame(); + + Segments originalSegments = holder.glyph.getSegments(); + + game.requestGlyphMovement(GlyphMovement.RIGHT); + ensureThat(holder.glyph.getSegments(), eq(originalSegments)); + + game.requestGlyphMovement(GlyphMovement.LEFT); + ensureThat(holder.glyph.getSegments(), eq(originalSegments)); + } + public void shouldEndGameAndStopHeartbeatWhenTheNewGlyphOverlapsTheJunk() { StubHeartbeat heartbeat = new StubHeartbeat(); Game game = new Game(new PseudoRandomGlyphFactory(42, 7, 2), heartbeat, 7, 2); // pit is only 2 deep!
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/domain/Segments.java (648 => 649)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/domain/Segments.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/domain/Segments.java 2007-01-03 11:54:20 UTC (rev 649) @@ -128,7 +128,27 @@ } return lowest; } + + public int leftmost() { + int leftmost = rightmost(); + for (int i = 0; i < segments.size(); i++) { + if (segments.get(i).x < leftmost){ + leftmost = segments.get(i).x; + } + } + return leftmost; + } + public int rightmost() { + int rightmost = -1; + for (int i = 0; i < segments.size(); i++) { + if (segments.get(i).x > rightmost){ + rightmost = segments.get(i).x; + } + } + return rightmost; + } + public Segments add(Segments segments) { Segment[] allSegments = new Segment[this.segments.size() + segments.size()]; for (int i = 0; i < this.segments.size(); i++) { @@ -181,4 +201,6 @@ return new Segments(newSegments); } + + }
Modified: trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java (648 => 649)
--- trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/java/com/sirenian/hellbound/engine/Game.java 2007-01-03 11:54:20 UTC (rev 649) @@ -32,10 +32,12 @@ private LivingGlyph glyph = LivingGlyph.NULL; private Junk junk = Junk.NULL; + private final int width; public Game(GlyphFactory factory, Heartbeat heartbeat, int width, int height) { this.factory = factory; this.heartbeat = heartbeat; + this.width = width; this.height = height; gameListeners = new ListenerSet(); glyphListeners = new ListenerSet(); @@ -50,6 +52,8 @@ collisionDetector = new CollisionDetector() { public boolean collides(Segments segments) { if (segments.lowest() >= Game.this.height) { return true; } + if (segments.leftmost() < 0) { return true; } + if (segments.rightmost() >= Game.this.width) { return true; } if (junk.overlaps(segments)) { return true; } return false; }
Deleted: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownButton.java (648 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownButton.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownButton.java 2007-01-03 11:54:20 UTC (rev 649) @@ -1,14 +0,0 @@ -package com.sirenian.hellbound.events; - -import java.awt.event.KeyEvent; - -import org.jbehave.core.story.domain.World; - - -public class ThePlayerPressesTheDownButton extends HellboundEvent { - - protected void occurAnyTimeIn(World world) { - pressKey(KeyEvent.VK_DOWN, world); - } - -}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownKey.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownKey.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/events/ThePlayerPressesTheDownKey.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,14 @@ +package com.sirenian.hellbound.events; + +import java.awt.event.KeyEvent; + +import org.jbehave.core.story.domain.World; + + +public class ThePlayerPressesTheDownKey extends HellboundEvent { + + protected void occurAnyTimeIn(World world) { + pressKey(KeyEvent.VK_DOWN, world); + } + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/outcomes/TheGlyphShouldBeAgainstTheLeftWall.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/outcomes/TheGlyphShouldBeAgainstTheLeftWall.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/outcomes/TheGlyphShouldBeAgainstTheLeftWall.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,26 @@ +package com.sirenian.hellbound.outcomes; + + +public class TheGlyphShouldBeAgainstTheLeftWall extends ThePitShouldLookLike { + + public TheGlyphShouldBeAgainstTheLeftWall() { + super( + "TTT...." + NL + + ".T....." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + ); + } + + + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheLeftWall.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheLeftWall.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheLeftWall.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,15 @@ +package com.sirenian.hellbound.scenarios; + +import com.sirenian.hellbound.events.ThePlayerPressesTheLeftKey; +import com.sirenian.hellbound.outcomes.TheGlyphShouldBeAgainstTheLeftWall; + +public class TheGlyphIsAgainstTheLeftWall extends HellboundScenario { + + protected void specifySteps() { + given(new TheFirstGlyphIsDisplayedOnTheBoard()); + when(new ThePlayerPressesTheLeftKey()); + when(new ThePlayerPressesTheLeftKey()); + then(new TheGlyphShouldBeAgainstTheLeftWall()); // sanity check + } + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheRightWall.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheRightWall.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphIsAgainstTheRightWall.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,14 @@ +package com.sirenian.hellbound.scenarios; + +import com.sirenian.hellbound.events.ThePlayerPressesTheRightKey; + +public class TheGlyphIsAgainstTheRightWall extends HellboundScenario { + + protected void specifySteps() { + given(new TheFirstGlyphIsDisplayedOnTheBoard()); + when(new ThePlayerPressesTheRightKey()); + when(new ThePlayerPressesTheRightKey()); + then(new TheGlyphShouldBeAgainstTheRightWall()); // sanity check + } + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphShouldBeAgainstTheRightWall.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphShouldBeAgainstTheRightWall.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphShouldBeAgainstTheRightWall.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,27 @@ +package com.sirenian.hellbound.scenarios; + +import com.sirenian.hellbound.outcomes.ThePitShouldLookLike; + +public class TheGlyphShouldBeAgainstTheRightWall extends ThePitShouldLookLike { + + public TheGlyphShouldBeAgainstTheRightWall() { + super( + "....TTT" + NL + + ".....T." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + ); + } + + + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveLeft.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveLeft.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveLeft.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,14 @@ +package com.sirenian.hellbound.scenarios; + +import com.sirenian.hellbound.events.ThePlayerPressesTheLeftKey; +import com.sirenian.hellbound.outcomes.TheGlyphShouldBeAgainstTheLeftWall; + +public class TheGlyphWillNotMoveLeft extends HellboundScenario { + + protected void specifySteps() { + given(new TheGlyphIsAgainstTheLeftWall()); + when(new ThePlayerPressesTheLeftKey()); + then(new TheGlyphShouldBeAgainstTheLeftWall()); + } + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveRight.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveRight.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/TheGlyphWillNotMoveRight.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,13 @@ +package com.sirenian.hellbound.scenarios; + +import com.sirenian.hellbound.events.ThePlayerPressesTheRightKey; + +public class TheGlyphWillNotMoveRight extends HellboundScenario { + + protected void specifySteps() { + given(new TheGlyphIsAgainstTheRightWall()); + when(new ThePlayerPressesTheRightKey()); + then(new TheGlyphShouldBeAgainstTheRightWall()); + } + +}
Modified: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/ThePlayerMovesTheGlyph.java (648 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/ThePlayerMovesTheGlyph.java 2007-01-03 11:12:18 UTC (rev 648) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/scenarios/ThePlayerMovesTheGlyph.java 2007-01-03 11:54:20 UTC (rev 649) @@ -1,6 +1,6 @@ package com.sirenian.hellbound.scenarios; -import com.sirenian.hellbound.events.ThePlayerPressesTheDownButton; +import com.sirenian.hellbound.events.ThePlayerPressesTheDownKey; import com.sirenian.hellbound.events.ThePlayerPressesTheLeftKey; import com.sirenian.hellbound.events.ThePlayerPressesTheRightKey; import com.sirenian.hellbound.outcomes.TheGlyphShouldBeCentredAtTheTopOfThePit; @@ -16,7 +16,7 @@ then(new TheGlyphShouldMoveRight()); when(new ThePlayerPressesTheLeftKey()); then(new TheGlyphShouldBeCentredAtTheTopOfThePit()); - when(new ThePlayerPressesTheDownButton()); + when(new ThePlayerPressesTheDownKey()); then(new TheGlyphShouldMoveDownwards()); then(new TheHeartbeatShouldBeSkipped()); }
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphIsConstrainedByThePit.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphIsConstrainedByThePit.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphIsConstrainedByThePit.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,20 @@ +package com.sirenian.hellbound.stories; + +import org.jbehave.core.story.domain.Narrative; + +import com.sirenian.hellbound.scenarios.TheGlyphWillNotMoveLeft; +import com.sirenian.hellbound.scenarios.TheGlyphWillNotMoveRight; + +public class TheGlyphIsConstrainedByThePit extends HellboundStory { + + public TheGlyphIsConstrainedByThePit() { + super(new Narrative("game player", "the glyph to be constrained by the pit", "the game has boundaries")); + } + + public void specify() { + addScenario(new TheGlyphWillNotMoveRight()); + addScenario(new TheGlyphWillNotMoveLeft()); + addScenario(new TheGlyphWillNotMoveDown()); + } + +}
Added: trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphWillNotMoveDown.java (0 => 649)
--- trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphWillNotMoveDown.java (rev 0) +++ trunk/examples/hellbound/src/stories/com/sirenian/hellbound/stories/TheGlyphWillNotMoveDown.java 2007-01-03 11:54:20 UTC (rev 649) @@ -0,0 +1,32 @@ +package com.sirenian.hellbound.stories; + +import com.sirenian.hellbound.events.ThePlayerPressesTheDownKey; +import com.sirenian.hellbound.events.ThePlayerPressesTheDropKey; +import com.sirenian.hellbound.outcomes.TheGlyphShouldBecomeJunkAndTheNextGlyphShouldAppear; +import com.sirenian.hellbound.scenarios.HellboundScenario; +import com.sirenian.hellbound.scenarios.TheFirstGlyphIsDisplayedOnTheBoard; + +public class TheGlyphWillNotMoveDown extends HellboundScenario { + + protected void specifySteps() { + given(new TheFirstGlyphIsDisplayedOnTheBoard()); + when(new ThePlayerPressesTheDropKey()); + when(new ThePlayerPressesTheDownKey()); + then(new TheGlyphShouldBecomeJunkAndTheNextGlyphShouldAppear( + "..ZZ..." + NL + + "...ZZ.." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "......." + NL + + "..XXX.." + NL + + "...X..." + NL + )); + } + +}
To unsubscribe from this list please visit:
