[Tutor] samples

Alan G alan.gauld at freenet.co.uk
Thu Jun 23 10:06:59 CEST 2005


> What I *am* looking for, if you have it or know of anyone who does,
is
> *simple* source code files (preferrably the entire game's code is in
> one .py file),

Thats unlikely to happen because its very bad practice and
Python tries to make it easy NOT to do that. Breaking code
into modules makes it easier to maintain and easier to reuse.

But the downside is trying to navigate it can be tricky
- especially when you don;t know which one is main...
Try a grep for __main__ to see if you can find the
if "__name__ === " trick. Or try grep for a def main.

In mainstream languages like C/Java you can use a feature
of vim/emacs called tags to navigate code across multiple
files, some IDEs have similar menu options, where you highlight
a function call and say 'go to source' and the IDE finds the
file with the definition... Makes browsing code much easier.

Of course better still is a design document!

> Does anyone have any little "gamelets" like these,

There are several games on Useless Python, including
my guessing games framework (which is from my book) and
the heavily commented code is zipped up on Useless
(hmgui.zip). But most of them don't use the pygame
framework.

HTH,

Alan G.



More information about the Tutor mailing list