Пример #1
0
    def result_popup(self):
        if is_win(self.grid):
            title = 'Congratulation!!!'
            message = '%s win!!!' % self.cur_player.title
        elif is_full(self.grid):
            title = 'Draw'
            message = 'Draw'

        new_game_btn = Button(text='New game', size_hint_y=None, height=50)
        close_btn = Button(text='Close', size_hint_y=None, height=50)
        content = BoxLayout(orientation='vertical')
        content.add_widget(Label(text=message))
        buttons = BoxLayout(orientation='horizontal')

        buttons.add_widget(new_game_btn)
        buttons.add_widget(close_btn)
        content.add_widget(buttons)
        popup = Popup(
            title=title,
            content=content,
            size_hint=(None, None),
            size=(300, 200)
        )
        close_btn.bind(on_release=popup.dismiss)
        new_game_btn.bind(on_release=self.on_new_game)
        new_game_btn.bind(on_release=popup.dismiss)
        popup.open()
Пример #2
0
    def click(self, cell_num):
        if is_win(self.grid):
            self.result_popup()
            return

        if is_full(self.grid):
            self.result_popup()
            return

        if self.is_correct_cell(cell_num):
            self.set_symbol(cell_num, self.cur_player.symbol)
            cur_move = self.cur_player.move(self.grid)

            if cur_move != None:
                self.set_symbol(cur_move, self.cur_player.symbol)
Пример #3
0
    def set_symbol(self, cell, symbol):
        self.cells[cell].background_normal = 'images/%s.png' % symbol.lower()
        self.grid = move(self.grid, cell, symbol)

        if is_win(self.grid):
            self.result_popup()
            return

        if is_full(self.grid):
            self.result_popup()
            return

        if self.cur_player == self.player_1:
            self.cur_player = self.player_2
        else:
            self.cur_player = self.player_1