Change constructor of score. Create new function to add score value from a string.
This commit is contained in:
+25
-4
@@ -8,7 +8,7 @@ class Score:
|
||||
|
||||
# no user setter, it should never change.
|
||||
|
||||
def __init__(self, user: str, value: int) -> None:
|
||||
def __init__(self, user: str) -> None:
|
||||
"""
|
||||
Default constructor for Score class.
|
||||
|
||||
@@ -17,7 +17,7 @@ class Score:
|
||||
value (int): Score's value
|
||||
"""
|
||||
self._user: str = user
|
||||
self._value: int = value
|
||||
self._value: int = -1
|
||||
|
||||
def __str__(self) -> str:
|
||||
"""
|
||||
@@ -67,6 +67,15 @@ class Score:
|
||||
"""
|
||||
return str(self._value)
|
||||
|
||||
def set_value_str(self, value: str) -> None:
|
||||
"""
|
||||
Setter for score value from string.
|
||||
|
||||
Args:
|
||||
value (str): int as a string
|
||||
"""
|
||||
self._value = int(value)
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Score object as a string.
|
||||
@@ -80,7 +89,7 @@ class Score:
|
||||
class ScoreTime(Score):
|
||||
"""Class for a time based score. Inherits from Score."""
|
||||
|
||||
def __init__(self, user: str, score: float) -> None: # pylint: disable=super-init-not-called
|
||||
def __init__(self, user: str) -> None: # pylint: disable=super-init-not-called
|
||||
"""
|
||||
Default constructor for ScoreTime class.
|
||||
|
||||
@@ -90,7 +99,7 @@ class ScoreTime(Score):
|
||||
"""
|
||||
# store time score as seconds.
|
||||
self._user: str = user
|
||||
self._score: float = score
|
||||
self._score: float = -1.0
|
||||
|
||||
@property
|
||||
def value(self) -> float:
|
||||
@@ -121,3 +130,15 @@ class ScoreTime(Score):
|
||||
"""
|
||||
milliseconds = round((self.value - int(self.value)) * 10)
|
||||
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(self.value))
|
||||
|
||||
def set_value_str(self, value: str) -> None:
|
||||
"""
|
||||
Setter for score value from a string.
|
||||
|
||||
Args:
|
||||
value (str): string representation of time
|
||||
"""
|
||||
if value.find(":"):
|
||||
self._score = int(value.split(":")[0]) * 60 + float(value.split(":")[1])
|
||||
else:
|
||||
self._score = float(value)
|
||||
|
||||
Reference in New Issue
Block a user