Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a cheap, evil test

  • Loading branch information...
commit 78171ea37e34c741d81e16f29fc2779589b2bdb1 1 parent a9fbed1
@practicingruby practicingruby authored
View
BIN  data/beep.wav
Binary file not shown
View
24 lib/blind/game.rb
@@ -0,0 +1,24 @@
+require "ray"
+
+module Blind
+ class Game
+ def initialize
+ @events = Hash.new { ->() {} }
+ @player_position = Ray::Vector2.new(0,0)
+ end
+
+ attr_reader :player_position, :events
+
+ def move_player(dx, dy)
+ @player_position += [dx, dy]
+
+ if @player_position.x < 0 || @player_position.y < 0
+ events[:out_of_bounds].call
+ end
+ end
+
+ def on_event(event_name, &block)
+ events[:out_of_bounds] = block
+ end
+ end
+end
View
25 test/game_test.rb
@@ -0,0 +1,25 @@
+require_relative "helper"
+require_relative "../lib/blind/game"
+
+describe Blind::Game do
+ it "must control player movement" do
+ game = Blind::Game.new
+
+ pos = game.player_position
+
+ game.move_player(3,2)
+ game.move_player(7,-5)
+
+ game.player_position.must_equal(Ray::Vector2.new(pos.x + 10, pos.y - 3))
+ end
+
+ it "must kill the player when out of bounds" do
+ game = Blind::Game.new
+ dead = false
+
+ game.on_event(:out_of_bounds) { dead = true }
+ game.move_player(-5,0)
+
+ dead.must_equal(true)
+ end
+end
View
1  test/suite.rb
@@ -1,2 +1,3 @@
require_relative "map_test"
require_relative "element_test"
+require_relative "game_test"
Please sign in to comment.
Something went wrong with that request. Please try again.