diff options
author | Viljami Ilola <+@hix.fi> | 2024-03-29 00:30:39 +0200 |
---|---|---|
committer | Viljami Ilola <+@hix.fi> | 2024-03-29 00:30:39 +0200 |
commit | 5c5df6e068b2957987cb51b34d6930769424f8ca (patch) | |
tree | 1f6ce6ff479ee787a3da6f51a9c337bcd24b841a /src/sliceitoff/stats | |
parent | 27c7e16e4bd808ce1176f18b7a78c02ff4fa88ee (diff) |
stats as object
Diffstat (limited to 'src/sliceitoff/stats')
-rw-r--r-- | src/sliceitoff/stats/stats.py | 77 |
1 files changed, 32 insertions, 45 deletions
diff --git a/src/sliceitoff/stats/stats.py b/src/sliceitoff/stats/stats.py index 79da2c9..2d63953 100644 --- a/src/sliceitoff/stats/stats.py +++ b/src/sliceitoff/stats/stats.py @@ -1,53 +1,40 @@ class Stats: - score = 0 - level = 0 - bonus = 0 - lives = 0 - enemies = 0 - percent = 0 - field_count = 0 - bgcolor = (64,0,0,255) - bordercolor = (0,0,0,255) + + def __init__(self): + self.score = 0 + self.level = 1 + self.bonus = 20_000 + self.lives = 3 + self.enemies = 3 + self.percent = 100 + self.field_count = 1 + self.bgcolor = (64,0,0,255) + self.bordercolor = (0,0,0,255) - @staticmethod - def new_game(): - __class__.score = 0 - __class__.level = 1 - __class__.bonus = 20_000 - __class__.lives = 3 - __class__.percent = 100 - __class__.field_count = 1 - __class__.enemies = 3 - - @staticmethod - def level_up(): - __class__.score += __class__.calc_bonus()[0] - __class__.bonus = 20_000 - __class__.percent = 100 - __class__.field_count = 1 - __class__.level += 1 - __class__.enemies = 3 + (__class__.level - 1) * 2 + def level_up(self): + self.score += self.calc_bonus()[0] + self.bonus = 20_000 + self.percent = 100 + self.field_count = 1 + self.level += 1 + self.enemies = 3 + (self.level - 1) * 2 - @staticmethod - def lose_life(): - __class__.lives -= 1 - return not __class__.lives + def lose_life(self): + self.lives -= 1 + return not self.lives - @staticmethod - def add_score(score_to_add): - __class__.score += score_to_add - __class__.score = max(0, __class__.score) + def add_score(self, score_to_add): + self.score += score_to_add + self.score = max(0, self.score) - @staticmethod - def calc_bonus(): - level = __class__.level * 3_000 - life = __class__.lives * 1_000 - time = __class__.level * __class__.bonus - area = __class__.level * int(max(20-__class__.percent,0) * 1_000) - herd = (__class__.enemies - __class__.field_count) * 1_000 + def calc_bonus(self): + level = self.level * 3_000 + life = self.lives * 1_000 + time = self.level * self.bonus + area = self.level * int(max(20-self.percent,0) * 1_000) + herd = (self.enemies - self.field_count) * 1_000 total = level + area + time + life + herd return total, level, life, time, area, herd - @staticmethod - def update_bonus(dt): - __class__.bonus = max(0, __class__.bonus - dt) + def update_bonus(self, dt): + self.bonus = max(0, self.bonus - dt) |