-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
279 lines (212 loc) · 8.61 KB
/
main.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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
from tkinter import *
from PIL import ImageTk, Image
import random
import mysql.connector as mysql
from turtle import turtle
from reflex import reflex
consolewindow = Tk()
consolewindow.title("VVLC Gaming Console")
consolewindow.geometry("600x300")
p1 = PhotoImage(file='./assets/game.png')
consolewindow.iconphoto(False, p1)
con = mysql.connect(host="localhost", passwd="admin", user="root")
cursor = con.cursor()
cursor.execute("CREATE DATABASE IF NOT EXISTS VVLCDATABASE")
cursor.execute("USE VVLCDATABASE")
cursor.execute("CREATE TABLE IF NOT EXISTS PLAYERINFO (NAME VARCHAR(30), USERNAME VARCHAR(30), PASSWORD VARCHAR(30), REFLEXSCORE INT, TURTLEWINS VARCHAR(255))")
con.commit()
over = False
def loginer(text=None):
global over
loginwindow = Toplevel(consolewindow)
loginwindow.geometry("300x400")
uname_var = StringVar()
passw_var = StringVar()
spassw_var = StringVar()
suname_var = StringVar()
sname_var = StringVar()
def signinfn():
global over
over = False
cursor.execute("SELECT * FROM PLAYERINFO")
profilelist = cursor.fetchall()
username = uname_var.get()
password = passw_var.get()
print("The username is : " + username)
print("The password is : " + password)
uname_var.set("")
passw_var.set("")
for i in profilelist:
if username == i[1] and password == i[2]:
over = username
loginwindow.quit()
loginwindow.destroy()
def signupfn():
global over
over = False
exists = False
name = sname_var.get()
username = suname_var.get()
password = spassw_var.get()
print("The username is : " + username)
print("The name is : " + name)
print("The password is : " + password)
suname_var.set("")
spassw_var.set("")
sname_var.set("")
cursor.execute("SELECT * FROM PLAYERINFO")
profilelist = cursor.fetchall()
if len(name) > 30 or len(password) > 30 or len(username) > 30 or password is None or name is None or username is None:
exists = True
for i in profilelist:
if username == i[1]:
exists = True
break
if exists == False:
cursor.execute(f"INSERT INTO PLAYERINFO VALUES('{name}', '{username}', '{password}', 0, 'None')")
con.commit()
over = username
loginwindow.quit()
loginwindow.destroy()
txtlabel = Label(loginwindow, text=text, justify="center", font=('calibre', 20, 'bold'))
txtlabel2 = Label(loginwindow, text="Signin", justify="center", font=('calibre', 20, 'bold'))
txtlabel3 = Label(loginwindow, text="(OR)", justify="center", font=('calibre', 20, 'bold'))
txtlabel4 = Label(loginwindow, text="Signup", justify="center", font=('calibre', 20, 'bold'))
uname_label = Label(loginwindow, text='Username')
uname_entry = Entry(loginwindow, textvariable=uname_var)
uname_label2 = Label(loginwindow, text='Username')
uname_entry2 = Entry(loginwindow, textvariable=suname_var)
name_label = Label(loginwindow, text='Name')
name_entry = Entry(loginwindow, textvariable=sname_var)
passw_label = Label(loginwindow, text='Password')
passw_entry = Entry(loginwindow, textvariable=passw_var, show='*')
passw_label2 = Label(loginwindow, text='Password')
passw_entry2 = Entry(loginwindow, textvariable=spassw_var, show='*')
signin = Button(loginwindow, text="Signin", command=signinfn)
signup = Button(loginwindow, text="Signup", command=signupfn)
txtlabel.pack()
txtlabel2.pack()
uname_label.pack()
uname_entry.pack()
passw_label.pack()
passw_entry.pack()
signin.pack()
txtlabel3.pack()
txtlabel4.pack()
uname_label2.pack()
uname_entry2.pack()
name_label.pack()
name_entry.pack()
passw_label2.pack()
passw_entry2.pack()
signup.pack()
loginwindow.mainloop()
return over
def turtlegame():
player1 = False
player2 = False
while player1 == False:
player1 = loginer(text="Player 1")
while player2 == False:
player2 = loginer(text="Player 2")
turtle.game(player1, player2, consolewindow)
def reflexgame():
player = False
while player == False:
player = loginer(text="Singleplayer")
reflex.game(player, consolewindow)
def randomgame():
randgame = random.choice(["turtle", "reflex"])
if randgame == "turtle":
turtlegame()
elif randgame == "reflex":
reflexgame()
def exitwindow():
consolewindow.quit()
consolewindow.destroy()
def credits():
window = Toplevel(consolewindow)
window.geometry("350x325")
p1 = PhotoImage(file='./assets/game.png')
window.iconphoto(False, p1)
window.title("VVLC Creators")
label1 = Label(window, text="Creators of VVLC", justify="center", font=('calibre', 25, 'bold'))
label2 = Label(window, text="Vignesh.T.A\nRollno:- 29\n\nV.Viswesh Kissan\nRollno:- 28\n\nV.Lathish\nRollno:- 27\n\nK.Charan\nRollno:- 22", font=('calibre', 15, 'bold'))
label1.pack()
label2.pack()
def leaderboard():
window = Toplevel(consolewindow)
window.geometry("350x500")
p1 = PhotoImage(file='./assets/trophy.png')
window.iconphoto(False, p1)
window.title("VVLC Leaderboard")
label3 = Label(window, text="Leaderboard", justify="center", font=('calibre', 20, 'bold'))
label3.grid(row=0, column=0, columnspan=5)
label4 = Label(window, text="Rank")
label4.grid(row=1, column=0, sticky="w")
label5 = Label(window, text="Name")
label5.grid(row=1, column=1, sticky="w")
label6 = Label(window, text="Username")
label6.grid(row=1, column=2, sticky="w")
label7 = Label(window, text="Reflex Score")
label7.grid(row=1, column=3, sticky="w")
label8 = Label(window, text="Turtle Wins")
label8.grid(row=1, column=4, sticky="w")
cursor.execute("SELECT * FROM PLAYERINFO ORDER BY REFLEXSCORE DESC")
data = cursor.fetchall()
for i in range(len(data)):
rec = data[i]
position = str(i+1)
name = rec[0]
username = rec[1]
reflexscore = rec[3]
turtlewins = rec[4]
if i == 0:
bolder = "bold"
else:
bolder = "normal"
label9 = Label(window, text=position, font=('calibre', 10, bolder))
label9.grid(row=i+2, column=0)
label10 = Label(window, text=name, font=('calibre', 10, bolder))
label10.grid(row=i+2, column=1)
label11 = Label(window, text=username, font=('calibre', 10, bolder))
label11.grid(row=i+2, column=2)
label12 = Label(window, text=str(reflexscore), font=('calibre', 10, bolder))
label12.grid(row=i+2, column=3)
label13 = Label(window, text=turtlewins, font=('calibre', 10, bolder))
label13.grid(row=i+2, column=4)
def documentation():
window = Toplevel(consolewindow)
window.geometry("300x600")
p1 = PhotoImage(file='./assets/documentation.png')
window.iconphoto(False, p1)
window.title("VVLC Documentation")
f = open("README.txt")
fdata = f.read()
f.close()
label1 = Label(window, text="README.txt")
label2 = Label(window, text=fdata)
label1.pack()
label2.pack(anchor="w")
canvas = Canvas(consolewindow, width=600, height=300)
canvas.pack()
img0 = Image.open("./assets/VVLC.jpg")
img0 = img0.resize((600, 300), Image.ANTIALIAS)
img0 = ImageTk.PhotoImage(img0)
bgimg = canvas.create_image(300, 150, image=img0)
turtlebtn = Button(consolewindow, text="Play Turtle Race", command=turtlegame)
canvas.create_window(300, 20, window=turtlebtn)
wcfbtn = Button(consolewindow, text="Play Reflex Game", command=reflexgame)
canvas.create_window(300, 50, window=wcfbtn)
randbtn = Button(consolewindow, text="Random Game", command=randomgame)
canvas.create_window(300, 80, window=randbtn)
creditsbtn = Button(consolewindow, text="Leaderboard", command=leaderboard)
canvas.create_window(300, 110, window=creditsbtn)
leaderboardbtn = Button(consolewindow, text="Credits", command=credits)
canvas.create_window(300, 140, window=leaderboardbtn)
documentationbtn = Button(consolewindow, text="Documentation", command=documentation)
canvas.create_window(300, 170, window=documentationbtn)
exitbtn = Button(consolewindow, text="Exit", command=exitwindow)
canvas.create_window(300, 200, window=exitbtn)
consolewindow.mainloop()
con.close()