-
Notifications
You must be signed in to change notification settings - Fork 0
/
players.py
45 lines (37 loc) · 1.06 KB
/
players.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# vim:ts=4:sw=4:expandtab
class player:
def __init__(self, name):
print "init player with name %s and wiimote " % (name)
self.name = name
self.score = 0
def add_score(self, points):
self.score += points
class players:
players = []
@classmethod
def get_player_by_name(cls, name):
for p in players.players:
if p.name == name:
return p
return None
@classmethod
def dump(cls):
print "-- DUMP --"
for p in players.players:
print "player %s with %d points" % (p.name, p.score)
print "-- END OF DUMP --"
@classmethod
def add_player(cls, name):
p = player(name)
players.players.append(p)
return p
@classmethod
def score(cls, name, points):
p = players.get_player_by_name(name)
p.add_score(points)
players.dump()
@classmethod
def scores(cls):
return map(lambda x: {'name': x.name, 'score': x.score}, players.players)