From: Hugh Sasse Date: 2008-11-04T04:14:16+09:00 Subject: Re: Text Based RPG in Ruby On Tue, 4 Nov 2008, Ruairidh Mchardy wrote: > Hi, > > Just modified my code a little and now have: > > Grunty = Grunt.new(100, 300, 300, "Ak47") Grunty is a constant. (Capital letter). Probably not what you want. > randy = rand(100) > Health = Grunt.hp - randy ^^ also a constant. > puts "Grunty is battling a kitten!" puts "#{grunty.name} is battling #{article} #{enemy.name}" > puts "The kitten attacks Grunty with an AK47 and inflicts #{randy} > points of damage!" > puts "Grunty lost #{randy} health!" > puts "Grunty's hp is #{Health} " > > So Grunty is my monster and I'm checking the starting vars from the > Grunt class, then subtracting hitpoints from a random value. So perhaps > I should do my checks of if Grunt.hp == 0 then blah in the attack class? ..in the attack *method*. Yes. > > Attached is my (albeit messy) code so far! > Not sure what happened to that, didn't reach the mailing list. Well, it didn't reach me anyway. > Hugh, > > Very true in regards to learning from others, I just feel that I > couldn't emulate that coding style as I don't understand it > sufficiently. It's very frustrating! Did you look at the stuff that only uses modules, and no metaclasses at all? It takes a bit of getting used to, but I think that code is easier. Anyway, maybe you don't need to vary your traits that much if all characters have @hit_points, @charisma, @damage (weapon power), @inventory = [], @description, @name. It can get really complicated simulating all this stuff, especially if you want to take account of where you are: "You cannot use a two-handed sword in a narrow passage -- at least, not without upsetting the landlord." > > Thanks for the help guys! > > Kind Regards, > > Ruairidh McHardy > -- > Posted via http://www.ruby-forum.com/. > Hugh