From: Ruairidh Mchardy Date: 2008-11-04T05:36:05+09:00 Subject: Re: Text Based RPG in Ruby Hugh Sasse wrote: > 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 Wow didn't expect quite so many replies! It seems I have a lot to learn but it's highly enjoyable (after coffee). I realize that my structuring is definitely rather odd... I think my problem is that I haven't fully learnt the grammar of Ruby and am probably suffering from a lack of planning in my game design. I hadn't really taken into account all the work it requires! I think I'll be recoding a lot of this project after seeing the replies as my current code (now attached, forgot last time!) is far too messy. Thanks guys! Kind Regards, Ruairidh Wynne-McHardy Attachments: http://www.ruby-forum.com/attachment/2888/main.rb -- Posted via http://www.ruby-forum.com/.