diff --git a/cromulant/ants.py b/cromulant/ants.py index 2e71dfe..e95a110 100644 --- a/cromulant/ants.py +++ b/cromulant/ants.py @@ -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: diff --git a/cromulant/config.py b/cromulant/config.py index 31cb64c..bd1b7dc 100644 --- a/cromulant/config.py +++ b/cromulant/config.py @@ -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" diff --git a/cromulant/game.py b/cromulant/game.py index 9972a11..530f9f4 100644 --- a/cromulant/game.py +++ b/cromulant/game.py @@ -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)) diff --git a/cromulant/img/evolved.jpg b/cromulant/img/top.jpg similarity index 100% rename from cromulant/img/evolved.jpg rename to cromulant/img/top.jpg