-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRank.py
64 lines (55 loc) · 2.26 KB
/
Rank.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
from PPlay.window import *
from PPlay.gameimage import *
from PPlay.sprite import *
from functools import cmp_to_key
def cmp_score(score1, score2):
if int(score1[1]) >= int(score2[1]):
return -1
else:
return 1
def Formatar(lista):
maior = 0
for j in range(5):
if len(lista[j][0]) > maior:
maior = len(lista[j][0])
for z in range(5):
if len(lista[z][0]) != maior:
lista[z][0] = lista[z][0] + ' '*(maior-len(lista[z][0]))
maior = 0
for j in range(5):
if len(lista[j][1]) > maior:
maior = len(lista[j][1])
for z in range(5):
if len(lista[z][1]) != maior:
lista[z][1] = '0' * (maior - len(lista[z][1])) + lista[z][1]
return lista
def Rank():
janela = Window(800, 600)
janela.set_title("Estelar: Saving the World")
fundo = GameImage("assets/sprites/rankingtela.png")
keyboard = Window.get_keyboard()
arquivo = open("assets/data/ranking.txt", "r")
rank = []
for linha in arquivo:
linha = linha.rstrip('\n')
rank.append(linha.split())
arquivo.close()
rank.sort(key=cmp_to_key(cmp_score))
rank = Formatar(rank)
while True:
fundo.draw()
janela.draw_text('Player:', 220, 200, size=46, color=(255, 255, 0))
janela.draw_text(str(rank[0][0]), 220, 250, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[1][0]), 220, 300, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[2][0]), 220, 350, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[3][0]), 220, 400, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[4][0]), 220, 450, size=46, color=(255, 255, 255))
janela.draw_text('Score:', 470, 200, size=46, color=(255, 255, 0))
janela.draw_text(str(rank[0][1]), 490, 250, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[1][1]), 490, 300, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[2][1]), 490, 350, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[3][1]), 490, 400, size=46, color=(255, 255, 255))
janela.draw_text(str(rank[4][1]), 490, 450, size=46, color=(255, 255, 255))
janela.update()
if keyboard.key_pressed("esc"):
return 0