Using property decorators.
This commit is contained in:
+24
-17
@@ -6,44 +6,51 @@ from typing import Optional
|
||||
class Score:
|
||||
"""Parent class for Scores. Stores common information for a Score."""
|
||||
|
||||
# no user setter, it should never change.
|
||||
|
||||
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:
|
||||
@property
|
||||
def user(self) -> str:
|
||||
"""Gets score's user."""
|
||||
return self._user
|
||||
|
||||
def set_score(self, score: int) -> None:
|
||||
@property
|
||||
def score(self) -> int:
|
||||
"""Gets score's value"""
|
||||
return self._score
|
||||
|
||||
@score.setter
|
||||
def score(self, score: int) -> None:
|
||||
"""Sets score's value"""
|
||||
self._score = score
|
||||
|
||||
def get_str(self) -> str:
|
||||
"""Gets score's value as a string."""
|
||||
return str(self._score)
|
||||
|
||||
class TimeScore(Score):
|
||||
|
||||
class ScoreTime(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:
|
||||
@property
|
||||
def score(self) -> float:
|
||||
"""Gets score's value"""
|
||||
return self._score
|
||||
|
||||
def get_score_str(self) -> str:
|
||||
@score.setter
|
||||
def score(self, score: float) -> None:
|
||||
"""Sets score's value"""
|
||||
self._score = score
|
||||
|
||||
def get_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
|
||||
|
||||
Reference in New Issue
Block a user