#!/usr/bin/env python # # while statement # import time import datetime print "Your objective is to guide your 'o' through this maze. " print "The stars that you see are actually spinning ninja stars. " print "If you run into one, it will kill you. " print "If you do not complete the maze in 60 seconds, the gates at the start and the " print "finish will close and you will be trapped inside the maze to die of starvation. " print "You have 5 chances to make it out of the maze alive. Good luck." # Matthew: by using the \ instead of quote semicolon, you have # created one very long string. Instead, you must create an array of lines. arr = [" ****************************************************************** ", "* * *", "* ** ***** *** ******** ******** * ", "* ** *** ******** ***** * ******** ***** * ", "*** *** ************ ***** ********** * ", "****** ** ****** ************* ********** ", "***** ******** ******** ******* ***** ", "*** ********* *** *********** ************* ***** ", "***** ************* ****** ************* *** ", "*** ***************************** ********* * ", "*** *********** ***************** * ", "******** ****** ****** ************** ** ", "*********** ******************************************************** ", "************ ******** ********* * ", "********************** **** ********** ", "**********************************************************************"] hpos = 0 vpos = 0 lifecount = 5 # Since the basic screen doesn't change, this function is unnecesary. # You can just assign arr to origscreen (in fact, you could have just used arr). origscreen = [] # screen without a "o" origscreen = arr # Matthew, this is all you need def formscreen(): len = 16 origscreen.append(arr) i = 1 while i < len: origscreen i = i+1 def printscreen(): global vpos global hpos global lifecount screen = [] mylen = len(origscreen) i = 0 loseflag = 0 winflag = 0 if (vpos == 14) and (hpos == 69): winflag = 1 print "vpos","hpos:", vpos, hpos while (i < mylen): x = origscreen[i] screen.append(x) if i == vpos: if (x[hpos] == "*"): loseflag = 1 # if (x[vpos] == 14) and (x[hpos] == 69): # how is x[vpos] going to be 14? vpos can be # winflag = 1 x = x[:hpos] + ("o") + x[hpos+1:] screen[i] = x i = i+1 for s in screen: print s if loseflag == 1: lifecount = lifecount - 1 print "You have ", lifecount, "lives remaining." if lifecount > 0: print "You died. Try again." totaltime = 0 hpos = 0 vpos = 0 # formscreen() # Matthew formscreen will repaint origscreen # Matthew, these next three statements do nothing useful. i = 0 x = "" loseflag = 0 if lifecount == 0: print "You failed to complete the maze. That means you suck.\ Go waste someone else's time." i = mylen + 1 # Matthew, why is this statement here? if winflag == 1: print "Congratulations! For surviving my maze with ", lifecount, " lives, \ I will award you ", lifecount, ",000 awesomeness points." print "These points may not be real, but you can still brag about them if you wish." i = mylen + 1 # Matthew, why is this statement here? totaltime = 0 # formscreen() # Matthew, you don't need this because the screen doesn't change i = 0 x = "" hpos = 0 vpos = 0 loseflag = 0 winflag = 0 while x != "s": printscreen() # arr = (" ") + arr # Matthew, why is this statement here? mybeforetime = time.time() # print mybeforetime x = raw_input("Please hit u(up), d(down), l(left), r(right), or s(stop):") myaftertime = time.time() diff = myaftertime - mybeforetime print ("You hit the letter: ") + x if x == "u": vpos = vpos-1 if x == "d": vpos = vpos+1 if x == "l": hpos = hpos-1 if x == "r": hpos = hpos+1 totaltime = totaltime + diff print totaltime i = i+1 print totaltime if totaltime >= int(60): loseflag = 1 lifecount = lifecount - 1 print "You have ", lifecount, "lives remaining." if lifecount > 0: print "You died. Try again." hpos = 0 vpos = 0 i = 0 loseflag = 0 if lifecount == 0: print "You failed to complete the maze. That means you suck. Go waste someone else's time." x = s if winflag == 1: print "Congratulations! For surviving my maze with ", lifecount, " lives, I will award you ", lifecount, ",000 awesomeness points." print "These points may not be real, but you can still brag about them if you wish." x = s