diff --git a/data/score.py b/data/score.py new file mode 100644 index 0000000..38281d8 --- /dev/null +++ b/data/score.py @@ -0,0 +1,49 @@ +"""File for Score classes""" + +from typing import Optional + + +class Score: + """Parent class for Scores. Stores common information for a Score.""" + + def __init__(self, user: str, score: Optional[int] = -1) -> None: + self._user: str = user + self._score: int = score + + def get_score(self) -> int: + """Gets score's value""" + return self._score + + def get_score_str(self) -> str: + """Gets score's value as a string.""" + return str(self._score) + + def get_user(self) -> str: + """Gets score's user.""" + return self._user + + def set_score(self, score: int) -> None: + """Sets score's value""" + self._score = score + + +class TimeScore(Score): + """Class for a time based score.""" + + def __init__(self, user: str, score: float) -> None: + super().__init__(user) + self._score: float = score + + def get_score(self) -> float: + """Gets score's value""" + return self._score + + def get_score_str(self) -> str: + """Gets score's value as a string. Returns in time format.""" + minutes: int = self._score / 60 + seconds: float = self._score % 60 + return f"{minutes}:{seconds}" + + def set_score(self, score: float) -> None: + """Sets score's value""" + self._score = score