Class: RubyWarrior::Level
- Inherits:
-
Object
- Object
- RubyWarrior::Level
- Defined in:
- lib/ruby_warrior/level.rb
Instance Attribute Summary collapse
-
#ace_score ⇒ Object
Returns the value of attribute ace_score.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_bonus ⇒ Object
- #exists? ⇒ Boolean
- #failed? ⇒ Boolean
- #generate_player_files ⇒ Object
- #grade_for(score) ⇒ 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
- #score_calculation(current_score, addition) ⇒ Object
- #setup_warrior(warrior) ⇒ Object
- #tally_points ⇒ Object
Constructor Details
#initialize(profile, number) ⇒ Level
Returns a new instance of Level.
16 17 18 19 20 |
# File 'lib/ruby_warrior/level.rb', line 16 def initialize(profile, number) @profile = profile @number = number @time_bonus = 0 end |
Instance Attribute Details
#ace_score ⇒ Object
Returns the value of attribute ace_score.
4 5 6 |
# File 'lib/ruby_warrior/level.rb', line 4 def ace_score @ace_score end |
#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 |
Class Method Details
.grade_letter(percent) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/ruby_warrior/level.rb', line 6 def self.grade_letter(percent) if percent >= 1.0 then "S" elsif percent >= 0.9 then "A" elsif percent >= 0.8 then "B" elsif percent >= 0.7 then "C" elsif percent >= 0.6 then "D" else "F" end end |
Instance Method Details
#clear_bonus ⇒ Object
93 94 95 |
# File 'lib/ruby_warrior/level.rb', line 93 def clear_bonus ((warrior.score + time_bonus)*0.2).round end |
#exists? ⇒ Boolean
113 114 115 |
# File 'lib/ruby_warrior/level.rb', line 113 def exists? File.exist? load_path end |
#failed? ⇒ Boolean
109 110 111 |
# File 'lib/ruby_warrior/level.rb', line 109 def failed? !@floor.units.include?(warrior) end |
#generate_player_files ⇒ Object
43 44 45 46 |
# File 'lib/ruby_warrior/level.rb', line 43 def generate_player_files load_level PlayerGenerator.new(self).generate end |
#grade_for(score) ⇒ Object
87 88 89 90 91 |
# File 'lib/ruby_warrior/level.rb', line 87 def grade_for(score) if ace_score self.class.grade_letter(score / ace_score.to_f) end end |
#load_level ⇒ Object
34 35 36 |
# File 'lib/ruby_warrior/level.rb', line 34 def load_level LevelLoader.new(self).instance_eval(File.read(load_path)) end |
#load_path ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ruby_warrior/level.rb', line 26 def load_path File.join( File.('../../../towers/', __FILE__), File.basename(@profile.tower_path) + "/level_" + @number.to_s.rjust(3, '0') + ".rb" ) end |
#load_player ⇒ Object
38 39 40 41 |
# File 'lib/ruby_warrior/level.rb', line 38 def load_player $: << player_path load 'player.rb' end |
#passed? ⇒ Boolean
105 106 107 |
# File 'lib/ruby_warrior/level.rb', line 105 def passed? @floor.stairs_space.warrior? end |
#play(turns = 1000) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_warrior/level.rb', line 48 def play(turns = 1000) load_level turns.times do |n| return if passed? || failed? UI.puts "- turn #{n+1} -" UI.print @floor.character @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
22 23 24 |
# File 'lib/ruby_warrior/level.rb', line 22 def player_path @profile.player_path end |
#score_calculation(current_score, addition) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/ruby_warrior/level.rb', line 97 def score_calculation(current_score, addition) if current_score.zero? addition.to_s else "#{current_score} + #{addition} = #{current_score + addition}" end end |
#setup_warrior(warrior) ⇒ Object
117 118 119 120 121 |
# File 'lib/ruby_warrior/level.rb', line 117 def setup_warrior(warrior) @warrior = warrior @warrior.add_abilities(*profile.abilities) @warrior.name = profile.warrior_name end |
#tally_points ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_warrior/level.rb', line 61 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? UI.puts "Level Grade: #{grade_for(score)}" if grade_for(score) UI.puts "Total Score: " + score_calculation(@profile.current_epic_score, score) @profile.current_epic_grades[@number] = (score / ace_score.to_f) if ace_score @profile.current_epic_score += score else UI.puts "Total Score: " + score_calculation(@profile.score, score) @profile.score += score @profile.abilities = warrior.abilities.keys end end |