Permalink
Browse files

Created a specific class for Player.

  • Loading branch information...
1 parent 92e8d5b commit b198938a89f1ac8c985f3947538a28e780e5171c @mauricioszabo committed Feb 24, 2012
Showing with 35 additions and 0 deletions.
  1. +19 −0 lib/player.rb
  2. +16 −0 spec/player_spec.rb
View
@@ -0,0 +1,19 @@
+class Player < Animable
+ attr_reader :energy
+
+ def initialize(player)
+ @energy = Energy.new
+ if(player == :p1)
+ super :p1, 20, 300
+ @tank_position = [20, 0]
+ else
+ super :p2, 780, 300
+ @tank_position = [Scene::WIDTH - 130, 0]
+ end
+ end
+
+ def draw_on(screen)
+ @energy.draw_on screen, *@tank_position
+ super
+ end
+end
View
@@ -0,0 +1,16 @@
+require_relative 'helper'
+
+describe Player do
+ class Energy; attr_reader :tank, :energy; end
+
+ let(:player1) { Player.new(:p1) }
+ let(:player2) { Player.new(:p2) }
+ let(:screen) { MockScreen.new }
+
+ it 'should draw energy tanks on screen' do
+ player1.draw_on(screen)
+ screen.should have_a(player1.energy.tank).on(20, 0)
+ player2.draw_on(screen)
+ screen.should have_a(player2.energy.tank).on(670, 0)
+ end
+end

0 comments on commit b198938

Please sign in to comment.