-
Notifications
You must be signed in to change notification settings - Fork 3
/
playGame.py
55 lines (43 loc) · 1.45 KB
/
playGame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import webapp2
import cgi
import os
import jinja2
import wordFunctions
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
newGame = True
gameWord = ""
gameBlack = ""
life = 6 #life points, will decrease upon incorrect guesses
gameDone = False
class PlayGame(webapp2.RequestHandler):
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