Class: SpaceInvaders::ScoreTracker

Inherits:
Base
  • Object
show all
Defined in:
lib/space_invaders/trackers/score_tracker.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#game_status

Constructor Details

#initialize(app) ⇒ ScoreTracker

Returns a new instance of ScoreTracker.



6
7
8
9
10
11
# File 'lib/space_invaders/trackers/score_tracker.rb', line 6

def initialize app
  @app = app
  @score = 0
  @score_headline = Gosu::Image.from_text @app, "Score:", App::DEFAULT_FONT, 30
  set_score_number
end

Instance Attribute Details

#scoreObject (readonly)

Returns the value of attribute score.



4
5
6
# File 'lib/space_invaders/trackers/score_tracker.rb', line 4

def score
  @score
end

Instance Method Details

#drawObject



22
23
24
25
# File 'lib/space_invaders/trackers/score_tracker.rb', line 22

def draw
  @score_headline.draw 10, 10, 1
  @score_number.draw 100, 10, 1, 1, 1, Gosu::Color::GREEN
end

#increase_by(number) ⇒ Object



13
14
15
16
# File 'lib/space_invaders/trackers/score_tracker.rb', line 13

def increase_by number
  @score += number
  set_score_number
end

#set_score_numberObject



18
19
20
# File 'lib/space_invaders/trackers/score_tracker.rb', line 18

def set_score_number
  @score_number = Gosu::Image.from_text @app, @score, App::DEFAULT_FONT, 30
end