Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code and player position is now updated on scene.

  • Loading branch information...
commit 458c8c1e78872f9cb1c2b20f13251355c42c2ded 1 parent 46b1c3a
@mauricioszabo authored
Showing with 30 additions and 15 deletions.
  1. +15 −13 lib/scene.rb
  2. +15 −2 spec/scene_spec.rb
View
28 lib/scene.rb
@@ -15,15 +15,11 @@ def initialize(screen)
end
def update
+ update_codes
@code1.run if @code1
@code2.run if @code2
- end
-
- def draw
- @p1_energy.draw_on @screen, 20, 0
- @p2_energy.draw_on @screen, WIDTH-130, 0
- @p1.draw_on @screen
- @p2.draw_on @screen
+ @p1.update
+ @p2.update
end
def register_to(code, player)
@@ -32,7 +28,6 @@ def register_to(code, player)
else
@code2 = code.register_to self, @p2
end
- update_codes
end
def update_codes
@@ -40,18 +35,25 @@ def update_codes
update_player_info @code2, @p2, @p1, @p2_energy, @p1_energy if @code2
end
private :update_codes
-
+
def update_player_info(code, me, enemy, my_energy, other_energy)
code.me ||= Code::ShipData.new
code.enemy ||= Code::ShipData.new
- code.me.x = me.x
- code.me.y = me.y
+ code.me.x = me.x.to_i
+ code.me.y = me.y.to_i
code.me.energy = my_energy.level
code.me.direction = Code::DIRECTION[me.current_animation + 1]
- code.enemy.x = enemy.x
- code.enemy.y = enemy.y
+ code.enemy.x = enemy.x.to_i
+ code.enemy.y = enemy.y.to_i
code.enemy.energy = other_energy.level
code.enemy.direction = Code::DIRECTION[enemy.current_animation + 1]
end
private :update_player_info
+
+ def draw
+ @p1_energy.draw_on @screen, 20, 0
+ @p2_energy.draw_on @screen, WIDTH-130, 0
+ @p1.draw_on @screen
+ @p2.draw_on @screen
+ end
end
View
17 spec/scene_spec.rb
@@ -4,7 +4,7 @@
let(:scene) { Scene.new(screen) }
let(:screen) { MockScreen.new }
- class Scene; attr_reader :p1, :p2; end
+ class Scene; attr_accessor :p1, :p2; end
class Energy; attr_reader :tank, :energy; end
it 'should draw the initial energy tanks' do
@@ -22,7 +22,7 @@ class Energy; attr_reader :tank, :energy; end
screen.should have_a(p2.surface)
end
- it 'should update the code' do
+ it 'should update the code on register' do
code1 = mock("Code")
code1.stub!(:register_to).and_return(code_instance1 = mock("Code Instance").as_null_object)
code2 = mock("Code")
@@ -33,4 +33,17 @@ class Energy; attr_reader :tank, :energy; end
scene.register_to code2, :p2
scene.update
end
+
+ it 'should update code\'s ship info on update' do
+ scene.should_receive :update_codes
+ scene.update
+ end
+
+ it 'should update the player' do
+ scene.p1 = mock("Player 1")
+ scene.p2 = mock("Player 1")
+ scene.p1.should_receive(:update)
+ scene.p2.should_receive(:update)
+ scene.update
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.