-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRegistration.py
198 lines (165 loc) · 6.71 KB
/
Registration.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
import sqlite3
from Scripts.NPCClass import*
from Scripts.Items import*
from appJar import gui
win = gui("Register", "800x600")
#win.setBg("SteelBlue")
win.setBg("Yellow")
win.setImageLocation("Graphics")
win.setFont(18)
TeacherCode="1234"
def start():
win.removeAllWidgets()
win.addLabel("lb1","Welcome")
win.addButtons(["Login","Registration","Exit"],press)
##Registration
def Registration():
win.removeAllWidgets()
win.addLabel("lb2","Who are You?")
win.addButtons(["Student","Teacher"],pressReg)
win.addButtons(["Exit","Back"],pressReg)
def StudentLog():
win.removeAllWidgets()
win.addLabel("lb2","All Fields are compulsory")
win.addLabelEntry("Username")
win.addLabelEntry("Name")
win.addLabelEntry("Surname")
win.addLabelEntry("Email")
win.addLabelEntry("Password")
win.addLabelEntry("Repeat password")
win.addLabelEntry("CharacterName")
Classroom = win.addLabelEntry("Classroom")
win.addButtons(["Submit","Back","Exit"],pressRegS)
def TeacherLog():
win.removeAllWidgets()
win.addLabel("lb2","All Fields are compulsory")
win.addLabelEntry("Username")
win.addLabelEntry("Name")
win.addLabelEntry("Surname")
win.addLabelEntry("Email")
win.addLabelEntry("Password")
win.addLabelEntry("Repeat password")
win.addLabelEntry("Teacher Code")
win.addButtons(["Submit","Back","Exit"],pressRegT)
def press(button):
if button == "Exit":
win.stop()
elif button=="Login":
Login()
elif button=="Registration":
Registration()
def pressReg(button):
if button == "Exit":
win.stop()
elif button == "Back":
start()
elif button == "Student":
StudentLog()
elif button == "Teacher":
TeacherLog()
def pressRegS(button):
if button == "Exit":
win.stop()
elif button=="Back":
Registration()
elif button=="Submit":
Username = win.getEntry("Username")
Name = win.getEntry("Name")
Surname = win.getEntry("Surname")
Email = win.getEntry("Email")
Password = win.getEntry("Password")
Password1 = win.getEntry("Repeat password")
Classroom = win.getEntry("Classroom")
CharacterName= win.getEntry("CharacterName")
Level=1
Health = 100
ATK = 20
DEF = 5
AttackPotion=0
DefendPotion=0
if Password == Password1:
conn = sqlite3.connect("GameDatabase.db")
c = conn.cursor()
c.execute ('INSERT INTO Sensible_Dettails VALUES(?,?,?)',(Username,Password,Email))
c.execute ('INSERT INTO Students VALUES(?,?,?,?)',(Name,Surname,Username,Classroom))
c.execute ('INSERT INTO Character_Stats VALUES(?,?,?,?,?,?,?,?)',(Username,CharacterName,Level,Health,ATK,DEF,DefendPotion,AttackPotion))
c.execute ('INSERT INTO Scores VALUES(?,0,0,0,0,0,0,0,0,0,0,0,0)',(Username,))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,CharacterName,"1","Prova.map"))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,npcFight.name,npcFight.Alive,npcFight.mapping))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,npcSpeech.name,npcSpeech.Alive,npcSpeech.mapping))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,npcChallenge.name,npcChallenge.Alive,npcChallenge.mapping))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,ItemHealth.name,ItemHealth.Taken,ItemHealth.mapping))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,ItemAttack.name,ItemAttack.Taken,ItemAttack.mapping))
c.execute ('INSERT INTO Saves (Username,EntityName,Status,Map)VALUES(?,?,?,?)',(Username,Door1.name,Door1.Taken,Door1.mapping))
conn.commit()
c.close()
conn.close()
Login()
else:
win.infoBox("Error","Data Inputted invalid try again")
return press
def pressRegT(button):
if button == "Exit":
win.stop()
elif button=="Back":
Registration()
elif button=="Submit":
Username = win.getEntry("Username")
Name = win.getEntry("Name")
Surname = win.getEntry("Surname")
Email = win.getEntry("Email")
Password = win.getEntry("Password")
Password1 = win.getEntry("Repeat password")
SubmittedCode = win.getEntry("Teacher Code")
if Password == Password1 and TeacherCode==SubmittedCode:
conn = sqlite3.connect("GameDatabase.db")
c = conn.cursor()
c.execute ('INSERT INTO Teachers VALUES(?,?,?)',(Username,Name,Surname))
c.execute ('INSERT INTO Sensible_Dettails VALUES(?,?,?)',(Username,Password,Email))
conn.commit()
c.close()
conn.close()
Login()
else:
win.infoBox("Error","Data Inputted invalid try again")
return press
##Login
def Login():
win.removeAllWidgets()
win.addLabel("lb1","Log in")
win.addLabelEntry("Username")
win.addLabelSecretEntry("Password")
win.addButtons(["Registration","Submit","Exit"],pressLog)
def pressLog(button):
if button == "Exit":
win.stop()
elif button =="Registration":
Registration()
elif button == "Submit":
usr = win.getEntry("Username")
pas = win.getEntry("Password")
conn = sqlite3.connect("GameDatabase.db")
c = conn.cursor()
find_user = ('SELECT Password FROM Sensible_Dettails WHERE Username = ? AND Password = ?')
c.execute(find_user,[(usr),(pas)])
results = c.fetchall()
find_role = ('SELECT Username FROM Teachers WHERE Username= ?')
c.execute(find_role,[(usr)])
Roleresults=c.fetchall()
if len(Roleresults)==1:
for i in results:
win.stop()
import TeacherChecking
elif results:
for i in results:
win.stop()
LogUser=usr
file=open("LogUser.txt","w")
file.write(LogUser)
file.close()
import RPGGame
else:
win.infoBox("Error","Invalid Username or Password")
win.setFocus("Username")
start()
win.go()