Class: DiabloGame::Level
- Inherits:
-
Object
- Object
- DiabloGame::Level
- Includes:
- PrintStats
- Defined in:
- lib/diablo_game/level.rb
Instance Attribute Summary collapse
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #add_hero(insert) ⇒ Object
-
#initialize(title) ⇒ Level
constructor
A new instance of Level.
- #load_players(from_file) ⇒ Object
- #play(stages) ⇒ Object
Methods included from PrintStats
Constructor Details
#initialize(title) ⇒ Level
Returns a new instance of Level.
13 14 15 16 |
# File 'lib/diablo_game/level.rb', line 13 def initialize(title) @title = title @heroes = [] end |
Instance Attribute Details
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/diablo_game/level.rb', line 11 def title @title end |
Instance Method Details
#add_hero(insert) ⇒ Object
18 19 20 |
# File 'lib/diablo_game/level.rb', line 18 def add_hero(insert) @heroes.push(insert) end |
#load_players(from_file) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/diablo_game/level.rb', line 22 def load_players(from_file) puts "\nLoading heroes from file path = #{from_file}:" File.readlines(from_file).each do |line| puts line name, health = line.split(',') hero = Hero.new(name, Integer(health)) add_hero(hero) end end |
#play(stages) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/diablo_game/level.rb', line 32 def play(stages) 1.upto(stages) do |x| puts "\nStage #{x}".ljust(60,'.') puts "\nStarting round stats for stage #{x}:" @heroes.each do |hero| if hero.health >=0 puts hero else puts "xxx #{hero.name} is dead xxx" end end @heroes.each do |hero| if hero.health >= 0 puts "\n" LevelTurn.take_turn(hero) else puts "\nxxx #{hero.name} is dead skip round xxx" end end end end |