game(feat): add game mode

This commit is contained in:
Kristofers Solo 2024-01-06 03:09:10 +02:00
parent 6b3f0ea619
commit bb80400ad7
4 changed files with 16 additions and 7 deletions

View File

@ -2,7 +2,7 @@
import argparse import argparse
from loguru import logger from loguru import logger
from utils import BASE_PATH, CONFIG from utils import BASE_PATH, CONFIG, GameMode
def pos_int(string: str) -> int: def pos_int(string: str) -> int:
@ -66,10 +66,11 @@ def main(args: argparse.ArgumentParser) -> None:
if args.train is not None: if args.train is not None:
ai.log.debug("Training the AI") ai.log.debug("Training the AI")
ai.train(*args.train) # ai.train(*args.train)
game.Main(GameMode.AI_TRAINING).run()
else: else:
game.log.debug("Running the game") game.log.debug("Running the game")
game.Main().run() game.Main(GameMode.PLAYER).run()
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,7 +1,7 @@
import sys import sys
import pygame import pygame
from utils import CONFIG, Figure from utils import CONFIG, Figure, GameMode
from .game import Game from .game import Game
from .log import log from .log import log
@ -25,8 +25,9 @@ class Main:
music: Pygame music that plays in the background. music: Pygame music that plays in the background.
""" """
def __init__(self) -> None: def __init__(self, mode: GameMode) -> None:
log.info("Initializing the game") log.info("Initializing the game")
self.game_mode = mode
self._initialize_pygeme() self._initialize_pygeme()
self._initialize_game_components() self._initialize_game_components()
self._start_background_music() self._start_background_music()

View File

@ -1,5 +1,5 @@
from .config import CONFIG from .config import CONFIG
from .enum import Direction, Field, Rotation from .enum import Direction, Field, GameMode, Rotation
from .figure import Figure, FigureConfig from .figure import Figure, FigureConfig
from .log import log from .log import log
from .path import BASE_PATH from .path import BASE_PATH
@ -15,4 +15,5 @@ __all__ = [
"Direction", "Direction",
"Field", "Field",
"Rotation", "Rotation",
"GameMode",
] ]

View File

@ -1,4 +1,4 @@
from enum import Enum from enum import Enum, auto
class Direction(Enum): class Direction(Enum):
@ -16,3 +16,9 @@ class Rotation(Enum):
class Field(Enum): class Field(Enum):
EMPTY = None EMPTY = None
FILLED = "Block" FILLED = "Block"
class GameMode(Enum):
PLAYER = auto()
AI_PLAYING = auto()
AI_TRAINING = auto()