Example #1
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Cell[1-9 or q to quit]: ")
        if choice.lower()[0] == 'q':
            save = mb.askyesno("Save game","Save game before quitting?")
            if save:
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice)-1
                if not (0 <= cell <= 8):
                    raise ValueError
            except ValueError:
                print("Choose a number or 'q' to quit")
                continue

            try:
                result = oxo_logic.userMove(game,cell)
            except ValueError:
                mb.showerror("Invalid cell", "Choose an empty cell")
                continue
            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                mb.showinfo("Result", "It's a draw")
            else:
                printGame(game)
                mb.showinfo("Result", "Winner is {}".format(result))
Example #2
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Quadrante [1-9 ou s para sair]: ")
        if choice.lower()[0] == 's':
            save = input("Salvar o jogo antes de sair? [s/n] ")
            if save.lower()[0] == 's':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice) - 1
                if not (0 <= cell <= 8):
                    raise ValueError
            except ValueError:
                print("Escolha um nĂºmero entre 1 e 9 ou 's' para sair.")
                continue

            try:
                result = oxo_logic.userMove(game, cell)
            except ValueError:
                print("Escolha um quadrante vazio.")
                continue

            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                print("Deu empate.")
            else:
                printGame(game)
                print("O vencedor foi ", result, "\n")
Example #3
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Cell[1-9 or q to quit]: ")
        if choice.lower()[0] == 'q':
            save = input("Save game before quitting?[y/n] ")
            if save.lower()[0] == 'y':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice)-1
                if not (0 <= cell <= 8):  # check range
                    raise ValueError
            except ValueError:
                print("Choose a number between 1 and 9 or 'q' to quit ")
                continue

            try:
                result = oxo_logic.userMove(game,cell)
            except ValueError:
                print("Choose an empty cell")
                continue
            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                print("Its a draw")                
            else:
                printGame(game)
                print("Winner is", result, '\n')
Example #4
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Cell[1-9 or q to quit]: ")
        if choice.lower()[0] == 'q':
            save = input("Save game before quitting?[y/n] ")
            if save.lower()[0] == 'y':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice) - 1
                if not (0 <= cell <= 8):  # check range
                    raise ValueError
            except ValueError:
                print("Choose a number between 1 and 9 or 'q' to quit ")
                continue

            try:
                result = oxo_logic.userMove(game, cell)
            except ValueError:
                print("Choose an empty cell")
                continue
            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                print("Its a draw")
            else:
                printGame(game)
                print("Winner is", result, '\n')
Example #5
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Celda[1-9 o q para quitar]: ")
        if choice.lower()[0] == 'q':
            saves = input("Guardar partida antes de abandonar??[S/N] ")
            if save.lower()[0] == 'S':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice) - 1
                if not (0 <= cell <= 8):
                    raise ValueError
            except ValueError:
                print("Escoje un numero entre 1 o 9 'q' para quitar ")
                continue

            try:
                result = oxo_logic.userMove(game, cell)
            except ValueError:
                print("Elige una celda vacia")
                continue

            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                print("Es un empate")
            else:
                printGame(game)
                print("El ganador es", result, '\n')
Example #6
0
def playGame(game):
    result =""
    printGrid()
    while not result:
        printGame(game)
        choice = raw_input('Cell[1-9 or q to quit]:')
        if choice.lower()[0] == 'q':
            save = raw_input('save game before quitting? [y/n]?')
            if save.lower()[0] =='y':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice)-1
                if not (0 <= cell <= 8): #check range
                    raise ValueError
            except ValueError:
                print "Choose a number between 1 and 9 or 'q' to quit"
                continue
        try: 
            result = oxo_logic.userMove(game,cell)
        except ValueError:
            print ("Choose any empty cell")
            continue
        if not result:
            result = oxo_logic.computerMove(game)
        if not result:
            continue
        elif result == 'D':
            printGame(game)
            print "It's a draw"
        else:
            printGame(game)
            mb.showinfo("Winner", result)  
            print ("Winner is ", result)
