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


Python Deck.get_n_cards方法代码示例

本文整理汇总了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)
开发者ID:lottepuski,项目名称:glory_to_rome,代码行数:75,代码来源:players.py


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