Class: StudioGame::Player
- Inherits:
-
Object
- Object
- StudioGame::Player
- 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.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #find_treasure(treasure = TreasureTrove.random_treasure) ⇒ Object
-
#initialize(name = "Player", health = 100) ⇒ Player
constructor
A new instance of Player.
- #points ⇒ Object
- #score ⇒ Object
- #to_s ⇒ Object
Methods included from Printable
#print_health_status, #print_player_information, #print_score, #print_treasure_trove, #print_treasures
Methods included from GameStats
#print_high_scores, #print_stats, #print_strength_stats, #print_treasure_stats, #total_points
Methods included from Formatting
#format_dot_spacing, #format_section_title
Methods included from Playable
Constructor Details
#initialize(name = "Player", health = 100) ⇒ Player
Returns a new instance of Player.
13 14 15 16 17 |
# File 'lib/studio_game/player.rb', line 13 def initialize(name = "Player", health = 100) @name = name.capitalize @health = health @found_treasures = Hash.new(0) end |
Instance Attribute Details
#found_treasures ⇒ Object (readonly)
Returns the value of attribute found_treasures.
11 12 13 |
# File 'lib/studio_game/player.rb', line 11 def found_treasures @found_treasures end |
#health ⇒ Object
Returns the value of attribute health.
10 11 12 |
# File 'lib/studio_game/player.rb', line 10 def health @health end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/studio_game/player.rb', line 10 def name @name end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 |
# File 'lib/studio_game/player.rb', line 27 def <=>(other) other.score <=> score end |
#find_treasure(treasure = TreasureTrove.random_treasure) ⇒ Object
44 45 46 47 48 |
# File 'lib/studio_game/player.rb', line 44 def find_treasure(treasure = TreasureTrove.random_treasure) @found_treasures[treasure.name] += treasure.points "#{@name} found a #{treasure.name} worth #{treasure.points} points" end |
#points ⇒ Object
35 36 37 |
# File 'lib/studio_game/player.rb', line 35 def points @found_treasures.values.sum end |
#score ⇒ Object
31 32 33 |
# File 'lib/studio_game/player.rb', line 31 def score @health + points end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/studio_game/player.rb', line 19 def to_s "#{@name}'s health = #{@health} and score = #{score}" end |