On Tue, 2 Jan 2001 16:33:01 +0900, Kevin Smith wrote:

> >Here I think I'd be looking at an array or some other collection:

> >  planets.each do |planet|
> >    planet.ships += planet.production
> >  end
 
> I happen to be writing a similar game right now :-)
 
> And yes, I have an Array of Ship objects, and an 
> Array of Planet objects. Works great. Highly 
> recommended.

well, i don't know how much detail your ships have, but mine don't really
have any, they are just numbers associated with a planet or a fleet.


this is the python planet class:


#!/usr/bin/python

import string
from whrandom import *

class planet:
      def __init__(self,x=100,y=100): 
          self.x=randint(1,x)
          self.y=randint(1,y)
	  self.production=randint(1,10)
	  self.ships=randint(1,100)
          self.owner="aliens"

      def name(self,planet):
          self.name=planet
      
      def upkeep(self):
          self.ships=self.ships+self.production

      def newowner(self):
          if self.owner=="player":
             self.owner="aliens"
          else:
             self.owner="player"
        

and this is the code that init's all the planets:


#!/usr/bin/python

import string, gebplanet, gebfleet,time

for letter in string.lowercase:
    exec '%s=gebplanet.planet()' % letter
    exec '%s.name(letter)' % letter


later on when i need planet upkeep:

for letter in string.lowercase:
    exec '%s.upkeep' % letter




nothing fancy. no arrays, or hashes, or hashes of arrays, etc. the python
code is very clean, readable, but most of all logical. i'm hoping the finished 
ruby code will be also

i'm trying to keep it very 'object oriented'. i don't feel that anything
that belongs to a 'planet' should be outside of it's class...

at any rate, it's only a simple strategy game (check the 'GEB' link at the
url below) for the palmpilot and windows version of the game...


-- 
*----------------------------------------
| 
|http://www.biosys.net/snowzone
|
|remove myspleen to email
|
*-----------------------