-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.py
45 lines (35 loc) · 1.35 KB
/
game.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
from player import Player
from string import Template
class Game:
def __init__(self):
self.players = dict()
def addResult(self, player, points):
self.players[player] = points
def getMatchScores(self):
scores = ""
i = 1
for player, points in sorted(self.players.items(), key=lambda value: value[1], reverse=True):
scores += "{}: {} - {}\n".format(i, player, points)
i += 1
return scores
def getMatchScoresFormatted(self):
t = Template('{"title": "${name}", "fields": [{"title": "Position","value": "${position}","short": true},{"title": "Score", "value": "${score}", "short": true}]')
scores = '['
i = 1
length = len(self.players.items())
for player, points in sorted(self.players.items(), key=lambda value: value[1], reverse=True):
scores += t.substitute(name = player, position = i, score = points)
scores += '}'
if i != length:
scores += ','
i += 1
scores += ']'
return scores
def getResults(self):
players = []
for player, points in self.players.items():
players.append(Player(player, 1000, 0, points, 0))
return players
def __str__(self):
for k, v in self.players.items():
print(k + " " + str(v))