本文整理汇总了Python中cards.Deck.get_n_cards方法的典型用法代码示例。如果您正苦于以下问题:Python Deck.get_n_cards方法的具体用法?Python Deck.get_n_cards怎么用?Python Deck.get_n_cards使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cards.Deck
的用法示例。
在下文中一共展示了Deck.get_n_cards方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Players
# 需要导入模块: from cards import Deck [as 别名]
# 或者: from cards.Deck import get_n_cards [as 别名]
class Players(RingBuffer):
''' Players is the general purpose class that holds the all data relating
to players and the game.
'''
def __init__(self):
super(Players, self).__init__()
self.__players_map = dict()
self.deck = Deck()
def add_player(self, name):
if self._get_num_objs() < MAX_PLAYERS:
assert isinstance(name, str)
self._add_object(name)
player = Player(name)
player.add_to_hand(self.deck.get_n_cards(player.hand_size))
self.__players_map[name] = player
else:
return "Sorry. Already reached maximum number of players"
def remove_player(self, name):
assert isinstance(name, str)
self._remove_object(name)
def choose_next_leader(self):
self._advance_right(1)
def get_current_leader(self):
return self._get_head_obj()
def get_current_order(self):
return self._objs_to_list()
def get_num_players(self):
return self._get_num_objs()
def get_player(self, index):
return self._get_obj_at_index(index)
def get_player_by_name(self, name):
return self.__players_map[name]
def add_card_to_hand(self, name, card):
'''
:param name:
:param card:
:return: True or False
'''
# assert isinstance(name, str) and self.__players_map.has_key(name)
player = self.get_player_by_name(name)
if len(player.hand) < player.hand_size:
player.hand.append(card)
return True
return False
def get_current_state(self, name):
try:
player = self.get_player_by_name(name)
except KeyError:
raise UnknownPlayerException, "Player not found"
return player.__repr__()
def bring_card_to_play(self, name, card):
'''
:param card: dict
:return: None
'''
player = self.get_player_by_name(name)
print player.name
for i, x in enumerate(player.hand):
if x.equal(card):
player.card_in_play = player.hand.pop(i)