class GamalielPelino::Player

Attributes

health[RW]
name[RW]

Public Class Methods

from_csv(string) click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 45
def self.from_csv(string)
    name, health = string.split(',')
    Player.new(name, Integer(health))
end
new(name, health=100) click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 10
def initialize(name, health=100)
    @name = name.capitalize
    @health = health
    @found_pieces = Hash.new(0)
end

Public Instance Methods

each_found_piece() { |piece| ... } click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 26
def each_found_piece
    @found_pieces.each do |item, points|
    yield Piece.new(item, points)
    end
end
found_piece(itemss) click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 20
def found_piece(itemss)
    @found_pieces[itemss.item] += itemss.points
    puts "#{@name}'s treasures: #{@found_pieces}"
end
points() click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 32
def points
    @found_pieces.values.reduce(0, :+)
end
score() click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 40
def score 
    halt = @health 
    halt += @name.length
end
to_csv() click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 50
def to_csv
"#{@name},#{@health}"
end
to_s() click to toggle source
# File lib/GamalielPelino/Agam11_split1.rb, line 54
def to_s
    "I'm #{@name} with a health of #{@health} and my score is #{score}"
end