-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGameMenu.py
More file actions
186 lines (159 loc) · 3.73 KB
/
GameMenu.py
File metadata and controls
186 lines (159 loc) · 3.73 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
from tkinter import *
from turtle import *
from GameMechanics import *
import random
showMenuAll = True
userInput = ""
labelScore = 0
window = Tk()
window.geometry("500x450")
window.configure(bg="#5d8fee")
canvas = Canvas(
window,
bg="#5d8fee",
height=450,
width=500,
bd=0,
highlightthickness=0
)
canvas.place(x= 0, y= 0)
turtleCanvas = TurtleScreen(canvas)
turtleCanvas.bgcolor("#5d8fee")
pen = RawTurtle(turtleCanvas)
pen.hideturtle()
def showMenuTitle(text, fontSize):
canvas.create_text(
10, -150,
text=text,
fill="white",
font= ("Calibri", int(fontSize)),
tags="menu",
width=450
)
def showQuestion(text, fontSize):
canvas.create_text(
10, -150,
text=text,
fill="white",
font= ("Calibri", int(fontSize)),
tags="menu",
width=450
)
riddle_list = InitializeRiddleList()
riddle_item = RandomRiddleItem(riddle_library=riddle_list)
showMenuTitle("Riddle Game", 37.0)
def tester():
print("printing")
def btnClicked():
global showMenuAll
showMenuAll = False
print("clearing")
canvas.delete("menu")
showQuestion(riddle_item["question"], 12.0)
global userInput
userInput = showEntry()
submitBtn()
showHintBtn()
userInput.bind("<Button-1>", clearPlaceholder)
def showMenuBtn():
if showMenuAll == True:
btnFunc = btnClicked
cordY = 216
else:
btnFunc = tester
cordY = 380
button = Button(
borderwidth=0,
highlightthickness=0,
text="Play",
relief="flat",
bg="#407CF3",
fg="white",
command= lambda:[btnFunc(), button.destroy()],
# command=btnFunc,
)
button.place(
x= 186, y= cordY,
width=127,
height=30
)
# return button
def showInstructions():
canvas.create_text(
0, 150,
text="HOW TO WIN:\n\nAnswer 10 riddles consecutively to win the game. Good luck!",
fill="white",
font=("Calibri", int(10.0)),
tags="menu"
)
canvas.create_text(
0, 200,
text="Made by Harith & Sydney",
fill="white",
font=("Calibri", int(10.0), "italic"),
tags="menu"
)
# tempBtn =
showMenuBtn()
showInstructions()
def showEntry():
entry = Entry(
borderwidth=0,
highlightthickness=0,
relief="flat"
)
entry.place(
x= 186, y= 300,
width=127,
height=30
)
entry.insert(0, "Enter your answer here")
return entry
def clearPlaceholder(e):
userInput.delete(0, "end")
def showScore(score):
label = Label(
text="Score: " + str(score),
bg="#5d8fee",
fg="white"
)
label.place(
x = 430, y = 0
)
def showHintBtn():
hint = Button(
borderwidth=0,
highlightthickness=0,
text="Generate Hint",
relief="flat",
bg="#407CF3",
fg="white",
command= lambda:[readAloud(text="The answer rhymes with " + riddle_item["hints"][generateIndex()]["word"]), generateIndex()]
)
hint.place(
x= 350, y= 400,
width=107,
height=30
)
showScore(score)
def generateIndex():
indexRand = random.randint(0, 5)
print(indexRand, riddle_item["shortened_answer"])
return indexRand
def submitBtn():
submit = Button(
borderwidth=0,
highlightthickness=0,
text="Submit",
relief="flat",
bg="#407CF3",
fg="white",
command=lambda:[verify_answer(user_input=userInput, shortened_answer=riddle_item["shortened_answer"], pen=pen, read_aloud=True)]
)
submit.place(
x=186, y=350,
width=127,
height=30
)
window.resizable()
window.mainloop()