示例#1
0
def Move(r, c, buttons, ownmove, Gamemode):
    result = game.setMove(r, c)
    
    # do things only when the move was valid
    if result:        
        # the bot has moved after player, so the field must be refreshed to 
        # display moves made by bot
        if result is 2 or result is 3:
            refresh_field(buttons)
        else: # update only the button that was set by the player
            buttons[r][c]["text"] = game.getValue(r, c)
            
        winner = game.finished()
        if winner:
            if (ownmove and (Gamemode == mode.SERVER or Gamemode == mode.CLIENT)):
                sendMove(r, c) # send move to opponent, so he also knows who won
            try:
                connection.close()

            finally:
                tkMsg.showinfo("Spielende", str(winner) + " hat das Spiel gewonnen!")
                showMenu()

        
        if (ownmove and (Gamemode == mode.SERVER or Gamemode == mode.CLIENT)):
            sendMove(r, c)
            MainWindow.update()
            waitForMove(buttons, Gamemode)
示例#2
0
    def update_b8(self):
        #self.button8["text"] = self.mark

        index = 8
        complete = g.finished(self.board)
        if self.board[index] == ' ' and not complete:
            self.board[index] = 'X'
            self.update()
            complete = g.finished(self.board)
            if not complete:
                self.board = g.get_next_move(self.board)
                self.update()
                complete = g.finished(self.board)
        if complete:
            winner = g.win(self.board)
            if winner == 1:
                #print("Player Wins")
                ask = tk.messagebox.askretrycancel(
                    "Player Wins", "The Winner is Player!" + "\n" +
                    "Would you like to play again?")
                if ask == True:
                    os.execl(sys.executable, os.path.abspath(__file__),
                             *sys.argv)
                else:
                    sys.exit(0)
            elif winner == -1:
                #print("Computer Wins")
                ask = tk.messagebox.askretrycancel(
                    "Computer Wins", "The Winner is Computer!" + "\n" +
                    "Would you like to play again?")
                if ask == True:
                    os.execl(sys.executable, os.path.abspath(__file__),
                             *sys.argv)
                else:
                    sys.exit(0)
            elif winner == 0:
                ask = tk.messagebox.askretrycancel(
                    "Draw", "The Match was a DRAW!" + "\n" +
                    "Would you like to play again?")
                if ask == True:
                    os.execl(sys.executable, os.path.abspath(__file__),
                             *sys.argv)
                else:
                    sys.exit(0)