本文整理汇总了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()
示例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: