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