示例#1
0
文件: main.py 项目: mjec/ultimatexo
    def gameboard_onclick(self, e):
        """The callback for clicks on the gameboard.
        Calls Game.play() at the appropriate place, and returns feedback to
        the user."""
        try:
            (row, col) = CanvasHelper.get_square(self.gameboard, e.x, e.y)
            (outer_row, outer_col, inner_row, inner_col) = (row // 3, col // 3,
                                                            row % 3, col % 3)
            self.game.play((outer_row, outer_col), (inner_row, inner_col))
            # self.set_status("Played at ({}, {}), ({}, {})".format(outer_row, outer_col, inner_row, inner_col))

            # That self.game.play(...) has changed self.game.active_player so
            # this is backwards
            if self.game.active_player == game.SquareState.X:
                CanvasHelper.draw_o(self.gameboard, row, col)
            else:
                CanvasHelper.draw_x(self.gameboard, row, col)

            if self.game.child_win is not None:
                self.game_onchildwin(self.game.child_win[0],
                                     self.game.child_win[1])
                self.game.child_win = None

            if self.game.overall_win is not None:
                CanvasHelper.higlight_available_boards(self.gameboard, ())
            else:
                CanvasHelper.higlight_available_boards(
                    self.gameboard, self.game.available_boards())

        except game.InvalidMoveException:
            # self.set_status("({}, {}), ({}, {}) is an invalid move".format(outer_row, outer_col, inner_row, inner_col))
            pass

        except CanvasHelper.OnGridException:
            pass
示例#2
0
文件: main.py 项目: mjec/ultimatexo
    def gameboard_onclick(self, e):
        """The callback for clicks on the gameboard.
        Calls Game.play() at the appropriate place, and returns feedback to
        the user."""
        try:
            (row, col) = CanvasHelper.get_square(self.gameboard, e.x, e.y)
            (outer_row, outer_col, inner_row, inner_col) = (row // 3, col // 3, row % 3, col % 3)
            self.game.play((outer_row, outer_col), (inner_row, inner_col))
            # self.set_status("Played at ({}, {}), ({}, {})".format(outer_row, outer_col, inner_row, inner_col))

            # That self.game.play(...) has changed self.game.active_player so
            # this is backwards
            if self.game.active_player == game.SquareState.X:
                CanvasHelper.draw_o(self.gameboard, row, col)
            else:
                CanvasHelper.draw_x(self.gameboard, row, col)

            if self.game.child_win is not None:
                self.game_onchildwin(self.game.child_win[0], self.game.child_win[1])
                self.game.child_win = None

            if self.game.overall_win is not None:
                CanvasHelper.higlight_available_boards(self.gameboard, ())
            else:
                CanvasHelper.higlight_available_boards(self.gameboard, self.game.available_boards())

        except game.InvalidMoveException:
            # self.set_status("({}, {}), ({}, {}) is an invalid move".format(outer_row, outer_col, inner_row, inner_col))
            pass

        except CanvasHelper.OnGridException:
            pass
示例#3
0
文件: main.py 项目: mjec/ultimatexo
    def __init__(self, parent, game, *args, **kwargs):
        ttk.Frame.__init__(self, parent, padding=20, *args, **kwargs)
        self.parent = parent
        self.game = game

        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=0)

        self.infoframe = info_frame.InfoFrame(
            self, game, start_game=None)  #self.start_game)
        self.infoframe.grid(column=0, row=1, sticky=(N, W, E, S))

        # We set up an auto-resizing, fixed-aspect-ratio frame which will
        # contain our gameboard canvas
        padframe = ttk.Frame(self, padding=0)
        padframe.grid(column=0, row=0, sticky=(N, W, E, S))
        gameframe = ttk.Frame(padframe, padding=0)
        gameframe.grid(column=0, row=0, sticky=(N, S, W, E))
        gameframe.columnconfigure(0, weight=1)
        gameframe.rowconfigure(0, weight=1)
        set_aspect(gameframe, padframe, 1)

        # We set up an auto-resizing canvas for the gameboard
        self.gameboard = ResizingCanvas(gameframe, bg="white")
        self.gameboard.grid(column=0, row=0, sticky=(N, S, E, W))

        # We need to update the root window to make sure we have the right
        # dimensions before we can draw the grids
        self.parent.update()
        CanvasHelper.draw_grid(self.gameboard,
                               colour="#999",
                               thickness=1,
                               rows=9,
                               cols=9,
                               tags=("minor-grid", ))
        CanvasHelper.draw_grid(self.gameboard, tags=("major-grid", ))

        # Create the click binding for the gameboard
        self.gameboard.bind("<Button-1>", self.gameboard_onclick)

        # Highlight all available boards
        CanvasHelper.higlight_available_boards(self.gameboard,
                                               self.game.available_boards())

        # Display status
        def log_func(status):
            self.set_status(status)

        self.game.add_log_function(log_func)

        # Set status
        self.set_status("{} to play".format(self.game.active_player.name))
示例#4
0
文件: main.py 项目: mjec/ultimatexo
    def __init__(self, parent, game, *args, **kwargs):
        ttk.Frame.__init__(self, parent, padding=20, *args, **kwargs)
        self.parent = parent
        self.game = game

        self.columnconfigure(0, weight=1)
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=0)

        self.infoframe = info_frame.InfoFrame(self, game, start_game=None) #self.start_game)
        self.infoframe.grid(column=0, row=1, sticky=(N, W, E, S))

        # We set up an auto-resizing, fixed-aspect-ratio frame which will
        # contain our gameboard canvas
        padframe = ttk.Frame(self, padding=0)
        padframe.grid(column=0, row=0, sticky=(N, W, E, S))
        gameframe = ttk.Frame(padframe, padding=0)
        gameframe.grid(column=0, row=0, sticky=(N, S, W, E))
        gameframe.columnconfigure(0, weight=1)
        gameframe.rowconfigure(0, weight=1)
        set_aspect(gameframe, padframe, 1)

        # We set up an auto-resizing canvas for the gameboard
        self.gameboard = ResizingCanvas(gameframe, bg="white")
        self.gameboard.grid(column=0, row=0, sticky=(N, S, E, W))

        # We need to update the root window to make sure we have the right
        # dimensions before we can draw the grids
        self.parent.update()
        CanvasHelper.draw_grid(self.gameboard, colour="#999", thickness=1, rows=9, cols=9, tags=("minor-grid",))
        CanvasHelper.draw_grid(self.gameboard, tags=("major-grid",))

        # Create the click binding for the gameboard
        self.gameboard.bind("<Button-1>", self.gameboard_onclick)

        # Highlight all available boards
        CanvasHelper.higlight_available_boards(self.gameboard, self.game.available_boards())

        # Display status
        def log_func(status):
            self.set_status(status)
        self.game.add_log_function(log_func)

        # Set status
        self.set_status("{} to play".format(self.game.active_player.name))