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


Python GameState.addPlayer方法代码示例

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


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

示例1: players

# 需要导入模块: import GameState [as 别名]
# 或者: from GameState import addPlayer [as 别名]

#.........这里部分代码省略.........
  # make a list of numbers of tricks for each hand
  # Parameter:
  #   handNum - number of the hand to start with (0 = first)
  # Return value:
  #   a list of the number of tricks for each hand
  #
  def makeTrickNums(self, handNum):
    trickNums = []
    
    for i in range(10,1,-1):
      trickNums.append(i)
      
    for i in range(self.numPlayers):
      trickNums.append(1)
      
    for i in range(2,11):
      trickNums.append(i)
      
    return trickNums[handNum:]

  #
  # start game
  # Parameters:
  #   handNum - number of hand to start with (0 = first)
  #   dealer  - index of player to start dealing (-1 to pick randomly)
  #
  def startGame(self, handNum, dealer):
    print 'startGame()'
    startMessage = 'START_GAME ' + str(self.numPlayers) + ' '
    id = 0
    for player in self.players:
      startMessage = startMessage + player.name + ' ' + str(player.score) + ' '
      if handNum == 0:
        self.gameState.addPlayer( id, player.name, None)
      id = id + 1
    self.broadcastMessage(startMessage)
    self.trickNums = self.makeTrickNums(handNum)

    self.handNum = 0

    self.numHands = 18 + self.numPlayers - self.handNum
    
    if dealer < 0:
      self.dealer = random.randrange(self.numPlayers)
    else:
      self.dealer = dealer
    print 'Initial dealer:', self.dealer

  #
  # calculate index of next player in sequence
  # Parameter:
  #   playerNum - current player
  # Return value:
  #   index of next player
  #
  def nextPlayer(self, playerNum ):
    return (playerNum + 1) % self.numPlayers

  #
  # start playing hand
  # creates new deck, deals cards and picks trump (if necessary)
  #
  def startHand(self):
    print 'startHand()'
    self.broadcastMessage('NEW_HAND %d %d' % ( self.trickNums[self.handNum],
                          self.dealer))
开发者ID:SeanCCarter,项目名称:ohell,代码行数:70,代码来源:server.py


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