-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.py
77 lines (62 loc) · 2.23 KB
/
leaderboard.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
import mysql.connector
from mysql.connector import errorcode
config = {
'user': 'n089p351',
'password': 'npelletier',
'host': '127.0.0.1',
'database': 'eecs_projects',
'raise_on_warnings': True
}
def leaderboard_control(song_name, difficulty, score):
if check_score(score):
print('Congratulations! You got a High Score!\n')
player_name = input('Enter Name:')
add_score(song_name, difficulty, player_name, score)
print('Highscores for', song_name, 'on ', difficulty, ':\nRank\tPlayer\tScore')
print_scores(song_name, difficulty)
else:
print('Highscores for', song_name, 'on ', difficulty, ':\nRank\tPlayer\tScore')
print_scores(song_name, difficulty)
def check_score(player_score):
count = 9
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
search_details(song_name, difficulty)
search_scores("SELECT player_name, score FROM leaderboard WHERE song_name = %s AND difficulty = %s ORDER BY score")
cursor.execute(search_people, people_data)
results = cursor.fetchall()
cursor.close()
cnx.close()
for (player_name, score) in results:
if(score<=player_score):
return True
count--
if count == 0:
break
return False
def add_score(song_name, difficulty, player_name, score):
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
add_new_score = ("INSERT INTO leaderboard "
"(song_name, difficulty, player_name, score) "
"VALUES (%s, %s, %s, %s)")
score_data = (song_name, difficulty, player_name, score)
cursor.execute(add_new_score, score_data)
cnx.commit()
cursor.close()
cnx.close()
def print_scores(song_name, difficulty):
count = 1
cnx = mysql.connector.connect(**config)
cursor = cnx.cursor()
search_details(song_name, difficulty)
search_scores("SELECT player_name, score FROM leaderboard WHERE song_name = %s AND difficulty = %s ORDER BY score")
cursor.execute(search_people, people_data)
results = cursor.fetchall()
cursor.close()
cnx.close()
for (player_name, score) in results:
print(count, "\t{}\t {}".format(player_name, score))
count++
if count == 10:
break