This commit is contained in:
Auric Vente 2024-07-25 08:02:46 -06:00
parent c5d1832c21
commit db8e716e8c
4 changed files with 17 additions and 12 deletions

View File

@ -91,11 +91,13 @@ class Ant:
class Ants:
ants: ClassVar[list[Ant]] = []
top: ClassVar[Ant | None] = None
@staticmethod
def prepare() -> None:
Ants.get()
Ants.check()
Ants.find_top()
@staticmethod
def check() -> None:
@ -121,8 +123,8 @@ class Ants:
def on_change() -> None:
from .game import Game
Ants.save()
Game.info()
Ants.save()
@staticmethod
def random_ant(ignore: list[Ant] | None = None) -> Ant | None:
@ -172,9 +174,9 @@ class Ants:
ant.method = method
ant.updated = Utils.now()
Ants.find_top()
Game.update(ant)
Game.info()
Ants.save()
Ants.on_change()
@staticmethod
def get() -> None:
@ -202,8 +204,8 @@ class Ants:
return Utils.random_name(names)
@staticmethod
def get_top() -> tuple[Ant, int] | None:
top = None
def find_top() -> None:
top: Ant | None = None
top_score = 0
for ant in Ants.ants:
@ -217,9 +219,9 @@ class Ants:
top = ant
if not top:
return None
return
return top, top_score
Ants.top = top
@staticmethod
def merge(ant_1: Ant | None = None) -> bool:

View File

@ -16,6 +16,7 @@ class Config:
icon_path: Path
status_image_path: Path
hatched_image_path: Path
top_image_path: Path
terminated_image_path: Path
names_json: Path
background_color: str = "rgb(44, 44, 44)"
@ -91,6 +92,7 @@ class Config:
Config.icon_path = Config.here / "img" / "icon_1.jpg"
Config.status_image_path = Config.here / "img" / "icon_2.jpg"
Config.hatched_image_path = Config.here / "img" / "hatched.jpg"
Config.top_image_path = Config.here / "img" / "top.jpg"
Config.terminated_image_path = Config.here / "img" / "terminated.jpg"
Config.font_path = Config.here / "fonts" / "NotoSans-Regular.ttf"
Config.emoji_font_path = Config.here / "fonts" / "NotoEmoji-Regular.ttf"

View File

@ -191,7 +191,9 @@ class Game:
@staticmethod
def get_image(ant: Ant) -> QLabel:
if ant.method == "hatched":
if ant == Ants.top:
path = Config.top_image_path
elif ant.method == "hatched":
path = Config.hatched_image_path
elif ant.method == "terminated":
path = Config.terminated_image_path
@ -378,12 +380,11 @@ class Game:
text.append("Hatch some ants")
else:
text.append(f"Ants:{nb}{len(Ants.ants)}")
top = Ants.get_top()
top = Ants.top
if top:
ant = top[0]
score = top[1]
text.append(f"Top:{nb}{ant.name} ({score})")
score = top.get_score()
text.append(f"Top:{nb}{top.name} ({score})")
Window.info.setText(Config.info_separator.join(text))

View File

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 269 KiB