def post(self): global newGame global usedLetter global gameWord global gameBlank global life global gameDone if newGame: usedLetter = [] gameWord = wordFunctions.getWord() #getting the word rand gameBlank = wordFunctions.createBlank(gameWord) if gameDone: pass else: pageVar = {'blank': wordFunctions.printBlank(gameBlank)} page = JINJA_ENVIRONMENT.get_template('playGame.html') self.response.write(page.render(pageVar)) newGame = False userInput = cgi.escape(self.request.get('letterGuess')) if userInput in usedLetter: self.response.write("\nYou already used that letter") elif userInput in gameWord: gameBlank = wordFunctions.updateBlank(userInput, gameWord, gameBlank) else: life -= 1 usedLetter.append(userInput) if '_' not in gameBlank: gameDone = True
def post(self): global newGame global usedLetter global gameWord global gameBlank global life global gameDone if newGame: usedLetter = [] gameWord = wordFunctions.getWord() # getting the word rand gameBlank = wordFunctions.createBlank(gameWord) if gameDone: pass else: pageVar = {"blank": wordFunctions.printBlank(gameBlank)} page = JINJA_ENVIRONMENT.get_template("playGame.html") self.response.write(page.render(pageVar)) newGame = False userInput = cgi.escape(self.request.get("letterGuess")) if userInput in usedLetter: self.response.write("\nYou already used that letter") elif userInput in gameWord: gameBlank = wordFunctions.updateBlank(userInput, gameWord, gameBlank) else: life -= 1 usedLetter.append(userInput) if "_" not in gameBlank: gameDone = True
def post(self): global newGame global usedLet global gameWord global gameBlank global turnsNeeded global turnsTake global life global score global begin global gameDone global liveOrDead global timer global category if newGame: usedLet = [] #will be used to store letter guesses to make sure the user does not repeatedly answer with the same letter if "animals" in self.request.url: gameWord = wordFunctions.getWord("animals") #getting the word randomly from the array category = "animals" elif "pokemon" in self.request.url: gameWord = wordFunctions.getWord("pokemon") category = "pokemon" else: gameWord = wordFunctions.getWord("food") category = "food" gameBlank = wordFunctions.createBlank(gameWord) #creating the blanks turnsNeeded = wordFunctions.getTurnNeed(gameWord) #number of turns needed to win the game turnsTake = 0 #counter for number of turns taked life = 6 #life points, will decrease upon incorrect guesses score = 0 #high score which will be totaled later begin = time.time() #gets the time in seconds past gameDone = False #shows when the game is done liveOrDead = True #shows when the person looses all life, assumes that they will win if gameDone: #if the game is done, total high score and store it in database end = time.time() #gets the time in seconds timer = int(end - begin) if liveOrDead: score = (abs(turnsTake - turnsNeeded) * (6 - life)) + timer #high score formula else: score = (abs(turnsTake - turnsNeeded) * (6 - life)) + timer + int(50 * (len(gameWord) / 1.5)) #death penalty scoreBase.enterScore(gameWord, score, category, timer) pageVar = {'status': liveOrDead, 'word': gameWord, 'score': score} page = JINJA_ENVIRONMENT.get_template('endGame.html') self.response.write(page.render(pageVar)) newGame = True #prepare to create a new game else: #otherwose, write out for user input pageVar = {'blank': wordFunctions.printBlank(gameBlank), 'life': life, 'used': usedLet, 'cat': category} page = JINJA_ENVIRONMENT.get_template('gamePlay.html') self.response.write(page.render(pageVar)) newGame = False """user input and message""" userInput = cgi.escape(self.request.get('message')) userInput = str(userInput).lower() """input validation and gameplay section""" if not userInput.isalpha() and userInput != '': #input validation checking for only letters self.response.write("\nIncorrect Input. Only letters allowed.") elif userInput in usedLet: #ensures that a player doesn't guess the same thing self.response.write("\nYou already used that letter!") elif len(gameWord) == len(userInput): #checks to see if the words are of equal length, only valid word guess if gameWord == userInput: #checks to see if the words are the same gameBlank = gameWord else: life = 0 #automatic loss turnsTake += 1 elif len(userInput) == 1: #checks to make sure that it is a valid letter guess if userInput in gameWord: gameBlank = wordFunctions.updateBlank(userInput, gameWord, gameBlank) #this program does not deal with any upper case letters, guess converted to lowercase else: life -= 1 #bad guess, lose a life point usedLet.append(userInput) #adds the guess to the array to be compared later turnsTake += 1 elif len(userInput) != 0: #input is invalid because you did not guess a word of equal length or a letter self.response.write("\nInvalid Input. Remember only guess a letter OR the entire word.\n") """game win or loss section""" if '_' not in gameBlank: #win condition, if all blanks are filled gameDone = True elif life == 0: #lose condition, if life goes to zero gameDone = True liveOrDead = False if len(userInput) != 0: page = JINJA_ENVIRONMENT.get_template('loading.html') self.response.write(page.render({}))