class Startupgem::Player

Attributes

found_treasures[R]
health[RW]
name[R]

Public Class Methods

convert(line) click to toggle source
# File lib/startupgem/player.rb, line 15
def self.convert(line)
        name,health = line.split(',')
        Player.new(name,Integer(health))
end
new(name,health=100) click to toggle source
# File lib/startupgem/player.rb, line 9
def initialize(name,health=100)
        @name = name.capitalize
        @health = health
        @found_treasures = Hash.new(0)
end

Public Instance Methods

<=>(other_object) click to toggle source
# File lib/startupgem/player.rb, line 64
def <=>(other_object)
        other_object.score <=> score
end
blam() click to toggle source
# File lib/startupgem/player.rb, line 50
def blam
        @health -= 10
        puts "\t\t#{@name} got blammed!"
end
found_treasure(treasure) click to toggle source
# File lib/startupgem/player.rb, line 32
def found_treasure(treasure)
        @found_treasures[treasure.name] += treasure.points
        puts "\t#{@name} found a #{treasure.name} worth #{treasure.points} points."
        puts "\t#{@name}'s treasures: #{@found_treasures}"
end
name=(new_name) click to toggle source
# File lib/startupgem/player.rb, line 60
def name=(new_name)
        @name = new_name.capitalize
end
points() click to toggle source
# File lib/startupgem/player.rb, line 27
def points
        @found_treasures.values.reduce(0) {|sum,t| sum + t }
        # @found_treasures.values.reduce(0,:+)
end
print_each_treasure() { |treasure| ... } click to toggle source
score() click to toggle source
# File lib/startupgem/player.rb, line 38
def score
        @health + points.to_i
end
strong?() click to toggle source
# File lib/startupgem/player.rb, line 42
def strong?
        health >= 100
end
to_s() click to toggle source
# File lib/startupgem/player.rb, line 46
def to_s
        "\tI'm #{@name} with a health = #{@health}, points = #{points}, score = #{score}."
end
w00t() click to toggle source
# File lib/startupgem/player.rb, line 55
def w00t
        self.health += 15
        puts "\t\t#{@name} got w00ted!"
end