Mods
This commit is contained in:
parent
95bc45af8b
commit
2b965b3435
|
@ -86,6 +86,7 @@ class Ants:
|
|||
break
|
||||
|
||||
Ants.save()
|
||||
Game.update_info()
|
||||
|
||||
@staticmethod
|
||||
def hatch_burst() -> None:
|
||||
|
@ -104,13 +105,17 @@ class Ants:
|
|||
|
||||
image_path = Config.terminated_image_path
|
||||
Game.add_message("Terminated", f"{ant.name} is gone", image_path)
|
||||
Game.update_info()
|
||||
|
||||
@staticmethod
|
||||
def terminate_all() -> None:
|
||||
from .game import Game
|
||||
|
||||
def action() -> None:
|
||||
Ants.ants = []
|
||||
Ants.save()
|
||||
Window.clear_view()
|
||||
Game.update_info()
|
||||
|
||||
Window.confirm("Terminate all ants?", action)
|
||||
|
||||
|
@ -157,3 +162,17 @@ class Ants:
|
|||
ant = Ant()
|
||||
ant.from_dict(obj)
|
||||
Ants.ants.append(ant)
|
||||
|
||||
@staticmethod
|
||||
def most_hits() -> Ant | None:
|
||||
if not len(Ants.ants):
|
||||
return None
|
||||
|
||||
return max(Ants.ants, key=lambda a: a.hits)
|
||||
|
||||
@staticmethod
|
||||
def most_triumph() -> Ant | None:
|
||||
if not len(Ants.ants):
|
||||
return None
|
||||
|
||||
return max(Ants.ants, key=lambda a: a.triumph)
|
||||
|
|
|
@ -20,7 +20,7 @@ class Config:
|
|||
background_color: str = "#2c2c2c"
|
||||
text_color: str = "#ffffff"
|
||||
image_size: int = 80
|
||||
space_1: int = 25
|
||||
space_1: int = 20
|
||||
max_messages: int = 120
|
||||
loop_delay_fast: int = 3_000
|
||||
loop_delay_normal: int = 20_000
|
||||
|
|
|
@ -26,6 +26,7 @@ class Game:
|
|||
@staticmethod
|
||||
def prepare() -> None:
|
||||
Game.initial_fill()
|
||||
Game.update_info()
|
||||
|
||||
@staticmethod
|
||||
def add_status(ant: Ant) -> None:
|
||||
|
@ -145,6 +146,7 @@ class Game:
|
|||
ants = sorted(Ants.ants, key=lambda ant: ant.updated)
|
||||
|
||||
for ant in ants:
|
||||
if ant.status:
|
||||
Game.add_status(ant)
|
||||
|
||||
@staticmethod
|
||||
|
@ -166,3 +168,28 @@ class Game:
|
|||
def update_speed() -> None:
|
||||
Game.timer.stop()
|
||||
Game.start_loop()
|
||||
|
||||
@staticmethod
|
||||
def update_info() -> None:
|
||||
text = []
|
||||
|
||||
# Non-breaking space
|
||||
nb = "\u00a0"
|
||||
|
||||
if not len(Ants.ants):
|
||||
text.append("Hatch some ants")
|
||||
else:
|
||||
text.append(f"Ants:{nb}{len(Ants.ants)}")
|
||||
|
||||
hits = Ants.most_hits()
|
||||
|
||||
if hits:
|
||||
text.append(f"Most{nb}Hits:{nb}{hits.name}")
|
||||
|
||||
triumph = Ants.most_triumph()
|
||||
|
||||
if triumph:
|
||||
text.append(f"Most{nb}Triumph:{nb}{triumph.name}")
|
||||
|
||||
Window.info.setText(" | ".join(text))
|
||||
Window.info.adjustSize()
|
||||
|
|
|
@ -15,6 +15,7 @@ from PySide6.QtWidgets import QComboBox
|
|||
from PySide6.QtWidgets import QLayout
|
||||
from PySide6.QtWidgets import QSizePolicy
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
from PySide6.QtWidgets import QLabel
|
||||
from PySide6.QtGui import QMouseEvent # type: ignore
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtCore import Qt # type: ignore
|
||||
|
@ -40,12 +41,15 @@ class Window:
|
|||
view: QVBoxLayout
|
||||
view_scene: QGraphicsScene
|
||||
speed: QComboBox
|
||||
scroll_area: QScrollArea
|
||||
info: QLabel
|
||||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
Window.make()
|
||||
Window.add_buttons()
|
||||
Window.add_view()
|
||||
Window.add_footer()
|
||||
|
||||
@staticmethod
|
||||
def make() -> None:
|
||||
|
@ -83,21 +87,21 @@ class Window:
|
|||
Window.speed.setCurrentIndex(1)
|
||||
Window.speed.currentIndexChanged.connect(Game.update_speed)
|
||||
|
||||
btn_close = QPushButton("Close")
|
||||
btn_close.clicked.connect(Window.close)
|
||||
btn_top = QPushButton("Top")
|
||||
btn_top.clicked.connect(Window.to_top)
|
||||
|
||||
layout = QHBoxLayout()
|
||||
layout.addWidget(btn_hatch)
|
||||
layout.addWidget(btn_terminate)
|
||||
layout.addWidget(Window.speed)
|
||||
layout.addWidget(btn_close)
|
||||
layout.addWidget(btn_top)
|
||||
|
||||
Window.root.addLayout(layout)
|
||||
|
||||
@staticmethod
|
||||
def add_view() -> None:
|
||||
scroll_area = QScrollArea()
|
||||
scroll_area.setWidgetResizable(True)
|
||||
Window.scroll_area = QScrollArea()
|
||||
Window.scroll_area.setWidgetResizable(True)
|
||||
|
||||
container = QWidget()
|
||||
parent = QVBoxLayout(container)
|
||||
|
@ -105,8 +109,8 @@ class Window:
|
|||
parent.addLayout(Window.view)
|
||||
|
||||
Window.view.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||
scroll_area.setWidget(container)
|
||||
Window.root.addWidget(scroll_area)
|
||||
Window.scroll_area.setWidget(container)
|
||||
Window.root.addWidget(Window.scroll_area)
|
||||
|
||||
@staticmethod
|
||||
def start() -> None:
|
||||
|
@ -155,3 +159,16 @@ class Window:
|
|||
item.widget().deleteLater()
|
||||
elif item.layout():
|
||||
Window.delete_layout(item.layout())
|
||||
|
||||
@staticmethod
|
||||
def to_top() -> None:
|
||||
Window.scroll_area.verticalScrollBar().setValue(0)
|
||||
|
||||
@staticmethod
|
||||
def add_footer() -> None:
|
||||
layout = QHBoxLayout()
|
||||
Window.info = QLabel("---")
|
||||
Window.info.setWordWrap(True)
|
||||
Window.expand(Window.info)
|
||||
layout.addWidget(Window.info)
|
||||
Window.root.addLayout(layout)
|
||||
|
|
Loading…
Reference in New Issue