-
Notifications
You must be signed in to change notification settings - Fork 22
/
Scores.py
executable file
·91 lines (72 loc) · 2.5 KB
/
Scores.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
#!/usr/bin/env python
'''
Created on Dec 18, 2011
@author: [email protected]
Scores.py is a module in the scorebot program. It's purpose is to track scores for a given team or Redcell player
Copyright (C) 2011 Dichotomy
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
'''
class Scores(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.latest_round = 1
self.rounds = {}
self.itteration = 1
def new_score(self, value):
self.latest_round += 1
self.rounds[self.latest_round] = int(value)
def total(self):
total = 0
for this_round in self.rounds:
total += self.rounds[this_round]
return total
def get_score(self, this_round=None):
which_round = self.latest_round
score = 0
if this_round:
which_round = int(this_round)
if which_round in self.rounds:
score = self.rounds[which_round]
return score
def set_score(self, this_round, value):
self.rounds[int(this_round)] = int(value)
self.latest_round += 1
def dump(self):
print self.rounds
def __iter__(self):
return self
def next(self):
if self.itteration < self.latest_round:
score = self.rounds[self.itteration]
self.itteration += 1
return self.itteration-1, score
else:
self.itteration = 1
raise StopIteration
if __name__ == "__main__":
import random
score_obj = Scores()
for n in range(1,10):
score = int(random.random()*100)
score_obj.set_score(n, score)
print "Round %s; Score %s" % (n, score)
round = 0
for round, score in score_obj:
print "Round %s; Score %s" % (round, score)
for round, score in score_obj:
print "Round %s; Score %s" % (round, score)