Created
September 20, 2012 20:58
-
-
Save chadjemmett/3758321 to your computer and use it in GitHub Desktop.
Why isn't the 'combat' method working?
This file contains hidden or 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 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