Class: Wackelkoepfe::Player

Inherits:
Object
  • Object
show all
Includes:
Playable
Defined in:
lib/Wackelkoepfe/player.rb

Direct Known Subclasses

BerserkPlayer, ClumsyPlayer

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.



14
15
16
17
18
# File 'lib/Wackelkoepfe/player.rb', line 14

def initialize(name, health = 100)
  @name = name.capitalize
  @health = health
  @found_treasures = Hash.new(0)
end

Instance Attribute Details

#healthObject

Returns the value of attribute health.



8
9
10
# File 'lib/Wackelkoepfe/player.rb', line 8

def health
  @health
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/Wackelkoepfe/player.rb', line 7

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



10
11
12
# File 'lib/Wackelkoepfe/player.rb', line 10

def <=>(other)
  other.score <=> score
end

#each_found_treasureObject



40
41
42
43
44
# File 'lib/Wackelkoepfe/player.rb', line 40

def each_found_treasure
  @found_treasures.each do |name, points|
    yield Treasure.new(name, points)
  end
end

#found_treasure(treasure) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/Wackelkoepfe/player.rb', line 28

def found_treasure(treasure)
  @found_treasures[treasure.name] += treasure.points
  puts "#{@name} hat eine #{treasure.name} gefunden die #{treasure.points} Punkte wert ist!"
  sleep(1)
  puts "#{@name}s Schatzpunkte: #{@found_treasures}"
  sleep(1)
end

#pointsObject



36
37
38
# File 'lib/Wackelkoepfe/player.rb', line 36

def points
  return @found_treasures.values.reduce(0, :+)
end

#scoreObject



24
25
26
# File 'lib/Wackelkoepfe/player.rb', line 24

def score
  score = @health + points
end

#to_sObject



20
21
22
# File 'lib/Wackelkoepfe/player.rb', line 20

def to_s
  "Mein Name ist #{@name} ich habe #{@health} Gesundheitspunkte, #{points} Punkte, und einen Gesamtpunktestand von #{score}."
end