当前位置: 首页>>代码示例>>Python>>正文


Python Console.winner_is_chosen方法代码示例

本文整理汇总了Python中Console.winner_is_chosen方法的典型用法代码示例。如果您正苦于以下问题:Python Console.winner_is_chosen方法的具体用法?Python Console.winner_is_chosen怎么用?Python Console.winner_is_chosen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Console的用法示例。


在下文中一共展示了Console.winner_is_chosen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: introduction

# 需要导入模块: import Console [as 别名]
# 或者: from Console import winner_is_chosen [as 别名]
def introduction(connection: 'connection', input_str: str):
    # This is used to send client introduction to server
    # Use username() function
    s_output = connection[2]
    s_input = connection[1]
    user = username()
    newGameCall = (input_str + ' ' + user)
    send_to_server(s_output, newGameCall)
    print('Client: ' + newGameCall)
    serverReply = receive_from_server(s_input)
    print('Server: ' + (serverReply))
    expectedReply = 'WELCOME ' + user.strip()
    if serverReply == expectedReply:
        newGame = sendGameRequest(connection)
        #print('Server: ' +serverReply)
        #userInput(newGame, connection)
    
        
        while Console.winner_is_chosen(newGame) == connectfour.NONE:

            userCommand = []
            if newGame.turn == 1:
                clientInput = ''
                clientInput = input('Client: ')
                userCommand = (clientInput).split()
                if 0 < int(userCommand[1]) <= len(newGame[0]):
                    if userCommand[0].lower() == 'drop':
                        newGame = Console.drop_piece(newGame, int(userCommand[1])-1)
                        Console.print_board(newGame)
                        send_to_server(s_output, userCommand[0].upper()+' ' +str(userCommand[1]))
                        print(receive_from_server(s_input))
                    elif userCommand[0].lower() == 'pop':
                        newGame = Console.pop_piece(newGame, int(userCommand[1])-1)
                        Console.print_board(newGame)
                        send_to_server(s_output, userCommand[0].upper()+' ' +str(userCommand[1]))
                        print(receive_from_server(s_input))
                else:
                    clientInput = receive_from_server(s_input)
                    print(clientInput)
                     
            elif newGame.turn == 2:
                serverInput = receive_from_server(s_input)
                serverInput = serverInput.split('\r\n')
                serverInput = serverInput[0].split()
                for i in serverInput:
                    print (i, end = ' ')
                print()
                if serverInput[0].lower() == 'drop':
                    newGame = Console.drop_piece(newGame, int(serverInput[1])-1)
                    Console.print_board(newGame)
                    #send_to_server(s_output, serverInput[0].upper()+' ' +str(serverInput[1]))
                    print(receive_from_server(s_input))
                elif serverInput[0].lower() == 'pop':
                    newGame = Console.pop_piece(newGame, int(serverInput[1])-1)
                    Console.print_board(newGame)
                    #send_to_server(s_output, serverInput[0].upper()+' ' +str(serverInput[1]))
                    print(receive_from_server(s_input))
                elif serverInput[0].lower() == 'invalid':
                    print()
                
                #print(Input[:len(Input)])
        else:
            print('UserName: ERROR')
开发者ID:dblam,项目名称:Duy-s-Python-Projects,代码行数:65,代码来源:ConnectfourSocket1.py

示例2: userInterface

# 需要导入模块: import Console [as 别名]
# 或者: from Console import winner_is_chosen [as 别名]
def userInterface(connection: 'connection', input_str: str):
    ''' Introduces the user to the server and plays the game
    '''
    s_output = connection[2]
    s_input = connection[1]
    user = username()
    newGameCall = (input_str + ' ' + user)
    send_to_server(s_output, newGameCall)
    print('Client: ' + newGameCall)
    serverReply = receive_from_server(s_input)
    print('Server: ' + (serverReply))
    expectedReply = 'WELCOME ' + user.strip()
    if serverReply == expectedReply:
        newGame = sendGameRequest(connection)
        winner = Console.winner_is_chosen(newGame)
        
        while winner == 0:
            try:
                userCommand = []
                if newGame.turn == 1:
                    clientInput = ''
                    clientInput = input('Client: ')
                    userCommand = (clientInput).split()
                    if len(userCommand) == 2:
                        if 0 < int(userCommand[1]) <= len(newGame[0]):
                            if userCommand[0].lower() == 'drop':
                                newGame = Console.drop_piece(newGame, int(userCommand[1])-1)
                                Console.print_board(newGame)
                                send_to_server(s_output, userCommand[0].upper()+' ' +str(userCommand[1]))
                                print('Server: ', end = '')
                                print(receive_from_server(s_input))
                                winner = Console.winner_is_chosen(newGame)
                                if winner != 0:
                                    print('Game is over.')
                                    break
                            elif userCommand[0].lower() == 'pop':
                                try:
                                    newGame = Console.pop_piece(newGame, int(userCommand[1])-1)
                                    Console.print_board(newGame)
                                    send_to_server(s_output, userCommand[0].upper()+' ' +str(userCommand[1]))
                                    print('Server: ', end = '')
                                    print(receive_from_server(s_input))
                                    winner = Console.winner_is_chosen(newGame)
                                    if winner != 0:
                                        print('Game is over.')
                                        break
                                except:
                                    print('That\'s not a valid move.')
                                    winner = 0
                            else:
                                print('The column number you specified is not correct.')
                                winner = 0       
                        else: 
                            print('The col number you specified is greater.')
                            winner = 0
                    else:
                        print('The move is invalid. Try again')
                        winner = 0
                         
                elif newGame.turn == 2:
                    serverInput = receive_from_server(s_input)
                    serverInput = serverInput.split('\r\n')
                    serverInput = serverInput[0].split()
                    output = str()
                    for i in serverInput:
                        output += i + ' '
                    print('Server: ' + output)
                    if serverInput[0].lower() == 'drop':
                        newGame = Console.drop_piece(newGame, int(serverInput[1])-1)
                        print('Server: ' + receive_from_server(s_input))
                        Console.print_board(newGame)
                        winner = Console.winner_is_chosen(newGame)
                    elif serverInput[0].lower() == 'pop':
                        newGame = Console.pop_piece(newGame, int(serverInput[1])-1)
                        print('Server: ' + receive_from_server(s_input))
                        Console.print_board(newGame)
                        winner = Console.winner_is_chosen(newGame)
                    elif serverInput[0].lower() == 'invalid':
                        print()
                    
                else:
                    print('UserName: ERROR')
            except ValueError:
                print('The number you attempt to put is not correct. Try again.')
                winner = 0
            except TypeError:
                print('The number you tried to input is not correct format.')
                winner = 0
开发者ID:dblam,项目名称:Duy-s-Python-Projects,代码行数:90,代码来源:ConnectfourSocket1+test.py


注:本文中的Console.winner_is_chosen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。