added some bones to players and teams
This commit is contained in:
parent
a317e079d6
commit
1ced6985fa
16
player.py
16
player.py
|
@ -7,14 +7,17 @@ class CreationError(Exception):
|
||||||
class Player(object):
|
class Player(object):
|
||||||
"""A hockey player with attributes and various functions."""
|
"""A hockey player with attributes and various functions."""
|
||||||
|
|
||||||
def __init__(self, name:str):
|
def __init__(self, name:str, number:int=0):
|
||||||
if name is None:
|
if name is None:
|
||||||
self.attributes = []
|
self.attributes = []
|
||||||
elif len(name) > 30:
|
elif len(name) > 30:
|
||||||
raise CreationError("Player name too long.")
|
raise CreationError("Player name too long.")
|
||||||
|
elif number < 0 or number > 99:
|
||||||
|
raise CreationError("Player number not valid.")
|
||||||
else:
|
else:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.attributes = self.loadAttributes()
|
self.attributes = self.loadAttributes()
|
||||||
|
self.number = number
|
||||||
|
|
||||||
def loadAttributes(self):
|
def loadAttributes(self):
|
||||||
"""Generates attributes based on name, or loads from database if present."""
|
"""Generates attributes based on name, or loads from database if present."""
|
||||||
|
@ -53,13 +56,24 @@ class Player(object):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"#{str(self.number)} {self.initials()}"
|
||||||
|
|
||||||
|
def initials(self):
|
||||||
|
names = self.name.split()
|
||||||
|
outString = ""
|
||||||
|
for name in names:
|
||||||
|
outString += f"{name[0]}."
|
||||||
|
return outString
|
||||||
|
|
||||||
class Skater(Player):
|
class Skater(Player):
|
||||||
"""A hockey player that is not a goalie."""
|
"""A hockey player that is not a goalie."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Goalie(Player):
|
class Goalie(Player):
|
||||||
"""A hockey player that *is* a goalie."""
|
"""A hockey player that *is* a goalie."""
|
||||||
|
pass
|
||||||
|
|
||||||
class AtkAction(Enum):
|
class AtkAction(Enum):
|
||||||
SkateB = 0
|
SkateB = 0
|
||||||
|
|
10
team.py
10
team.py
|
@ -5,6 +5,14 @@ class Team(object):
|
||||||
"""A team of either 6 or 10 skaters and 1-3 goalies."""
|
"""A team of either 6 or 10 skaters and 1-3 goalies."""
|
||||||
roster = [] #ordered, first line then second line; (#, name)
|
roster = [] #ordered, first line then second line; (#, name)
|
||||||
goalies = [] # (#, name)
|
goalies = [] # (#, name)
|
||||||
|
name = None
|
||||||
|
shortname = None
|
||||||
|
|
||||||
|
def __init__(self, skaters, goalies, name:str, shortname:str):
|
||||||
|
self.roster = skaters
|
||||||
|
self.goalies = goalies
|
||||||
|
self.name = name
|
||||||
|
self.shortname = shortname
|
||||||
|
|
||||||
def chooseGoalie(self):
|
def chooseGoalie(self):
|
||||||
return sample(goalies,1)
|
return sample(self.goalies,1)
|
Loading…
Reference in a new issue