當前位置: 首頁>>代碼示例>>Python>>正文


Python GameState.generateXML方法代碼示例

本文整理匯總了Python中GameState.generateXML方法的典型用法代碼示例。如果您正苦於以下問題:Python GameState.generateXML方法的具體用法?Python GameState.generateXML怎麽用?Python GameState.generateXML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GameState的用法示例。


在下文中一共展示了GameState.generateXML方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: players

# 需要導入模塊: import GameState [as 別名]
# 或者: from GameState import generateXML [as 別名]

#.........這裏部分代碼省略.........
        self.players[self.dealer].sendMessage('BADBID %d' % bid)

  #
  # play a hand
  #
  def playHand( self ):
    hand = HandState(len(self.players), self.trickNums[self.handNum],
                     self.trump, self.dealer)
    for i in range(len(self.players)):
      cards = []
      for c in range(52):
        if self.players[i].hasCard(c):
          cards.append(c)
      hand.setHand(i, cards)
      hand.setBid(i, self.players[i].bid)
    playerNum = self.nextPlayer(self.dealer)
    for i in range(self.trickNums[self.handNum]):
      winnerNum, trick = self.playTrick(playerNum)
      hand.addTrick(trick)
      self.players[winnerNum].wonTrick()
      playerNum = winnerNum
      self.broadcastMessage( 'TRICK_WINNER %d' % winnerNum)

##    if self.trump == -1:
##      trumpSuite = None
##    else:
##      trumpSuite = cardSuit(self.trump)

    for i in range(len(self.players)):
      hand.setTricksMade(i, self.players[i].numTricks)
    self.gameState.addHand(hand)
    
    xmlFile = open(self.xmlFileName, "w")
    xmlFile.write( self.gameState.generateXML() )
    xmlFile.close()
    
    deltas = self.updateScores()
    message = 'END_HAND '
    for delta in deltas:
      message = message + '%d ' % delta
    self.broadcastMessage(message)

  #
  # play a trick of a hand
  # Parameter:
  #   leadPlayerNum - index of player to lead
  #
  def playTrick(self, leadPlayerNum):
    playerNum = leadPlayerNum
    firstCard = -1
    cards = []
    trick = TrickState()
    for i in range(self.numPlayers):
      player = self.players[playerNum]
      cardOK = 0
      while not cardOK:
        card = self.playCard(player, firstCard)
        cardOK = card >= 0
      if firstCard == -1:
        firstCard = card
      self.broadcastMessage('CARD_PLAYED %d %d' % (playerNum, card))
      cards.append( (playerNum, card) )
      trick.addCard( playerNum, card )
      playerNum = self.nextPlayer(playerNum)
    return self.findWinner(cards), trick
開發者ID:SeanCCarter,項目名稱:ohell,代碼行數:69,代碼來源:server.py


注:本文中的GameState.generateXML方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。