Class: RubyWarrior::Level
- Inherits:
-
Object
- Object
- RubyWarrior::Level
- Defined in:
- lib/ruby_warrior/level.rb
Instance Attribute Summary collapse
-
#clue ⇒ Object
Returns the value of attribute clue.
-
#description ⇒ Object
Returns the value of attribute description.
-
#floor ⇒ Object
Returns the value of attribute floor.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#time_bonus ⇒ Object
Returns the value of attribute time_bonus.
-
#tip ⇒ Object
Returns the value of attribute tip.
-
#warrior ⇒ Object
Returns the value of attribute warrior.
Instance Method Summary collapse
- #clear_bonus ⇒ Object
- #exists? ⇒ Boolean
- #failed? ⇒ Boolean
- #generate_player_files ⇒ Object
-
#initialize(profile, number) ⇒ Level
constructor
A new instance of Level.
- #load_level ⇒ Object
- #load_path ⇒ Object
- #load_player ⇒ Object
- #passed? ⇒ Boolean
- #play(turns = 1000) ⇒ Object
- #player_path ⇒ Object
- #setup_warrior(warrior) ⇒ Object
- #tally_points ⇒ Object
Constructor Details
#initialize(profile, number) ⇒ Level
Returns a new instance of Level.
6 7 8 9 10 |
# File 'lib/ruby_warrior/level.rb', line 6 def initialize(profile, number) @profile = profile @number = number @time_bonus = 0 end |
Instance Attribute Details
#clue ⇒ Object
Returns the value of attribute clue.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def clue @clue end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def description @description end |
#floor ⇒ Object
Returns the value of attribute floor.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def floor @floor end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/ruby_warrior/level.rb', line 3 def number @number end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
3 4 5 |
# File 'lib/ruby_warrior/level.rb', line 3 def profile @profile end |
#time_bonus ⇒ Object
Returns the value of attribute time_bonus.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def time_bonus @time_bonus end |
#tip ⇒ Object
Returns the value of attribute tip.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def tip @tip end |
#warrior ⇒ Object
Returns the value of attribute warrior.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def warrior @warrior end |
Instance Method Details
#clear_bonus ⇒ Object
71 72 73 |
# File 'lib/ruby_warrior/level.rb', line 71 def clear_bonus ((warrior.score + time_bonus)*0.2).round end |
#exists? ⇒ Boolean
83 84 85 |
# File 'lib/ruby_warrior/level.rb', line 83 def exists? File.exist? load_path end |
#failed? ⇒ Boolean
79 80 81 |
# File 'lib/ruby_warrior/level.rb', line 79 def failed? !@floor.units.include?(warrior) end |
#generate_player_files ⇒ Object
29 30 31 32 |
# File 'lib/ruby_warrior/level.rb', line 29 def generate_player_files load_level PlayerGenerator.new(self).generate end |
#load_level ⇒ Object
20 21 22 |
# File 'lib/ruby_warrior/level.rb', line 20 def load_level LevelLoader.new(self).instance_eval(File.read(load_path)) end |
#load_path ⇒ Object
16 17 18 |
# File 'lib/ruby_warrior/level.rb', line 16 def load_path @profile.tower_path + "/level_" + @number.to_s.rjust(3, '0') + ".rb" end |
#load_player ⇒ Object
24 25 26 27 |
# File 'lib/ruby_warrior/level.rb', line 24 def load_player $: << player_path load 'player.rb' end |
#passed? ⇒ Boolean
75 76 77 |
# File 'lib/ruby_warrior/level.rb', line 75 def passed? @floor.stairs_space.warrior? end |
#play(turns = 1000) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_warrior/level.rb', line 34 def play(turns = 1000) load_level turns.times do |n| return if passed? || failed? UI.puts "- turn #{n+1} -" UI.print @floor.to_map @floor.units.each { |unit| unit.prepare_turn } @floor.units.each { |unit| unit.perform_turn } yield if block_given? @time_bonus -= 1 if @time_bonus > 0 end end |
#player_path ⇒ Object
12 13 14 |
# File 'lib/ruby_warrior/level.rb', line 12 def player_path @profile.player_path end |
#setup_warrior(warrior) ⇒ Object
87 88 89 90 91 |
# File 'lib/ruby_warrior/level.rb', line 87 def setup_warrior(warrior) @warrior = warrior @warrior.add_abilities(*profile.abilities) @warrior.name = profile.warrior_name end |
#tally_points ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_warrior/level.rb', line 47 def tally_points score = 0 UI.puts "Level Score: #{warrior.score}" score += warrior.score UI.puts "Time Bonus: #{time_bonus}" score += @time_bonus if floor.other_units.empty? UI.puts "Clear Bonus: #{clear_bonus}" score += clear_bonus end if @profile.epic? @profile.current_epic_score += score UI.puts "Total Score: #{@profile.current_epic_score}" else @profile.score += score @profile.abilities = warrior.abilities.keys UI.puts "Total Score: #{@profile.score}" end end |