Thufir Hawat
11/7/2007 9:16:00 PM
In Driver, I was considering creating a pseudo-random number between 0
and 4, then using case:
case 0
AssistantViceTentacleAndOmbudsman
case 1
Dragon
case 2
DwarvenAngel
case 3
IntrepidDecomposedCyclist
case 4
TeethDeer
so that the array of Creatures is filled with a variety of monsters
which inherit from Creature. However, there's gotta be another way.
Perhaps ask Creature what its sub-classes are? Then randomly select
from that list/array of monsters?
Here's the code:
C:\code>
C:\code>type Driver.rb
require 'ArrayOfCreatures'
require 'Dragon' #Dragon inherits
from Creature
require 'Creature' #Subclasses
include: Dragon, TeethDeer, etc
#numOfCreatures=Kernel.rand(3)
puts "\nquantity of creatures:"
numOfCreatures = gets.chomp.to_i
someCreatures = ArrayOfCreatures.new
0.upto(numOfCreatures) do |i|
someCreatures[i]=Dragon.new #what about other
types (children/sub-classes) of creature?
print "\n"
print "someCreatures["
print i
print "]:\n"
print someCreatures[i].toString
end
C:\code>
thanks,
Thufir