当前位置: 首页>>代码示例>>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;未经允许,请勿转载。