from src.Game.game import Game

class UI:
    def __init__(self, game: Game) -> None:
        self.game = game
    
    def start(self) -> None:
        print("\nTo play, enter a column number. To quit, enter 'quit'. To reset the board, enter 'reset'. To reset the game, enter 'reset game'.\n")
        while True:
            print(self.game)
            command = input("Enter a column: ")
            if command == "quit":
                break
            elif command == "reset":
                self.game.reset_board()
            elif command == "reset game":
                self.game.reset_game()
            elif command.isnumeric() and 0 < int(command) and int(command) < 8:
                try:
                    winner = self.game.play(int(command))
                    if winner == "Draw":
                        print(self.game)
                        print("Draw!")
                        input("Press enter to continue")
                        self.game.reset_board()
                        continue
                    if winner is not None:
                        print(self.game)
                        print(f"{winner} won!")
                        input("Press enter to continue")
                        self.game.reset_board()
                except Exception as e:
                    print(e)
            else:
                print("Invalid command")



