Exemple #1
0
def main():
    game = TicTacToeGame()
    while not game.is_over():
        try:
            display_board(game.board)
            row = int(input('Enter row: '))
            column = int(input('Enter column: '))
            try:
                game.make_move(row, column)
            except GameError as error:
                print(error)
        except ValueError:
            print('Invalid input.Try again.')
    display_board(game.board)
Exemple #2
0
class TicTacToe(App):
    status_message = StringProperty('shall we play a game?')

    def __init__(self, **kwargs):
        super(TicTacToe, self).__init__(**kwargs)
        self.game = TicTacToeGame()

    def build(self):
        self.title = "Tic Tac Toe! Version 2"
        self.root = Builder.load_file('game_v2.kv')
        return self.root

    def pressed(self, button):
        move = self.game.make_move(button.row, button.column)
        button.text = move
        if self.game.is_over():
            self.status_message = "game over!"
            self.root.ids.game_grid.disabled = True
Exemple #3
0
class TicTacToe(App):
    status_message = StringProperty('shall we play a game?')

    def __init__(self, **kwargs):
        # super().__init__(**kwargs)
        # Python 2 version below:
        super(TicTacToe, self).__init__(**kwargs)
        self.game = TicTacToeGame()

    def build(self):
        self.title = "Tic Tac Toe! Version 2"
        self.root = Builder.load_file('game_v2.kv')
        return self.root

    def pressed(self, button):
        # print(self.game)
        move = self.game.make_move(button.row, button.column)
        button.text = move
        if self.game.is_over():
            self.status_message = "game over!"
            self.root.ids.game_grid.disabled = True
Exemple #4
0
# Using the "model" class Game to play via the console "view"

from board_game import TicTacToeGame, GameError

game = TicTacToeGame()
while not game.is_over():
    try:
        print(game)
        row = int(input('Enter row: '))
        column = int(input('Enter column: '))
        try:
            game.make_move(row, column)
        except GameError as error:
            print(error)
    except ValueError:
        print('invalid input, try again')
print(game)
# Using the "model" class Game to play via the console "view"

from board_game import TicTacToeGame, GameError

game = TicTacToeGame()
while not game.is_over():
    try:
        print(game)
        row = int(input('Enter row: '))
        column = int(input('Enter column: '))
        try:
            game.make_move(row, column)
        except GameError as error:
            print(error)
    except ValueError:
        print('invalid input, try again')
print(game)