[Tutor] Issue With a Python Game

Mark Lawrence breamoreboy at yahoo.co.uk
Sun Apr 14 19:41:00 CEST 2013


On 13/04/2013 14:13, John Bochicchio wrote:
> I have a question about a game I am making. I finished the overall code,
> but keep getting errors when I try to play. This is my most common error:
> C:\Users\John\Documents\Python Games\Noah>python nickeladventuredemo.py
> Traceback (most recent call last):
>    File "nickeladventuredemo.py", line 451, in <module>
>      main()
>    File "nickeladventuredemo.py", line 78, in main
>      levels = readLevelsFile('levels.txt')
>    File "nickeladventuredemo.py", line 371, in readLevelsFile
>      assert startx != None  and starty!= None, 'Level %s (around line
> %s) in %s i
> s missing a "@" or "+" to mark the start point.' % (levelNum+1, lineNum,
> filenam
> e)
> AssertionError: Level 1 (around line 10) in levels.txt is missing a "@"
> or "+" t
> o mark the start point.
>
> The Code:
> import random, sys, copy, os, pygame
>

I've stripped the remaining 450 lines of code as it's got the dread 
double spaced google disease, please see my signature.  You're also far 
more likely to get responses if your question follows the guidelines 
given here http://www.sscce.org/, particularly if someone already has 
pygame installed, which I don't.

However I did note one area where you can simplfy your code.  You've 
many lines using this type of construct.

for i in range(len(ships)):
     doSomething(ships[i])

There's rarely a need for this in Python.  Use this instead.

for ship in ships:
     doSomething(ship)

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence



More information about the Tutor mailing list