Todd Benson
4/22/2008 7:47:00 PM
On Tue, Apr 22, 2008 at 2:00 PM, Todd Benson <caduceass@gmail.com> wrote:
>
> On Tue, Apr 22, 2008 at 1:36 PM, Ben Galyean <bengalyean@hotmail.com> wrote:
> > Stuck again. My random monster-fight generator works, but it's so BASIC.
> > How can I do this without the if-statements? Is it a bad thing to stick
> > class objects into an array?
> >
> > Also, I know Moblist[0].fight works, but why not Moblist[0..2].fight ?
> >
> >
> > ##############################################
> > class Mob
> > def fight
> > "THIS IS A FIGHT METHOD"
> > end
> > end
> >
> > GOBO = Mob.new
> > DRAGON = Mob.new
> > SLIME= Mob.new
> >
> > Moblist = [GOBO, DRAGON, SLIME]
> >
> > def rand_fight
> > a = rand(Moblist.length)#<-----------Has to be a better way|
> > if a ==0 then GOBO.fight
> > elsif a==1 then DRAGON.fight
> > elsif a==2 then SLIME.fight
> > end#------------------------------------------------------|
> >
> > end
> >
> > p rand_fight
> > ##############################################
>
> I'm not sure why you use constants, but...
>
> class C
> def fight
> puts 'hi, nice to meet you'
> puts 'I am " << self.__id__.to_s
Once again that weird todd person makes a slight mishap :) That double
quote is supposed to be a single one. And I really wanted to say
something a little more sinister, like "So, we meet again }>),
muahaha." but the nice thing is kind of funny.
Todd