Class: Studio_game::Player
- Inherits:
-
Object
- Object
- Studio_game::Player
- Includes:
- Playable
- Defined in:
- lib/studio_game/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#found_treasures ⇒ Object
readonly
Returns the value of attribute found_treasures.
-
#health ⇒ Object
Returns the value of attribute health.
-
#name ⇒ Object
Returns the value of attribute name.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#sum ⇒ Object
readonly
Returns the value of attribute sum.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_treasure ⇒ Object
- #found_treasure(name, pointsy) ⇒ Object
-
#initialize(name, health = 100) ⇒ Player
constructor
A new instance of Player.
- #reset_health ⇒ Object
- #to_s ⇒ Object
- #treasure_total(treasure_value) ⇒ Object
Methods included from Playable
Constructor Details
#initialize(name, health = 100) ⇒ Player
10 11 12 13 14 15 16 17 |
# File 'lib/studio_game/player.rb', line 10 def initialize(name, health = 100) @name = name @health = health @start_health = health @score = @health + @name.length @found_treasures = Hash.new(0) @sum = 0 end |
Instance Attribute Details
#found_treasures ⇒ Object (readonly)
Returns the value of attribute found_treasures.
7 8 9 |
# File 'lib/studio_game/player.rb', line 7 def found_treasures @found_treasures end |
#health ⇒ Object
Returns the value of attribute health.
8 9 10 |
# File 'lib/studio_game/player.rb', line 8 def health @health end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/studio_game/player.rb', line 8 def name @name end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
7 8 9 |
# File 'lib/studio_game/player.rb', line 7 def score @score end |
#sum ⇒ Object (readonly)
Returns the value of attribute sum.
7 8 9 |
# File 'lib/studio_game/player.rb', line 7 def sum @sum end |
Class Method Details
.load_players_(line) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/studio_game/player.rb', line 19 def self.load_players_(line) name, health = line.split(',') Player.new(name, Integer(health)) rescue ArgumentError puts "ignored invalid health: #{health}" Player.new(name) end |
Instance Method Details
#clear_treasure ⇒ Object
37 38 39 40 |
# File 'lib/studio_game/player.rb', line 37 def clear_treasure @found_treasures = Hash.new(0) @sum = 0 end |
#found_treasure(name, pointsy) ⇒ Object
27 28 29 30 |
# File 'lib/studio_game/player.rb', line 27 def found_treasure(name, pointsy) @found_treasures[name] += pointsy end |
#reset_health ⇒ Object
42 43 44 45 46 47 |
# File 'lib/studio_game/player.rb', line 42 def reset_health puts 'beginning health: ' + @start_health.to_s puts 'working health: ' + @health.to_s @health = @start_health #@health = 100 end |
#to_s ⇒ Object
55 |
# File 'lib/studio_game/player.rb', line 55 def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score} and #{@sum} points and I found #{@found_treasures}" |
#treasure_total(treasure_value) ⇒ Object
32 33 34 |
# File 'lib/studio_game/player.rb', line 32 def treasure_total(treasure_value) @sum += treasure_value end |