Permalink
Browse files

Beginnings of a game class

  • Loading branch information...
1 parent f6316e7 commit eff2276f8ee2fa7f061a0cc78c256e732c5572af @practicingruby practicingruby committed Apr 15, 2012
Showing with 28 additions and 2 deletions.
  1. +14 −1 lib/blind/game.rb
  2. +13 −1 test/game_test.rb
  3. +1 −0 test/suite.rb
View
@@ -1,11 +1,24 @@
module Blind
class Game
def initialize(world)
-
+ @world = world
+ @events = Hash.new { |h,k| h[k] = ->() {} }
end
def move(dx, dy)
+ x,y = world.current_position.to_a
+ region = world.move_to(x + dx, y + dy)
+
+ @events[:abyss_reached].call if region == :abyss
+ end
+
+ def on_event(name, &block)
+ @events[name] = block
end
+
+ private
+
+ attr_reader :world, :events
end
end
View
@@ -6,6 +6,18 @@
it "must be able to trigger an event when the abyss is reached" do
game = Blind::Game.new(world)
- flunk
+
+ world.expect(:current_position, [0,0])
+ world.expect(:move_to, :abyss, [Numeric, Numeric])
+
+
+ dead = false
+ game.on_event(:abyss_reached) { dead = true }
+
+ refute dead, "should not be dead before the abyss is reached"
+
+ game.move(500,500)
+
+ assert dead, "should be dead once the abyss is reached"
end
end
View
@@ -1,2 +1,3 @@
require_relative "point_test"
require_relative "world_test"
+require_relative "game_test"

0 comments on commit eff2276

Please sign in to comment.