Skip to content

Instantly share code, notes, and snippets.

@chadjemmett
Created September 20, 2012 20:58
Show Gist options
  • Save chadjemmett/3758321 to your computer and use it in GitHub Desktop.
Save chadjemmett/3758321 to your computer and use it in GitHub Desktop.
Why isn't the 'combat' method working?
class Fight
def initialize
Player.new
Monster.new
end #end of the initialize method.
class Player
attr_accessor :ac, :attack, :hp
def initialize
@ac = 12
@attack = 5
@hp = 20
end #end of initialize method.
end #end of the player class.
class Monster
attr_accessor :ac, :attack, :hp
def initialize
@ac = 10
@attack = 4
@hp = 15
end #end of initialize method.
end #end of monster class.
def combat player, monster
unless player.hp == 0 || monster.hp == 0
if player.attack + rand(20) >= monster.ac
monster.hp -= 1
end #end of the if a hit
end #end of the unless checking for zero hp
end #end of combat method.
end #end of the fight class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment