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


Python Deck.refill方法代码示例

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


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

示例1: Game

# 需要导入模块: from Deck import Deck [as 别名]
# 或者: from Deck.Deck import refill [as 别名]
class Game(object):

  def __init__(self, numPlayers=1, numAI = 3):
    """
    basic set up for a game where:
    numPlayers = the total number of  human players
    numAI = the number of the total players that are AI
    """
    self.totPlayers = numPlayers + numAI
    #checking that there are atleast 2 players
    if (self.totPlayers) < 2:
      raise Exception('need atleast 2 players to play the game')
    
    self.deck = Deck()
    
    self.numPlayers = numPlayers
    self.numAI = numAI
    
    self.winners = []
    
    #setting up the players
    self.players = []
    [self.players.append(Player(len(self.players), game=self, AI = len(self.players) >= numPlayers)) for i in range(numPlayers + numAI)]
    
    for i in range(len(self.players)):
      self.players[i].setPrev(self.players[i-1])
      self.players[i].setNext(self.players[(i + 1) % len(self.players)])
  
  
  def play(self):
    self.dealHands()
    self.played = [[]]
    player = self.players[0]
    while not self.endCondition():
      print("--------------------------------------")
      print("It is player " + str(player.idNum) + " turn")
      played = player.play(self.played[-1])
      if played: self.played.append(played)
      player = self.playerPlayed(player, played) if played else self.cantPlay(player)
      player = self.outOfTurnPlay(player, played)
    
    self.winMessage()
  
  def refillDeck(self):
    keep = [self.played.pop()]
    add = []
    toAdd = self.played
    for it in toAdd:
      if type(it) is Card:
        add.append(it)
        
    self.deck.refill(add)
    self.played = keep
    print("+++++++++++++++++++++++++++deck refilled from discarded +++++++++++++++")
    print(self.played)
  
  def endCondition(self):
    raise Exception("implemention must define this")
  
  def validPlays(self, hand, lastPlayed):
    raise Exception("implemention must define this")
  
  def cantPlay(self, player):
    raise Exception("implemention must define this")
  
  def playerPlayed(self, player, played):
    raise Exception("implemention must define this")
  
  def dealHands(self):
    raise Exception("implemention must define this")
  
  def winMessage(self):
    raise Exception("implementation must define this")
  
  def outOfTurnPlay(self, lastPlayer, lastPlayed):
    return lastPlayer
      
      
  
  def __str__(self):
    return str(self.players)
开发者ID:ejgillia,项目名称:plm18_f,代码行数:83,代码来源:Game.py


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