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

View File

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

View File

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

View File

Before

Width:  |  Height:  |  Size: 269 KiB

After

Width:  |  Height:  |  Size: 269 KiB