[Tutor] Python game - robot

Gerrit Holl gerrit at nl.linux.org
Sat Nov 29 15:12:43 EST 2003


Leung Cris wrote:
> I'm 3/4 through programming this game - a player in the middle, robots 
> chase you. Player touch robot, player dies. Robot touch each other, they 
> die. But I got stuck to the part where they "teach" you how to make 
> multiple robots. They said use an empty list, but I simply don't get it. 
> This is from the livewire package :www.livewires.org.uk/python . Worksheet 
> 5- robot.

I don't see which part of which tutorial you mean, but I think I know
your question - if not, maybe you can clarify it. I'm guessing here. Is
it true that, until know, you created robots just with code like

foo = Robot()
bar = Robot()

?

But know you want to create X different robots...?

If so, you can do so like this:

L = []
for i in range(X):
    L.append(Robot())

This creates X robots without a "name". They can be accessed through the
list: L[0], L[1], L[2], etc. They do not have a name binding in your
namespace: the only reference to their objects is through the list L.

Maybe this answered your question or maybe this helps you in answering
your question. If not, clarifying your question may help...

yours,
Gerrit.

-- 
15. If any one take a male or female slave of the court, or a male or
female slave of a freed man, outside the city gates, he shall be put to
death.
          -- 1780 BC, Hammurabi, Code of Law
-- 
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/



More information about the Tutor mailing list