Example #7
0
def playGame(game):
    result = ''
    while not result:
        printGame(game)
        choice = input('Cell[1-9 or q to quit]: ')
        if choice.lower()[0] == 'q':
            save = mb.askyesno("Save game", "Save game before quitting?")
            if save:
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
            	cell = int(choice) - 1
            	if not (0 <= cell <= 8):
            		raise ValueError
            except ValueError:
                print('Choose a number between 1 and 9 or q to quit')
                continue

            try:
                result = oxo_logic.userMove(game, cell)
            except ValueError:
                mb.showerror("Invalid cell", "Choose an empty cell")
                continue
            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                mb.showinfo("Result", "It's a draw")
                print("It's a draw")
            else:
                printGame(game)
                mb.showinfo("Result", "Winner is {}".format(result))
Example #8
0
def playGame(game):
    result = ""
    while not result:
        printGame(game)
        choice = input("Cell [1-9 or q to quit]: ")
        if choice.lower()[0] == 'q':
            save = input('Save game before quitting? [y/n] ')
            if save.lower()[0] == 'y':
                oxo_logic.saveGame(game)
            quitGame()
        else:
            try:
                cell = int(choice) - 1
                if not (0 <= cell <= 8):
                    raise ValueError
            except ValueError:
                print('Choose a number between 1 and 9 or "q" to quit.')
                continue

            try:
                result = oxo_logic.userMove(game, cell)
            except ValueError:
                print('Choose an empty cell')
                continue
            if not result:
                result = oxo_logic.computerMove(game)
            if not result:
                continue
            elif result == 'D':
                printGame(game)
                print('Its a draw')
            else:
                printGame(game)
                print('Winner is', result, "\n")
Example #9
0
def playGame(game):
    result = ""
    printGrid()
    while not result:
        printGame(game)
        choice = raw_input('Cell[1-9 or q to quit]:')
        if choice.lower()[0] == 'q':
            save = raw_input('save game before quitting? [y/n]?')
            if save.lower()[0] == 'y':
                oxo_logic.saveGame(game)
            quit()
        else:
            try:
                cell = int(choice) - 1
                if not (0 <= cell <= 8):  #check range
                    raise ValueError
            except ValueError:
                print "Choose a number between 1 and 9 or 'q' to quit"
                continue
        try:
            result = oxo_logic.userMove(game, cell)
        except ValueError:
            print("Choose any empty cell")
            continue
        if not result:
            result = oxo_logic.computerMove(game)
        if not result:
            continue
        elif result == 'D':
            printGame(game)
            print "It's a draw"
        else:
            printGame(game)
            mb.showinfo("Winner", result)
            print("Winner is ", result)
Example #10
0
def evClick(row, col):
    if status['text'] == 'Game over':
        mb.showerror("Game over", "Game over!")
        return

    game = cells2game() #translate the gameboard to the game string
    index = (3 * row) + col #record the index of the string
    result = oxo_logic.userMove(game, index) #get "", "X", "O", or "D"
    game2cells(game) #draw the new user move

    if not result:
        result = oxo_logic.computerMove(game)
        game2cells(game) #if no result, get a computer move and draw it
    if result == "D":
        mb.showinfo("Result", "It's a draw!")
        status['text'] == 'Game over'
    else:
        if result == "X" or result == "O":
            mb.showinfo("Result", "The winner is: {}".format(result))
            status['text'] == 'Game over'
def evClick(row, col):
    if status['text'] == "Game over":
        mb.showerror("Game over", "Game over!")
        return

    game = cells2game()
    index = (3 * row) + col
    result = oxo_logic.userMove(game, index)
    game2cells(game)

    if not result:
        result = oxo_logic.computerMove(game)
        game2cells(game)
    if result == "D":
        mb.showinfo("Result", "It's a Draw!")
        status['text'] = "Game over"
    else:
        if result == "X" or result == "O":
            mb.showinfo("Result", "The winner is: {}".format(result))
            status['text'] = "Game over"
Example #12
0
def evClick(row,col):
    if status['text']=='Game Over':
        showerror('Game over', 'Game over!')
        return
    
    game = cells2game()
    index = (3*row) + col
    result = oxo_logic.userMove(game, index)
    game2cells(game)
    
    if not result:
        result = oxo_logic.computerMove(game)
        game2cells(game)
    if result == 'D':
        showinfo("Result", "It's a Draw")
        status['text']='Game Over'
    else:
        if result == "X" or result == "O":
            showinfo("Result", "The winner is: {}".format(result))
            status['text']='Game Over'