-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaps.py
More file actions
54 lines (34 loc) · 1.43 KB
/
Copy pathaps.py
File metadata and controls
54 lines (34 loc) · 1.43 KB
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
#!/usr/bin/env python3
class PlayerError(BaseException): pass
class Player(object):
openSlots = [True,] * 32
teamBySlots = [4] * 32
teamNames = ("Red", "Blue", "Green", "Gold", "None")
teamCount = len(teamNames)
def __init__(self, name, *, team=4, startHealth=100):
try:
self.pln = Player.openSlots.index(True)
except ValueError:
raise PlayerError("no open player slots, aborting")
self.pln = -1
del self # no point in existing
else:
Player.openSlots[self.pln] = False
if team < 0 or team >= Player.teamCount:
raise PlayerError("team {} out of range [0, {}], aborting".format(
team, Player.teamCount - 1))
del self
self.team = team
Player.teamBySlots[self.pln] = team
self.name = name
def __del__(self):
if self.pln <= 0:
Player.openSlots[self.pln] = True
Player.teamBySlots[self.pln] = 4
def __repr__(self):
return "{}(pln={}, name={}, team={})".format(self.__class__.__name__,
self.pln, repr(self.name),
self.team)
def __str__(self):
return "{} (pln: {}, team: {})".format(self.name, self.pln,
Player.teamNames[self.team])