-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_db.py
95 lines (77 loc) · 2.56 KB
/
score_db.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
import sqlite3
def create_table():
connection = sqlite3.connect("data.db")
cursor = connection.cursor()
query = '''CREATE TABLE IF NOT EXISTS Score(
ID INTEGER PRIMARY KEY AUTOINCREMENT,
NAME VARCHAR(80) UNIQUE,
AI_EASY_WINS INT DEFAULT 0,
AI_EASY_LOSES INT DEFAULT 0,
AI_EASY_TIES INT DEFAULT 0,
AI_MEDIUM_WINS INT DEFAULT 0,
AI_MEDIUM_LOSES INT DEFAULT 0,
AI_MEDIUM_TIES INT DEFAULT 0,
AI_HARD_WINS INT DEFAULT 0,
AI_HARD_LOSES INT DEFAULT 0,
AI_HARD_TIES INT DEFAULT 0,
PVP_WINS INT DEFAULT 0,
PVP_LOSES INT DEFAULT 0,
PVP_TIES INT DEFAULT 0
);'''
cursor.execute(query)
cursor.close()
connection.close()
def insert_player_name(p_name):
connection = sqlite3.connect("data.db")
cursor = connection.cursor()
query = f'''INSERT OR IGNORE INTO Score(NAME) VALUES ('{p_name}');'''
cursor.execute(query)
connection.commit()
cursor.close()
connection.close()
def show_data(p_name):
connection = sqlite3.connect("data.db")
cursor = connection.cursor()
query_select = f'''SELECT * FROM Score WHERE NAME = '{p_name}';'''
cursor.execute(query_select)
data = cursor.fetchall()
connection.commit()
print("\n"
f"Statistics - Player: {p_name}\n"
"\n"
"vs AI Easy Mode:\n"
f"Wins {data[0][2]}\n"
f"Loses {data[0][3]}\n"
f"Ties {data[0][4]}\n"
"\n"
"vs AI Medium Mode:\n"
f"Wins {data[0][5]}\n"
f"Loses {data[0][6]}\n"
f"Ties {data[0][7]}\n"
"\n"
"vs AI Hard Mode:\n"
f"Wins {data[0][8]}\n"
f"Loses {data[0][9]}\n"
f"Ties {data[0][10]}\n"
"\n"
"vs Player Mode:\n"
f"Wins {data[0][11]}\n"
f"Loses {data[0][12]}\n"
f"Ties {data[0][13]}\n"
"")
cursor.close()
connection.close()
def update_player_score(p_name, g_mode, result):
connection = sqlite3.connect("data.db")
cursor = connection.cursor()
category = {
"1": ['AI_EASY_WINS', 'AI_EASY_LOSES', 'AI_EASY_TIES'],
"2": ['AI_MEDIUM_WINS', 'AI_MEDIUM_LOSES', 'AI_MEDIUM_TIES'],
"3": ['AI_HARD_WINS', 'AI_HARD_LOSES', 'AI_HARD_TIES'],
"4": ['PVP_WINS', 'PVP_LOSES', 'PVP_TIES']
}
query_update = f'''UPDATE Score SET {category[g_mode][result]} = {category[g_mode][result]} + 1 WHERE NAME = '{p_name}';'''
cursor.execute(query_update)
connection.commit()
cursor.close()
connection.close()