class BattleRoyal::Player

Attributes

health[RW]
name[RW]

Public Class Methods

from_csv(string) click to toggle source
# File lib/battle_royal/player.rb, line 18
def self.from_csv(string)
  Player.new(string[0], string[1].to_i)
end
new(name, health = 100) click to toggle source
# File lib/battle_royal/player.rb, line 8
def initialize(name, health = 100)
  @name = name.capitalize
  @health = health
  @found_weapons = Hash.new(0)
end

Public Instance Methods

attack(player, found_weapon) click to toggle source
# File lib/battle_royal/player.rb, line 29
def attack(player, found_weapon)
  @health = health - found_weapon
  print " and attacked #{player.name} \n"
  sleep(0.5)
  puts "#{player.name}'s health is now: #{player.health} \n"
end
each_found_weapon() { |weapon| ... } click to toggle source
# File lib/battle_royal/player.rb, line 40
def each_found_weapon
  @found_weapons.each do |name, points|
    yield Weapon.new(name, points)
  end
end
found_weapon(weapon) click to toggle source
# File lib/battle_royal/player.rb, line 22
def found_weapon(weapon)
  @found_weapons[weapon.name] += weapon.points
  print "\n#{@name} found a #{weapon.name} worth #{weapon.points} damage points"

  @found_weapons[weapon.name]
end
points() click to toggle source
# File lib/battle_royal/player.rb, line 36
def points
  @found_weapons.values.inject(0, :+)
end
score() click to toggle source
# File lib/battle_royal/player.rb, line 46
def score
  points + @health
end
to_s() click to toggle source
# File lib/battle_royal/player.rb, line 14
def to_s
  "#{@name} health = #{@health}, points = #{points}, and score = #{score}"
end