This commit is contained in:
Auric Vente
2024-07-18 21:08:11 -06:00
parent fa1f5301ae
commit c95dab8e57
9 changed files with 120 additions and 48 deletions

View File

@@ -1,21 +1,30 @@
from PySide6.QtWidgets import QWidget
from PySide6.QtGui import QColor
from __future__ import annotations
import random
from PySide6.QtWidgets import QWidget # type: ignore
from PySide6.QtGui import QColor # type: ignore
from PySide6.QtGui import QPainter
from PySide6.QtCore import Qt
from PySide6.QtCore import Qt # type: ignore
from PySide6.QtWidgets import QHBoxLayout
from PySide6.QtWidgets import QLabel
from PySide6.QtGui import QPaintEvent
from wonderwords import RandomSentence # type: ignore
from .ants import Ant
from .ants import Ants
from .window import Window
class CircleWidget(QWidget):
def __init__(self, color, parent=None):
super().__init__(parent)
class CircleWidget(QWidget): # type: ignore
def __init__(self, color: tuple[int, int, int]) -> None:
super().__init__(None)
self.color = QColor(*color)
self.setFixedSize(20, 20)
def paintEvent(self, event):
def paintEvent(self, event: QPaintEvent) -> None:
print(type(event))
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
painter.setBrush(self.color)
@@ -25,16 +34,38 @@ class CircleWidget(QWidget):
class Game:
@staticmethod
def update_view() -> None:
for ant in Ants.ants:
container = QHBoxLayout()
circle = CircleWidget(ant.color)
text = QLabel(ant.status)
container.addWidget(circle)
container.addWidget(text)
Window.view.addLayout(container)
def add_status(ant: Ant) -> None:
container = QHBoxLayout()
circle = CircleWidget(ant.color)
text = QLabel(ant.status)
container.addWidget(circle)
container.addWidget(text)
Window.view.addLayout(container)
@staticmethod
def log(message: str) -> None:
Window.log.append(message)
Window.log.append(message)
@staticmethod
def get_status() -> None:
ant = Ants.get_lazy()
num = random.randint(1, 10)
if num == 1:
ant.hits += 1
ant.status = f"Took a hit ({ant.hits} total)"
elif num == 2:
ant.triumph += 1
ant.status = f"Scored a triumph ({ant.triumph} total)"
elif num == 3:
s = RandomSentence()
ant.status = s.simple_sentence()
elif (num == 4) and (len(Ants.ants) > 1):
other = Ants.get_other(ant)
ant.status = f"Is thinking about {other.name}"
else:
s = RandomSentence()
ant.status = s.bare_bone_with_adjective()
Game.add_status(ant)
Ants.save()