T
Thufir
The below uses pseudo-random number generation to populate an array
with various monsters, all inherit from Creature. Can a list of
classes which inherit from Creature be generated automagically? There
must be a better technique to fill the array then the case
statement...
C:\code>
C:\code>
C:\code>type Driver.rb
require 'ArrayOfCreatures'
require 'Creature'
require 'AssistantViceTentacleAndOmbudsman'
require 'Dragon'
require 'DwarvenAngel'
require 'TeethDeer'
puts "\nquantity of creatures:"
numOfCreatures = gets.chomp.to_i
someCreatures = ArrayOfCreatures.new
0.upto(numOfCreatures) do |i|
creatureType = Kernel.rand(4)
case creatureType
when 0
someCreatures=AssistantViceTentacleAndOmbudsman.new
when 1
someCreatures=Dragon.new
when 2
someCreatures=DwarvenAngel.new
when 3
someCreatures=TeethDeer.new
end
end
someCreatures.toString
C:\code>
C:\code>
thanks,
Thufir
with various monsters, all inherit from Creature. Can a list of
classes which inherit from Creature be generated automagically? There
must be a better technique to fill the array then the case
statement...
C:\code>
C:\code>
C:\code>type Driver.rb
require 'ArrayOfCreatures'
require 'Creature'
require 'AssistantViceTentacleAndOmbudsman'
require 'Dragon'
require 'DwarvenAngel'
require 'TeethDeer'
puts "\nquantity of creatures:"
numOfCreatures = gets.chomp.to_i
someCreatures = ArrayOfCreatures.new
0.upto(numOfCreatures) do |i|
creatureType = Kernel.rand(4)
case creatureType
when 0
someCreatures=AssistantViceTentacleAndOmbudsman.new
when 1
someCreatures=Dragon.new
when 2
someCreatures=DwarvenAngel.new
when 3
someCreatures=TeethDeer.new
end
end
someCreatures.toString
C:\code>
C:\code>
thanks,
Thufir