Class: Leaderboard

Inherits:
Object
  • Object
show all
Defined in:
lib/rrobots/gui/leaderboard.rb

Instance Method Summary collapse

Constructor Details

#initialize(window, robots) ⇒ Leaderboard

Returns a new instance of Leaderboard.



2
3
4
5
6
7
8
# File 'lib/rrobots/gui/leaderboard.rb', line 2

def initialize(window, robots)
  @font_size = 24 
  @robots = robots
  @font = Gosu::Font.new(window, 'Courier New', @font_size) 
  @x_offset = @font_size
  @y_offset = @font_size * 2
end

Instance Method Details

#drawObject



10
11
12
13
14
15
16
17
18
# File 'lib/rrobots/gui/leaderboard.rb', line 10

def draw
  if @robots
    @robots.each_with_index do |r, i|
      y = @y_offset + i * @font_size
      @font.draw("#{r.first.name}", @x_offset, y, ZOrder::UI, 1.0, 1.0, r.last.font_color)
      @font.draw("#{r.first.energy.to_i}", @x_offset + (@font_size * 6), y, ZOrder::UI, 1.0, 1.0, r.last.font_color)
    end
  end
end