#RubyRPG Project. Coded by Ruairidh Wynne-McHardy. #Would prefer to be in bed right now or at least in the pub but instead I sacrifice endless hours # coding a rather odd RPG game! #Let's create a basic class for the evil Monsters! class Enemy def initialize(hp,attack,defense) @hp = hp @attack = attack @defense = defense end end #Testing shows that this works. The world is full of happiness once more! #Shall we extend Mr.Bond? class Grunt < Enemy def initialize(hp,attack, defense, weapon) super(hp, attack, defense) @weapon = "AK47" @hp =hp end end #Added a new Monster named Grunty (Can you guess why?). Added property of weapon. #Now to see if it has an AK47! Grunto = Grunt.new(100, 300, 300, "Ak47") def Grunto.hp hp = 100 end #Time for the damage calculation stuff! randy = rand(100) puts "Grunty is battling a kitten!" puts "The kitten attacks Grunty with an AK47 and inflicts #{randy} points of damage!" puts "Grunty lost #{randy} health!" if Grunto.hp == 0 puts "Grunty is dead!" else puts "Grunty is wounded but can still fight!" end Health = Grunto.hp - randy puts "Grunty's hp is #{Health}" #Right everything's working though damage should be randomized through attack points