コード例 #1
0
ファイル: oxo_ui.py プロジェクト: slmagicbox/PyProj
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')
コード例 #2
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))
コード例 #3
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')
コード例 #4
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")
コード例 #5
0
ファイル: oxo_ui.py プロジェクト: DanOswalt/oxogame
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))
コード例 #6
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')
コード例 #7
0
ファイル: oxo_ui.py プロジェクト: garg10may/Tic-Tac-Toe
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)
コード例 #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")
コード例 #9
0
ファイル: oxo_ui.py プロジェクト: garg10may/Tic-Tac-Toe
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)
コード例 #10
0
ファイル: oxo_gui.py プロジェクト: DanOswalt/oxogame
def evSave():
    game = cells2game()
    oxo_logic.saveGame(game)
コード例 #11
0
def evSave():
    game = cells2game()
    oxo_logic.saveGame(game)