Class: Studio_game::Player

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

Direct Known Subclasses

Berserker, ClumsyPlayer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Playable

#boost, #drain

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_treasuresObject (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

#healthObject

Returns the value of attribute health.



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

def health
  @health
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#scoreObject (readonly)

Returns the value of attribute score.



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

def score
  @score
end

#sumObject (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_treasureObject



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_healthObject



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_sObject



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