Created
March 16, 2013 09:43
-
-
Save anonymous/5175690 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def initialize name, health=100 | |
@name = name.capitalize | |
@health = health | |
end | |
def say_hello | |
if @health >= 1 | |
puts "I'm #{@name} with a health of #{@health}." | |
else | |
puts "#{@name} is dead!!" | |
end | |
end | |
def blam | |
apply_damage 25, "blammed" | |
end | |
def woot | |
apply_damage 25, "wooted" | |
end | |
def apply_damage amount, damage_name | |
@health = @health - amount | |
if @health == 0 | |
puts "#{@name} is dead!!" | |
elsif @health >= 1 | |
puts "#{@name} just got #{damage_name} for #{amount} hp and now has #{@health}!!" | |
else @health <= -1 | |
puts "You #{damage_name} #{@name} !!! WTH, Stop beating #{@name} to death, he already is a corpse!!" | |
end | |
end | |
end | |
player1 = Player.new("moe") | |
player2 = Player.new("larry", 60) | |
player3 = Player.new("curly", 125) | |
puts player1.say_hello | |
puts player1.blam | |
puts player1.say_hello | |
puts player1.blam | |
puts player1.say_hello | |
puts player1.blam | |
puts player1.say_hello | |
puts player1.blam | |
puts player1.blam | |
puts player1.say_hello | |
puts player2.say_hello | |
puts player3.say_hello | |
puts player1.woot | |
puts player1.blam | |
puts player1.blam | |
puts player1.blam |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment