This commit is contained in:
Auric Vente
2024-07-21 05:50:25 -06:00
parent 34896e24e2
commit 3d8ff1f167
4 changed files with 67 additions and 34 deletions

View File

@@ -70,16 +70,11 @@ class Ants:
@staticmethod
def prepare() -> None:
Ants.get()
Ants.fill()
@staticmethod
def hatch(num: int = 1) -> None:
from .game import Game
if len(Ants.ants) >= Config.max_ants:
Window.alert("Max ants reached\nTerminate some to hatch new ones")
return
now = Utils.now()
for _ in range(num):
@@ -91,9 +86,6 @@ class Ants:
Ants.ants.append(ant)
Ants.announce_hatch(ant)
if len(Ants.ants) >= Config.max_ants:
break
Ants.save()
Game.update_info()
@@ -179,28 +171,16 @@ class Ants:
@staticmethod
def get() -> None:
objs = Storage.get_ants()
changed = False
if len(objs) > Config.max_ants:
objs = objs[: Config.max_ants]
changed = True
for obj in objs:
ant = Ant()
ant.from_dict(obj)
Ants.ants.append(ant)
if changed:
Ants.save()
@staticmethod
def fill() -> None:
diff = Config.max_ants - len(Ants.ants)
if diff <= 0:
return
Ants.hatch(diff)
def populate(num: int) -> None:
Ants.clear()
Ants.hatch(num)
@staticmethod
def random_name() -> str: