mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 07:39:25 +08:00
33 lines
738 B
Python
33 lines
738 B
Python
class CounterReachMaxCountException(Exception):
|
|
...
|
|
|
|
|
|
class MaxCounter:
|
|
def __init__(self, max_count):
|
|
self.max_count = max_count
|
|
self.current_count = 0
|
|
|
|
def count_once(self, throw=True) -> bool:
|
|
self.current_count += 1
|
|
if self.current_count >= self.max_count:
|
|
if throw:
|
|
raise CounterReachMaxCountException()
|
|
else:
|
|
return False
|
|
return True
|
|
|
|
def reset(self):
|
|
self.current_count = 0
|
|
|
|
|
|
class Counter:
|
|
def __init__(self, start=0):
|
|
self.current_count = start
|
|
|
|
def count_once(self, throw=True) -> bool:
|
|
self.current_count += 1
|
|
return True
|
|
|
|
def reset(self):
|
|
self.current_count = 0
|