Class: StudioGame::Player
- Inherits:
-
Object
- Object
- StudioGame::Player
show all
- Includes:
- Playable
- Defined in:
- lib/studio_game/player.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Playable
#blam, #strong?, #w00t
Constructor Details
#initialize(name, health = 100) ⇒ Player
Returns a new instance of Player.
12
13
14
15
16
17
|
# File 'lib/studio_game/player.rb', line 12
def initialize(name, health=100)
@name = name.capitalize
@health = health
@points = 0
@found_treasure = Hash.new(0)
end
|
Instance Attribute Details
#health ⇒ Object
Returns the value of attribute health.
9
10
11
|
# File 'lib/studio_game/player.rb', line 9
def health
@health
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/studio_game/player.rb', line 9
def name
@name
end
|
#score ⇒ Object
Returns the value of attribute score.
10
11
12
|
# File 'lib/studio_game/player.rb', line 10
def score
@score
end
|
#show ⇒ Object
Returns the value of attribute show.
10
11
12
|
# File 'lib/studio_game/player.rb', line 10
def show
@show
end
|
Instance Method Details
#<=>(other_player) ⇒ Object
27
28
29
|
# File 'lib/studio_game/player.rb', line 27
def <=>(other_player)
other_player.score <=> @score
end
|
#each_found_treasure ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/studio_game/player.rb', line 56
def each_found_treasure
@found_treasure.each do |key, value|
yield Treasure.new(key, value)
end
end
|
#found_treasure(treasure = TreasureTrove::TREASURES.sample) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/studio_game/player.rb', line 31
def found_treasure(treasure = TreasureTrove::TREASURES.sample)
if !@found_treasure
@found_treasure = Hash.new(0)
end
@found_treasure[treasure.name.to_sym] += treasure.points
puts "Treasure selected in \'found_treasure\' method: #{treasure.name}"
end
|
#points ⇒ Object
47
48
49
50
|
# File 'lib/studio_game/player.rb', line 47
def points
return 0 if @found_treasure.size == 0
@points = @found_treasure.values.reduce(:+)
end
|
#random_stuff ⇒ Object
52
53
54
|
# File 'lib/studio_game/player.rb', line 52
def random_stuff
0
end
|
#to_s ⇒ Object
23
24
25
|
# File 'lib/studio_game/player.rb', line 23
def to_s
return "I\'m #{@name} with a health of #{@health} and a #{score} score.\n#{@name}'s treasure bag contains #{treasure_bag}.\n#{@name}'s Grand Total Points = #{@points}\n\n"
end
|
#treasure_bag ⇒ Object
42
43
44
45
|
# File 'lib/studio_game/player.rb', line 42
def treasure_bag
return "no treasure in this bag" if !@found_treasure
@found_treasure
end
|