Example #1
0
    def _game_over(self, event: tkinter.Event) -> None:
        gamestate = joshuaconsole1.Gamestate(self._turn, self._dimensions,
                                             self._winner, self.board)

        self._title.destroy()
        end_title = tkinter.StringVar()
        end_title.set("GAME OVER")
        self._end_title = tkinter.Label(master=self._root_window,
                                        textvariable=end_title,
                                        font=DEFAULT_FONT)
        self._end_title.grid(row=5,
                             column=0,
                             padx=10,
                             pady=10,
                             sticky=tkinter.S)
        self._canvas.bind('<Button-1>', self.leave_game)

        self._winner_label = tkinter.Label(master=self._root_window,
                                           text='',
                                           font=('Helvetica', 20))
        self._winner_label.grid(row=4, column=0, padx=0, pady=10)

        scores = gamestate.count_pieces()
        win_num = gamestate.check_for_winner()
        if win_num == 1:
            winner = 'B'
            self._winner_label['text'] = f'WINNER: {winner}'
        elif win_num == 2:
            winner = 'W'
            self._winner_label['text'] = f'WINNER: {winner}'
        elif win_num == 0:
            winner = 'NONE'
            self._winner_label['text'] = f'WINNER: {winner}'
Example #2
0
    def _redraw_all_spots(self) -> None:

        gamestate = joshuaconsole1.Gamestate(self._turn, self._dimensions,
                                             self._winner, self.board)
        scores = gamestate.count_pieces()
        b = scores[0]
        self._b_count = b
        w = scores[1]
        self._w_count = w
        self._score_label['text'] = f'Black: {b} White: {w}'

        self._canvas.delete(tkinter.ALL)
        self._redraw_all_lines()

        for spot in self._state.all_black_spots():
            self._draw_black_spot(spot)

        for spot in self._state.all_white_spots():
            self._draw_white_spot(spot)
Example #3
0
    def _on_canvas_clicked(self, event: tkinter.Event) -> None:

        gamestate = joshuaconsole1.Gamestate(self._turn, self._dimensions,
                                             self._winner, self.board)
        turn = gamestate.current_player()
        self._display_turn(turn)
        canvas_width = self._canvas.winfo_width()
        canvas_height = self._canvas.winfo_height()
        converted = self.convert_piece(event.x, event.y)

        check = gamestate.check_if_game_playable()
        if check == True:

            coordinates = self._update_gamestate(converted)
            game2 = gamestate.ultimate_check(coordinates)
            game3 = list(set(game2))
            game3.append(coordinates)

            if game2 != []:
                for x in game3:
                    update_pieces = self.reversed_convert_piece(x)
                    gamestate.drop_piece(x)

                    click_point = point1.from_pixel(update_pieces[0],
                                                    update_pieces[1],
                                                    canvas_width,
                                                    canvas_height)
                    if self._turn.upper() == 'B':
                        self._state.handle_black_click(click_point)
                        if x != game3[-1]:
                            self._state.handle_white_click(click_point)

                    elif self._turn.upper() == 'W':
                        self._state.handle_white_click(click_point)
                        if x != game3[-1]:
                            self._state.handle_black_click(click_point)
                self._next_player()

            self._redraw_all_spots()

        check = gamestate.check_if_game_playable()
        if check == False:
            self._game_over(event)
Example #4
0
    def setup_board(self, event: tkinter.Event) -> None:
        width = self._canvas.winfo_width()
        height = self._canvas.winfo_height()
        converted = self.convert_piece(event.x, event.y)

        gamestate = joshuaconsole1.Gamestate(self._turn, self._dimensions,
                                             self._winner, self.board)

        coordinates = self._update_gamestate(converted)
        game1 = gamestate.drop_piece(coordinates)

        click_point = point1.from_pixel(converted[0], converted[1], width,
                                        height)

        if self._turn.upper() == 'B':
            self._state.handle_black_click(click_point)
        else:
            self._state.handle_white_click(click_point)

        self._redraw_into_spots()
Example #5
0
    def update_button3(self):
        if self._turn == 'B':
            title2 = tkinter.StringVar()
            title2.set("Let's Play The Game! PLAYER W GOES FIRST")
            self._title = tkinter.Label(master=self._root_window,
                                        textvariable=title2,
                                        font=DEFAULT_FONT)
            self._title.grid(row=4,
                             column=0,
                             padx=10,
                             pady=10,
                             sticky=tkinter.S)
            self._turn = 'W'
        else:
            title3 = tkinter.StringVar()
            title3.set("Let's Play The Game! PLAYER B GOES FIRST")
            self._title = tkinter.Label(master=self._root_window,
                                        textvariable=title3,
                                        font=DEFAULT_FONT)
            self._title.grid(row=4,
                             column=0,
                             padx=10,
                             pady=10,
                             sticky=tkinter.S)
            self._turn = 'B'

        self._button3.destroy()
        self._title3.destroy()
        gamestate = joshuaconsole1.Gamestate(self._turn, self._dimensions,
                                             self._winner, self.board)
        check = gamestate.check_if_game_playable()

        if check == True:
            self._title.destroy()
            turn = gamestate.current_player()
            self._display_turn(turn)
            self._canvas.bind('<Button-1>', self._on_canvas_clicked)
        else:
            self._title.destroy()
            end_title = tkinter.StringVar()
            end_title.set("GAME OVER")
            self._end_title = tkinter.Label(master=self._root_window,
                                            textvariable=end_title,
                                            font=DEFAULT_FONT)
            self._end_title.grid(row=5,
                                 column=0,
                                 padx=10,
                                 pady=10,
                                 sticky=tkinter.S)
            self._canvas.bind('<Button-1>', self.leave_game)

            self._winner_label = tkinter.Label(master=self._root_window,
                                               text='',
                                               font=('Helvetica', 20))
            self._winner_label.grid(row=4, column=0, padx=0, pady=10)

            scores = gamestate.count_pieces()
            win_num = gamestate.check_for_winner()
            if win_num == 1:
                winner = 'B'
                self._winner_label['text'] = f'WINNER: {winner}'
            elif win_num == 2:
                winner = 'W'
                self._winner_label['text'] = f'WINNER: {winner}'
            elif win_num == 0:
                winner = 'NONE'
                self._winner_label['text'] = f'WINNER: {winner}'