本文整理汇总了Python中gamestate.GameState.getPlayer方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getPlayer方法的具体用法?Python GameState.getPlayer怎么用?Python GameState.getPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gamestate.GameState
的用法示例。
在下文中一共展示了GameState.getPlayer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Client
# 需要导入模块: from gamestate import GameState [as 别名]
# 或者: from gamestate.GameState import getPlayer [as 别名]
class Client(QObject):
sendReady = pyqtSignal(int, list)
readyToConnect = pyqtSignal()
def __init__(self, host, port, name = "", parent = None):
QObject.__init__(self, parent)
self.game = GameState()
self.host = host
self.port = port
self.name = name
self.connection = Connection(client=True)
self.connection.messageReceived.connect(self.handleMessage)
self.connection.error.connect(self.handleError)
self.sendReady.connect(self.connection.sendMessage)
self.connection.connectToHost(self.host, self.port)
while not self.connection.waitForConnected(10000):
if not QMessageBox.Retry == QMessageBox.critical(None, "Connection Failed", "Failed to connect to %s on port %d" % (self.host, self.port), QMessageBox.Retry | QMessageBox.Cancel):
sys.exit()
self.send(Message.Join)
QApplication.setQuitOnLastWindowClosed(False)
def send(self, msg, args = []):
self.sendReady.emit(msg, args)
def handleError(self, err):
log.error(self.connection.errorString())
QMessageBox.critical(None, "Network Error", self.connection.errorString())
QApplication.quit()
def handleMessage(self, msg, args):
if msg == Message.Ping:
self.send(Message.Pong)
elif msg == Message.StateChanged:
self.handleStateChange(*args)
elif msg == Message.ReceiveChat:
(sender, text, timestamp) = args
p = self.game.getPlayer(sender)
if not p:
color = (128, 128, 128)
else:
color = p.color
self.mainWindow.chat.addLine(Line(Line.Chat, sender=sender, text=text, playerColor=color, timestamp = timestamp))
elif msg == Message.ReceiveWhisper:
(sender, target, text, timestamp) = args
p = self.game.getPlayer(sender)
self.mainWindow.chat.addLine(Line(Line.Whisper, sender=sender, target=target, text=text, playerColor=p.color, timestamp = timestamp))
elif msg == Message.WhisperError:
self.mainWindow.chat.addLine("No such player.")
elif msg == Message.JoinSuccess:
name = self.name
while not name:
(name, ok) = QInputDialog.getText(None, "Username", "Name")
if not ok:
QApplication.quit()
break
self.send(Message.RequestName, [name])
elif msg == Message.NameTaken:
name = ""
while not name:
(name, ok) = QInputDialog.getText(None, "Name Taken", "New name")
if not ok:
QApplication.quit()
break
self.send(Message.RequestName, [name])
elif msg == Message.NameAccepted:
(self.clientPlayerName, self.password) = args
self.send(Message.RequestPlayerList)
elif msg == Message.PlayerJoined:
name = args[0]
color = args[1:]
player = self.game.addPlayer(name)
player.color = color
self.mainWindow.chat.addLine(Line(Line.PlayerJoined, target=name))
self.mainWindow.playerInfo.addPlayer(player)
elif msg == Message.GameInProgress:
password = ""
while not password:
(password, ok) = QInputDialog.getText(None, "Game Already Inprogress", "Password")
if not ok:
QApplication.quit()
break
self.send(Message.Rejoin, [str(password)])
elif msg == Message.IncorrectPassword:
password = ""
while not password:
(password, ok) = QInputDialog.getText(None, "Incorrect Password", "Password")
if not ok:
QApplication.quit()
break
self.send(Message.Rejoin, [str(password)])
#.........这里部分代码省略.........