[Tutor] Issue With a Python Game
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 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 from pygame.locals import * FPS = 30 WINWIDTH = 800 WINHEIGHT = 600 HALF_WINWIDTH = int(WINWIDTH / 2) HALF_WINHEIGHT = int(WINHEIGHT / 2) TILEWIDTH = 50 TILEHEIGHT = 85 TILEFLOORHEIGHT = 45 CAM_MOVE_SPEED = 5 OUTSIDE_DECORATION_PCT = 20 BRIGHTBLUE = ( 0, 170, 255) WHITE = (255, 255, 255) BGCOLOR = BRIGHTBLUE TEXTCOLOR = WHITE UP = 'up' DOWN = 'down' LEFT = 'left' RIGHT = 'right' def main(): global FPSCLOCK, DISPLAYSURF, IMAGESDICT, TILEMAPPING, OUTSIDECOMAPPING, BASICFONT, PLAYERIMAGES, currentImage pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT)) pygame.display.set_caption('Noah Nickel Adventure!') BASICFONT = pygame.font.Font('freesansbold.ttf', 18) IMAGESDICT = {'uncovered goal': pygame.image.load('RedSelector.png'), 'covered goal': pygame.image.load('Selector.png'), 'star': pygame.image.load('Star.png'), 'corner': pygame.image.load('Wall Block Tall.png'), 'wall': pygame.image.load('Wood Block Tall.png'), 'inside floor': pygame.image.load('Plain Block.png'), 'outside floor': pygame.image.load('Grass Block.png'), 'title': pygame.image.load('star_title.png'), 'solved': pygame.image.load('star_solved.png'), 'princess': pygame.image.load('princess.png'), 'boy': pygame.image.load('boy.png'), 'catgirl': pygame.image.load('catgirl.png'), 'horngirl': pygame.image.load('horngirl.png'), 'pinkgirl': pygame.image.load('pinkgirl.png'), 'rock': pygame.image.load('Rock.png'), 'short tree': pygame.image.load('Tree_Short.png'), 'tall tree': pygame.image.load('Tree_Tall.png'), 'ugly tree': pygame.image.load('Tree_Ugly.png')} TILEMAPPING = {'X': IMAGESDICT['corner'], '#': IMAGESDICT['wall'], 'o': IMAGESDICT['inside floor'], ' ': IMAGESDICT['outside floor']} OUTSIDECOMAPPING = {'1': IMAGESDICT['rock'], '2': IMAGESDICT['short tree'], '3': IMAGESDICT['tall tree'], '4': IMAGESDICT['ugly tree']} #Super important to remember: #DEAR GOD REMEMBER THIS IS AN INDEX OF PLAYER IMAGES. currentImage = 0 PLAYERIMAGES = [IMAGESDICT['princess'], IMAGESDICT['boy'], IMAGESDICT['catgirl'], IMAGESDICT['horngirl'], IMAGESDICT['pinkgirl']] startScreen() levels = readLevelsFile('levels.txt') currentLevelIndex = 0 while True: result = runLevel(levels, currentLevelIndex) if result in ('solved', 'next'): currentLevelIndex += 1 if currentLevelIndex >= len(levels): currentLevelIndex = 0 elif result == 'back': currentLevelIndex -= 1 if currentLevelIndex <0: currentLevelIndex = len(levels)-1 elif result == 'reset': pass def runLevel(levels, levelNum): global currentImage level0bj = levels[levelnum] map0bj = decorateMap(level0bj['map0bj'], level0bj['startState']['player']) gameState0bj = copy.deepcopy(level0bj['startState']) mapNeedsRedraw = True levelSurf = BASICFONT.render('Level %s of %s' % (level0bj['levelNum'] +1, totalNumOfLevels), 1, TEXTCOLOR) levelRect = levelSurf.get_rect() levelRect.bottomleft = (20, WINHEIGHT - 35) mapWidth = len(map0bj) * TITLEWIDTH mapHeight = (len(map0bj[0]) - 1) * (TITLEHEIGHT - TILEFLOORHEIGHT) + TILEHEIGHT MAX_CAM_X_PAN = abs(HALF_WINHEIGHT - int(mapHeight / 2)) + TILEWIDTH MAX_CAM_Y_PAN = abs(HALF_WINWIDTH - int(mapWidth / 2)) + TILEHEIGHT levelIsComplete = False camera0ffsetX = 0 camera0ffsety = 0 cameraUp = False cameraDown = False cameraLeft = False cameraRight = False while
[Tutor] Issue With a Python Game
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 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 error has something to do with the levels. I will attach the code and levels, as they are fairly long. -- A computer without a Microsoft operating system is like a dog without bricks tied to its head. ; Starting demo level: ## # # . # # $ # # .$@$. # $ # #. # # ## # ; 1 ### ## # ## ### # ## $ # # @$ # # ### $### # # #.. # ## ##.# ## # ## # ## ### ; 2 ## # ## ## . # # ## $. # ## $ # ## $@ ### # $ ## #.. ## ## # # ## # # ; 3 # ## # ## # $ ## # $ $# # $ $ # ## ## $ $ $# # .# $ $ # # .# # # # # @ # ## ## ## ; 4 ### ## # @# ### $ $$# # # ##$$$ # # # $ # # ## ## #.. ..$ #*## # ..### # ..# # ; 5 ### ##### ### $ $#$ $ ### # #$ $ # $ $# # # $ ..#.. $ # # $...#...$ # # $ .. * .. $ # ## @ ## # $ .. .. $ # # $...#...$ # # $ ..#.. $ # # #$ $ # $ $# # ### $ $#$ $ ### ##### ### ; 6 ### ###. .$. .### ## $ $ $ ## ## ..$.. ## ##$#$#$## #.$ $.# # @ # ### ### ## $ $ ## #. $ .# ### . ### # ; 7 ## ### ### # # ## ### ### # $ # # $ @ ...*.. $ # # $ $ ## ### ### ### ### # # # ### # # ; 8 ### # ## # ### ## # # ## #@$***. ##$ # # ### .# ## ## # $ # ## .$.# ### ## ## ; 9 # #. .# #.$. . # ## ###@ # # $ ## # $$ ## # $ # # ### ; 10 ## ## # @ ### # # # ..#.#$# # $ $ ##... # # .#$$ # ## ##$## # # $# # # # # ### $# # $ $ # # #$# # # ### ; 11 ### # @ ## # #. .#.### # $$$ $$$ # ###.#.#.# # ## # ### ; 12 # # # # # ### # # # . # # # ## # # # # # # $ $ $ $ $ # ## ## $ # # # ##.. ### $$ ### # ## * ## # $$ # ##+$$ ## # # #.$ $# # #.## # ; 13 ### ### ## # ### # # # # ###$#@ # # # # # # # *. # ##$$# *.## # *..# #...## # #$$$ # # $ # # # ; 14 ### ## # # # *.$.# # *.#.### # #$@$$ # # ## # # ## # # ; 15 #@ # ## # # .$# #$. # ###..$### # ..$ # # $ $ # # # # # # # # ; 16 ## ## # ### ## # # ## # # $.# # ## $ $.# # # #. ## # $. @# # $. ### # #*# # ### .$ # # .$ # ## .# # # #.$ $ ## # #.$ # # ## # # ## ### # ## ## ; 17 ### ## . . . . ### # $$ $ $ $ # # # # ## $ # # # ## $ $ # ### # # ## # # $ # #... # $ ### #... @ $ ## #... $ $ # # # # ; 18 # # # # #$ $ $ # #.*.*.*# #*.*.*.# # $ $ $# #..# #.*.*.*# #$ $ $ # # $ $ $# #$ $ $ # # # #@ # ; 19 # # ### # $ ## ## ## ## # ## # # # ##$ ## # #. #@## $ ## # #.# ##### $ ## # #.# ## $ ## # #.# # ## ## $ ## ## #.# ## ### ## $ # # #.# # #*## ## # # .# # # ##*## # ## # ## # ; 20 # # ##$.# # $ $.# # $@$...# # $$$..## # $ ..# ; 21 # # ### . $ # # $ *.. #$ ## ## $# ..* $ @# # $ . ### # # ; 22 # #@ .### ### $$ $# # # . . ## # # $ # . . ## # ## . $ $$ # # # # ###. # # # # # # ## ### # # .$ # # ## # ### ; 23 ### ## ## # . ..$#$.. . # # $ $ . $ $ # ###$@$### # $ $ . $ $ # # . ..$#$.. . # ## ## ###
Re: [Tutor] A Text Adventure Problem
1. I'm using the terminal to run the code. Using the command - (cd python && python2 game1.py) 2. Using python 2.6 I believe. 3. I'm running Arch Linux at the moment. 4. I'm new to python, but I assume the error must have something to do with not having a way for the program to move to the next area of the code. On Sun, Mar 24, 2013 at 4:58 PM, bob gailer wrote: > On 3/24/2013 3:41 PM, John Bochicchio wrote: > > I've been trying to write a simple test text adventure, but have been > running into serious problems. Here is the error I get when I run it. It > will give me the opening text and lets me make my first choice. > > What did you enter? I will bet is was 'window'. > > Then I get this. > > error "Traceback: (Most recent call last) > file "game1.py", line 104, in > RUNNER (ROOMS, shack_front) > file "game1.py", line 100 in runner > room = map[next] > keyerror= none > > [snip] > > Questions: > 1 - what are you using to run your code? > 2 - Version of Python? > 3 - Operating system? > 4 - Did you think about what the error might mean? > > Observations: > > 1 - The traceback does not match your code, so either you retyped it or > you are using some unusual way of running the program. > > Compare > RUNNER (ROOMS, shack_front) > with > runner (ROOMS, 'shack_front') > > 2 - the error normally would look like KeyError: None rather than keyerror= > none > > 3 - The various room functions have at least one way out of them with no > return statement. The value returned in that case is None. > > 4 - There are many many blank lines in the program making it much harder > to read. In future eliminate most or all of them. > > 5 - Most of us do not have the patience to count down 100 lines. In future > flag the line with something like: > room = map[next] < line 100 > > 6 - quips = ["You've become a zombie and eat you pals. Douche." > > "You've died and left your comrades to fend for themselves. > Douche" > "Your whole group dies because of you. Douche." > "You've got terrible planning skills, and ruined the teams > chances of survival. Douche."] > quips is a list with one element, consisting of one string or 244 > characters. > print quips[randint(0, len(quips)-1)] > will always print the entire string. > Perhaps you meant to put a comma at the end of each line? > > HTH and good luck. > > -- > Bob Gailer919-636-4239 > Chapel Hill NC > > -- A computer without a Microsoft operating system is like a dog without bricks tied to its head. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] A Text Adventure Problem
I've been trying to write a simple test text adventure, but have been running into serious problems. Here is the error I get when I run it. It will give me the opening text and lets me make my first choice. Then I get this. error "Traceback: (Most recent call last) file "game1.py", line 104, in RUNNER (ROOMS, shack_front) file "game1.py", line 100 in runner room = map[next] keyerror= none And here is my code. from sys import exit from random import randint def death(): quips = ["You've become a zombie and eat you pals. Douche." "You've died and left your comrades to fend for themselves. Douche" "Your whole group dies because of you. Douche." "You've got terrible planning skills, and ruined the teams chances of survival. Douche."] print quips[randint(0, len(quips)-1)] exit(1) def shack_front(): print "The year is 2062, and the zombies have risen. You're not a doctor, and you have no training. You're just a guy trying to survive." print ".." * 8 print "You stand in front of a broken down shack, you here gurgles and screams from inside. There is a window to the side of the house that you can see through, or a door you can burst into." print ".." * 8 print "Window or door?" action = raw_input(">") if action == "window": print "You silently walk over to the dirty window. You look inside to see a man held captive by 2 marauders. The marauders are armed with bats, and don't seem to know what they're doing. You have 1 9mm glock with 12 bullets." elif action == "door": print "You burst through the door with your shoulder. You see only one marauder. You shoot him in the chest and notice a man tied up in a chair. You walk over to him but feel a sharp pain in the back of your head. You never saw the second marauder coming." return 'death' else: print "Not a valid command" return 'shack_front' def shack_window(): print "Do you burst through the door or try to fire through the window at the marauders?" action = raw_input(">") if action == "window": print "You fire off three shots through the window. Two in the chest of the first marauder, one in the neck of the other. They fall to the ground, dead. You walk inside to see if the man is okay." elif action == "door": print "You burst through the door and fire two shots into the first marauder. You remember seeing two, so you turn around and put one bullet through the head of the one behind you. You walk over to the man to see if he's okay." else: print "Not a valid command" return 'shack_window' def shack_interior(): print "You ask the man if he is okay." print "He says that he will be fine, and that his name is Carmicheal." print "He says he is an ex marine, but was ambushed by five of them. He believes that three went out on a scavenging party." print "Carmicheal believes that if you wait for them to come back and ambush them, you will be able to get food, ammo, and perhaps even a gun." print "Do you tell him yes, or no?" action = raw_input(">") if action == "yes": print "You tell Carmicheal yes. You both hide in the back of the shack. Carmicheal takes a cleaver and you pull out your glock. 30 minutes pass." print ".." * 10 elif action == "no": print "Carmicheal looks at you puzzled. You ask if he wants to come with you, but he only gets mad. He screams at you for not following the plan, but you walk out." print "You hear a rush of sound as the cleaver hits the back of your skull. You are dead." return 'death' else: print "Not a valid command" return 'shack_interior' def shack_back(): print "You hear the sound of boots in the next room. Carmicheal and you stand up, ready to attack. Do you go in first, or him?" action = raw_input(">") if action == "him": print "Carmicheal goes in first. His cleaver tearing through the neck of the first marauder. You see one trying to pull the gun from his waist. You fire two shots into the marauder, killing him. The third marauder grabs you from behind. You elbow him in the abdomen, leaving Carmicheal just enough room to throw his cleaver into the marauder's head." print "You have both survived. Do you scavenge the dead bodies?" elif action == "me": print "You go in first. You see the three marauders lined up like bowling pins. You let off six shots. Killing first the marauder with the gun, then the two with knives and bats. You easily killed these men without even breaking a sweat. Their bodies lay before you. Do you want to scavenge them?" else: print "Not a valid command." return 'shack_back' ROOMS = { 'death': death, 'shack_front': shack_front, 'shack_window': shack_wi