Module: DiabloGame::PrintStats

Included in:
Level
Defined in:
lib/diablo_game/print_stats_mixin.rb

Instance Method Summary collapse

Instance Method Details



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/diablo_game/print_stats_mixin.rb', line 4

def print_stats
  dead_heroes = @heroes.select { |hero| hero.dead?}
  survive_heroes = @heroes.reject { |hero| hero.dead?}
  sorted_survive_heroes = survive_heroes.sort {|a,b| b.points <=> a.points}
  
  puts "\n#{title} survivor total points:"
  sorted_survive_heroes.each do |hero|
    formatted_name = hero.name.ljust(20,'.')
    puts "#{formatted_name} #{hero.points}"
  end
  
  puts "\n#{title} dead heroes:"
  dead_heroes.each do |hero|
    formatted_name = hero.name.ljust(20,'.')
    puts "#{formatted_name} Dead!"
  end
end