Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code now exposes player and enemy's position and status.

  • Loading branch information...
commit 6791fe2fdc68cd62298fcf8f85ab4b8d9637962d 1 parent 1376a4e
@mauricioszabo authored
Showing with 46 additions and 5 deletions.
  1. +19 −1 lib/code.rb
  2. +27 −4 spec/code_spec.rb
View
20 lib/code.rb
@@ -1,6 +1,24 @@
Object.send :remove_const, :ObjectSpace
class Code
- attr_accessor :block
+ ShipData = Struct.new(:x, :y, :energy, :direction)
+
+ me = enemy = nil
+
+ define_method(:me=) { |o| me = o }
+ define_method(:enemy=) { |o| enemy = o }
+ define_method(:me) { me }
+ define_method(:enemy) { enemy }
+
+ DIRECTION = {
+ Player::UPPER => :upper,
+ Player::UPPER_RIGHT => :upper_right,
+ Player::RIGHT => :right,
+ Player::LOWER_RIGHT => :lower_right,
+ Player::LOWER => :lower,
+ Player::LOWER_LEFT => :lower_left,
+ Player::LEFT => :left,
+ Player::UPPER_LEFT => :upper_left,
+ }
class << self
block = nil
View
31 spec/code_spec.rb
@@ -41,8 +41,27 @@
end
context "on positioning" do
- it 'should show where is the other ship' do
- pending
+ it 'should show where are the ships' do
+ run {
+ me.x.should == 20
+ me.y.should == 300
+ enemy.x.should == 780
+ enemy.y.should == 300
+ }
+ end
+
+ it 'should show position of mine and other ship' do
+ run {
+ me.direction.should == :upper
+ enemy.direction.should == :upper
+ }
+ end
+
+ it 'should show energy for both ships' do
+ run {
+ me.energy.should == 100
+ enemy.energy.should == 100
+ }
end
end
@@ -93,7 +112,11 @@ def this_code &block
code = Class.new(Code) do
each_frame &block
end
- #FIXME: Cannot stay on Code interface
- code.register_to scene, player
+ player.stub!(:x).and_return(20)
+ player.stub!(:y).and_return(300)
+ player.stub!(:current_animation).and_return(0)
+ scene.instance_variable_set :@p1, player
+ scene.register_to code, :p1
+ scene.instance_variable_get :@code1
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.