Class: RubyWarrior::Profile
- Inherits:
-
Object
- Object
- RubyWarrior::Profile
- Defined in:
- lib/ruby_warrior/profile.rb
Instance Attribute Summary collapse
-
#abilities ⇒ Object
Returns the value of attribute abilities.
-
#current_epic_score ⇒ Object
Returns the value of attribute current_epic_score.
-
#epic_score ⇒ Object
Returns the value of attribute epic_score.
-
#level_number ⇒ Object
Returns the value of attribute level_number.
-
#player_path ⇒ Object
Returns the value of attribute player_path.
-
#score ⇒ Object
Returns the value of attribute score.
-
#tower_path ⇒ Object
Returns the value of attribute tower_path.
-
#warrior_name ⇒ Object
Returns the value of attribute warrior_name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_abilities(*abilities) ⇒ Object
- #current_level ⇒ Object
- #directory_name ⇒ Object
- #enable_epic_mode ⇒ Object
- #encode ⇒ Object
- #epic? ⇒ Boolean
-
#initialize ⇒ Profile
constructor
A new instance of Profile.
- #next_level ⇒ Object
- #save ⇒ Object
- #to_s ⇒ Object
- #tower ⇒ Object
- #update_epic_score ⇒ Object
Constructor Details
#initialize ⇒ Profile
Returns a new instance of Profile.
7 8 9 10 11 12 13 14 15 |
# File 'lib/ruby_warrior/profile.rb', line 7 def initialize @tower_path = nil @warrior_name = nil @score = 0 @current_epic_score = 0 @epic_score = 0 @abilities = [] @level_number = 0 end |
Instance Attribute Details
#abilities ⇒ Object
Returns the value of attribute abilities.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def abilities @abilities end |
#current_epic_score ⇒ Object
Returns the value of attribute current_epic_score.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def current_epic_score @current_epic_score end |
#epic_score ⇒ Object
Returns the value of attribute epic_score.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def epic_score @epic_score end |
#level_number ⇒ Object
Returns the value of attribute level_number.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def level_number @level_number end |
#player_path ⇒ Object
Returns the value of attribute player_path.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def player_path @player_path end |
#score ⇒ Object
Returns the value of attribute score.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def score @score end |
#tower_path ⇒ Object
Returns the value of attribute tower_path.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def tower_path @tower_path end |
#warrior_name ⇒ Object
Returns the value of attribute warrior_name.
5 6 7 |
# File 'lib/ruby_warrior/profile.rb', line 5 def warrior_name @warrior_name end |
Class Method Details
.decode(str) ⇒ Object
27 28 29 |
# File 'lib/ruby_warrior/profile.rb', line 27 def self.decode(str) Marshal.load(Base64.decode64(str)) end |
.load(path) ⇒ Object
31 32 33 34 35 |
# File 'lib/ruby_warrior/profile.rb', line 31 def self.load(path) player = decode(File.read(path)) player.player_path = File.dirname(path) player end |
Instance Method Details
#add_abilities(*abilities) ⇒ Object
65 66 67 68 |
# File 'lib/ruby_warrior/profile.rb', line 65 def add_abilities(*abilities) @abilities += abilities @abilities.uniq! end |
#current_level ⇒ Object
57 58 59 |
# File 'lib/ruby_warrior/profile.rb', line 57 def current_level Level.new(self, level_number) end |
#directory_name ⇒ Object
41 42 43 |
# File 'lib/ruby_warrior/profile.rb', line 41 def directory_name [warrior_name.downcase.gsub(/[^a-z0-9]+/, '-'), tower.name].join('-') end |
#enable_epic_mode ⇒ Object
70 71 72 73 74 |
# File 'lib/ruby_warrior/profile.rb', line 70 def enable_epic_mode @epic = true @epic_score ||= 0 @current_epic_score ||= 0 end |
#encode ⇒ Object
17 18 19 |
# File 'lib/ruby_warrior/profile.rb', line 17 def encode Base64.encode64(Marshal.dump(self)) end |
#epic? ⇒ Boolean
76 77 78 |
# File 'lib/ruby_warrior/profile.rb', line 76 def epic? @epic end |
#next_level ⇒ Object
61 62 63 |
# File 'lib/ruby_warrior/profile.rb', line 61 def next_level Level.new(self, level_number+1) end |
#save ⇒ Object
21 22 23 24 25 |
# File 'lib/ruby_warrior/profile.rb', line 21 def save update_epic_score @level_number = 0 if epic? File.open(player_path + '/.profile', 'w') { |f| f.write(encode) } end |
#to_s ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/ruby_warrior/profile.rb', line 45 def to_s if epic? [warrior_name, tower.name, "first score #{score}", "epic score #{epic_score}"].join(' - ') else [warrior_name, tower.name, "level #{level_number}", "score #{score}"].join(' - ') end end |
#tower ⇒ Object
53 54 55 |
# File 'lib/ruby_warrior/profile.rb', line 53 def tower Tower.new(@tower_path) end |
#update_epic_score ⇒ Object
80 81 82 83 84 |
# File 'lib/ruby_warrior/profile.rb', line 80 def update_epic_score if @current_epic_score > @epic_score @epic_score = @current_epic_score end end |