SimHoc/player.py

72 lines
1.7 KiB
Python

import attributes
from enum import Enum
class CreationError(Exception):
pass
class Player(object):
"""A hockey player with attributes and various functions."""
def __init__(self, name:str):
if len(name) > 30:
raise CreationError("Player name too long.")
self.name = name
self.attributes = self.loadAttributes()
def loadAttributes(self):
"""Generates attributes based on name, or loads from database if present."""
rawAtrs = attributes.attributesFromName(self.name)
self.attributesVersion = rawAtrs[0]
return rawAtrs[1:]
def twitterString(self):
"""Generates a twitter-formatted string representing the player."""
send = f"{self.name}:\n"
for attr in self.attributes:
if attr.name not in attributes.noPrint:
send += attr.twitterFormat()
send += "\n"
return send
def getAttribute(self, shortname:str):
for attr in self.attributes:
if attr.name.lower().startswith(shortname.lower()):
return attr.value
return None
def __eq__(self, value):
if isinstance(value, Player):
return self.name == value.name
elif isinstance(value, str):
return self.name == value
else:
return False
class Skater(Player):
"""A hockey player that is not a goalie."""
class Goalie(Player):
"""A hockey player that *is* a goalie."""
class AtkAction(Enum):
SkateB = 0
SkateF = 1
SkateT = 2
SkateA = 3
PassS = 4
PassF = 5
PassB = 6
Dump = 7
ShotS = 8
ShotW = 9
class DefAction(Enum):
Steal = 0
Poke = 1
BlockLn = 2
Body = 3
Force = 4
Pin = 5
BlockSlot = 6