Classes referencing each other

Manuel Bleichner manuel at prolink.de
Fri Sep 1 06:45:52 EDT 2006


Hi, thanks for your answer, too :)

Your solution won't do it, because of reasons I explained
in the answer to Georg Brandl.

> BTW, care to tell us what the connections mean? Applications of
> connected instances of the one class are of course very common, but 50
> classes connected in a cyclic fashion is rather new to me ...

Okay, I didn't want to do this, because some of you would
think I'm crazy, but what the heck :D

I'm programming a browsergame which is split in multiple parts.
There is a core which is running all the time and a cgi client connecting
to it. The core maintains all classes and keeps the game running, while
the client only requests data from it.
The core of course needs to hold all the definitions for the game
(e.g. units, buildings, resources, research) - these are written as
classes.

class EMCenter(Building, Researcher, Constructor, OnLand):
   maxhitpoints = 1000
   researchspeed = 70
   constructspeed = 50
   research_costs = [SmallEM, Weapons, Shields]
   resource_costs = [Iron: 500, Granite: 300, Silicon: 150]
   possible_research = [MediumEM, EMWeapons, EmShockwave]
   possible_constructs = [Razor, Lancer, Stinger]            # these are  
all units

Now when a certain unit should be built, it must be checked if
the requirements are matched.
=> check research_costs and resource_costs
After building it, an instance of the class will be created.
The new object can itself build (=> Constructor) and research
(=> Researcher) the items provided in possible_constructs and
possible_research.

The problem occured when i wanted to define a unit that can
construct a building which itself is able to construct that
unit.

Absolutely overkill for a browsergame, I know, but I like the concept =)


Manuel



More information about the Python-list mailing list