Mods
This commit is contained in:
parent
a14e36e932
commit
685f5bc686
|
@ -3,4 +3,4 @@ venv/*
|
|||
*.pyc
|
||||
__pycache__/
|
||||
.mypy_cache/
|
||||
ants.db
|
||||
cromulant.db
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import annotations
|
||||
from typing import ClassVar
|
||||
|
||||
from utils import Utils
|
||||
from database import Database
|
||||
from .utils import Utils
|
||||
from .database import Database
|
||||
|
||||
|
||||
class Ant:
|
|
@ -0,0 +1,17 @@
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
class Config:
|
||||
title = "Cromulant"
|
||||
width = 800
|
||||
height = 600
|
||||
here: str
|
||||
database_path: Path
|
||||
schema_path: Path
|
||||
|
||||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
Config.here = Path(__file__).parent
|
||||
Config.database_path = Config.here / "cromulant.db"
|
||||
Config.schema_path = Config.here / "schema.sql"
|
|
@ -3,6 +3,8 @@ from __future__ import annotations
|
|||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
from .config import Config
|
||||
|
||||
|
||||
class Database:
|
||||
connection: sqlite3.Connection
|
||||
|
@ -10,12 +12,12 @@ class Database:
|
|||
|
||||
@staticmethod
|
||||
def prepare() -> None:
|
||||
Database.connection = sqlite3.connect("ants.db")
|
||||
Database.connection = sqlite3.connect(Config.database_path)
|
||||
Database.cursor = Database.connection.cursor()
|
||||
|
||||
@staticmethod
|
||||
def create() -> None:
|
||||
with Path("schema.sql").open("r") as file:
|
||||
with Config.schema_path.open("r") as file:
|
||||
schema = file.read()
|
||||
|
||||
Database.cursor.executescript(schema)
|
|
@ -0,0 +1,11 @@
|
|||
from .window import Window
|
||||
|
||||
class Game:
|
||||
@staticmethod
|
||||
def update_view() -> None:
|
||||
scene = Window.view.scene()
|
||||
scene.addRect(0, 0, 10, 10)
|
||||
scene.addRect(10, 10, 10, 10)
|
||||
scene.addRect(20, 20, 10, 10)
|
||||
scene.addRect(30, 30, 10, 10)
|
||||
scene.addRect(40, 40, 10, 10)
|
|
@ -1,22 +1,22 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from database import Database
|
||||
from window import Window
|
||||
from ants import Ants
|
||||
from .config import Config
|
||||
from .database import Database
|
||||
from .window import Window
|
||||
from .ants import Ants
|
||||
|
||||
|
||||
def main() -> None:
|
||||
Config.prepare()
|
||||
Database.prepare()
|
||||
Database.create()
|
||||
|
||||
Ants.get_all()
|
||||
|
||||
for ant in Ants.ants:
|
||||
ant.describe()
|
||||
|
||||
Window.make()
|
||||
Window.add_buttons()
|
||||
Window.add_view()
|
||||
Window.add_log()
|
||||
Window.start()
|
||||
|
||||
|
|
@ -8,16 +8,17 @@ from PySide6.QtWidgets import QGraphicsScene
|
|||
from PySide6.QtWidgets import QVBoxLayout
|
||||
from PySide6.QtWidgets import QPushButton
|
||||
from PySide6.QtWidgets import QHBoxLayout
|
||||
from PySide6.QtWidgets import QTextEdit
|
||||
|
||||
from config import Config
|
||||
from ants import Ants
|
||||
from .config import Config
|
||||
|
||||
|
||||
class Window:
|
||||
app: QApplication
|
||||
window: QMainWindow
|
||||
root: QWidget
|
||||
root: QHBoxLayout
|
||||
view: QGraphicsView
|
||||
log: QTextEdit
|
||||
|
||||
@staticmethod
|
||||
def make() -> None:
|
||||
|
@ -25,37 +26,56 @@ class Window:
|
|||
Window.window = QMainWindow()
|
||||
Window.window.setWindowTitle(Config.title)
|
||||
Window.window.resize(Config.width, Config.height)
|
||||
Window.root = QWidget()
|
||||
Window.window.setCentralWidget(Window.root)
|
||||
Window.root = QHBoxLayout()
|
||||
central_widget = QWidget()
|
||||
Window.root = QVBoxLayout()
|
||||
central_widget.setLayout(Window.root)
|
||||
Window.window.setCentralWidget(central_widget)
|
||||
|
||||
@staticmethod
|
||||
def add_buttons() -> None:
|
||||
btn_hatch = QPushButton("Hatch Ant")
|
||||
btn_hatch = QPushButton("Hatch")
|
||||
btn_terminate = QPushButton("Terminate")
|
||||
btn_update = QPushButton("Update")
|
||||
|
||||
btn_hatch.clicked.connect(Window.hatch)
|
||||
btn_terminate.clicked.connect(Window.terminate)
|
||||
btn_update.clicked.connect(Window.update_view)
|
||||
|
||||
layout = QHBoxLayout()
|
||||
layout.addWidget(btn_hatch)
|
||||
layout.addWidget(btn_terminate)
|
||||
layout.addWidget(btn_update)
|
||||
|
||||
Window.root.setLayout(layout)
|
||||
Window.root.addLayout(layout)
|
||||
|
||||
@staticmethod
|
||||
def add_view() -> None:
|
||||
Window.view = QGraphicsView()
|
||||
scene = QGraphicsScene()
|
||||
Window.view.setScene(scene)
|
||||
layout = QVBoxLayout(Window.root)
|
||||
layout.addWidget(Window.view)
|
||||
Window.root.addWidget(Window.view)
|
||||
|
||||
@staticmethod
|
||||
def add_log() -> None:
|
||||
Window.log = QTextEdit()
|
||||
Window.log.setReadOnly(True)
|
||||
Window.log.setFixedHeight(100)
|
||||
Window.root.addWidget(Window.log)
|
||||
|
||||
@staticmethod
|
||||
def update_view() -> None:
|
||||
from .game import Game
|
||||
Game.update_view()
|
||||
|
||||
@staticmethod
|
||||
def hatch() -> None:
|
||||
from .ants import Ants
|
||||
Ants.hatch()
|
||||
|
||||
@staticmethod
|
||||
def terminate() -> None:
|
||||
from .ants import Ants
|
||||
Ants.terminate()
|
||||
|
||||
@staticmethod
|
Loading…
Reference in New Issue