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


Python Messenger.read方法代码示例

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


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

示例1: client_thread

# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import read [as 别名]
def client_thread(conn):
    current_state = WAITING_TO_START_GAME
    messenger = Messenger(conn)
    while current_state is not GAME_OVER:
        if current_state is WAITING_TO_START_GAME:
            game = init_game(messenger)
            current_state = WAITING_FOR_MOVE
        elif current_state is WAITING_FOR_MOVE:
            letter = messenger.read()
            if game.already_guessed(letter):
                reply = "You've already guessed %r." % letter
            else:
                game.guess_letter(letter)
                reply = str(game)

            if game.gameover:
                current_state = WAITING_TO_PLAY_AGAIN
            messenger.send(reply)
            messenger.send(str(game.gameover))
        elif current_state is WAITING_TO_PLAY_AGAIN:
            play_again = messenger.read()
            if play_again == "play":
                current_state = WAITING_TO_START_GAME
            elif play_again == "quit":
                current_state = GAME_OVER

    conn.close()
开发者ID:RealStyle12,项目名称:hangman,代码行数:29,代码来源:server.py

示例2: str

# 需要导入模块: from messenger import Messenger [as 别名]
# 或者: from messenger.Messenger import read [as 别名]
    except socket.error, msg:
        print "Client: Failed to create socket. Error code: " + str(msg[0]) \
                + ", Error message: " + msg[1]
        sys.exit()
    return c


if __name__ == "__main__":
    sock = make_socket()
    sock.connect((HOST,PORT))
    messenger = Messenger(sock)
    current_state = WAITING_FOR_WELCOME

    while current_state is not GAME_OVER:
        if current_state is WAITING_FOR_WELCOME:
            print messenger.read()
            current_state = WAITING_FOR_BOARD
        elif current_state is WAITING_FOR_BOARD:
            print messenger.read() 
            current_state = WAITING_FOR_GAME_STATUS
        elif current_state is WAITING_FOR_GAME_STATUS:
            msg = messenger.read()
            if msg == "True":
                current_state = WAITING_TO_PLAY_AGAIN
            elif msg == "False":
                current_state = WAITING_FOR_USER_INPUT
        elif current_state is WAITING_FOR_USER_INPUT:
            guess = raw_input("Guess a letter: ").lower()
            if len(guess) > 1 or guess not in string.lowercase:
                print "Please guess a letter."
            else:
开发者ID:RealStyle12,项目名称:hangman,代码行数:33,代码来源:client.py


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