當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。