This commit is contained in:
Auric Vente 2024-07-21 00:49:32 -06:00
parent a44461a93b
commit 814465c2a0
1 changed files with 22 additions and 7 deletions

View File

@ -80,8 +80,7 @@ class Ants:
ant.name = Ants.random_name() ant.name = Ants.random_name()
Ants.ants.append(ant) Ants.ants.append(ant)
image_path = Config.hatched_image_path Ants.announce_hatch(ant)
Game.add_message("Hatched", f"{ant.name} is born", image_path)
if len(Ants.ants) >= Config.max_ants: if len(Ants.ants) >= Config.max_ants:
break break
@ -108,8 +107,7 @@ class Ants:
Ants.ants.remove(ant) Ants.ants.remove(ant)
Ants.save() Ants.save()
image_path = Config.terminated_image_path Ants.announce_terminate(ant)
Game.add_message("Terminated", f"{ant.name} is gone", image_path)
Game.update_info() Game.update_info()
@staticmethod @staticmethod
@ -270,6 +268,7 @@ class Ants:
words_2 = fill(words_2) words_2 = fill(words_2)
name = "" name = ""
names = Ants.get_names()
for _ in range(12): for _ in range(12):
name = f"{random.choice(words_1)} {random.choice(words_2)}" name = f"{random.choice(words_1)} {random.choice(words_2)}"
@ -277,14 +276,18 @@ class Ants:
if (name == ant_1.name) or (name == ant_2.name): if (name == ant_1.name) or (name == ant_2.name):
continue continue
if name in Utils.names: if (name in names) or (name in Utils.names):
continue continue
if not name: if not name:
return return
Ants.announce_terminate(ant_1)
Ants.announce_terminate(ant_2)
Ants.ants.remove(ant_1) Ants.ants.remove(ant_1)
Ants.ants.remove(ant_2) Ants.ants.remove(ant_2)
now = Utils.now() now = Utils.now()
ant = Ant() ant = Ant()
@ -295,8 +298,20 @@ class Ants:
ant.hits = ant_1.hits + ant_2.hits ant.hits = ant_1.hits + ant_2.hits
Ants.ants.append(ant) Ants.ants.append(ant)
Ants.announce_hatch(ant)
Game.update_info()
Ants.save() Ants.save()
@staticmethod
def announce_hatch(ant: Ant) -> None:
from .game import Game
image_path = Config.hatched_image_path image_path = Config.hatched_image_path
Game.add_message("Merged", f"{ant.name} is born", image_path) Game.add_message("Hatched", f"{ant.name} is born", image_path)
Game.update_info()
@staticmethod
def announce_terminate(ant: Ant) -> None:
from .game import Game
image_path = Config.terminated_image_path
Game.add_message("Terminated", f"{ant.name} is gone", image_path)