diff --git a/main.py b/main.py index c7346b6..b2bc7a7 100755 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import argparse -from game import Game2048 +from game import play # from ai import train from loguru import logger @@ -85,10 +85,10 @@ def main(args: argparse.ArgumentParser) -> None: logger.debug("Train") elif args.noui: logger.debug("Run game in CLI") + play() else: logger.debug("Run app") - game = Game2048() - game.display() + # play() if __name__ == "__main__": diff --git a/src/game/__init__.py b/src/game/__init__.py index fea3aa8..45e6df8 100644 --- a/src/game/__init__.py +++ b/src/game/__init__.py @@ -1,3 +1,3 @@ -from .game import Game2048 +from .game import Game2048, play -__all__ = ["Game2048"] +__all__ = ["Game2048", "play"] diff --git a/src/game/game.py b/src/game/game.py index 86c16af..e35bee8 100644 --- a/src/game/game.py +++ b/src/game/game.py @@ -5,6 +5,30 @@ from loguru import logger from utils import Config, Direction +def play() -> None: + game = Game2048() + + while True: + game.display() + move = input("Enter direction: ") + moves = { + "w": Direction.UP, + "a": Direction.LEFT, + "s": Direction.DOWN, + "d": Direction.RIGHT, + } + + if move == "q": + break + + direction = moves.get(move, None) + + if direction: + game.move(direction) + + game.display() + + class Game2048: def __init__(self, size: int = 4): self.size = size