Пример #1
0
    def deal_cards(self, last_cards, last_person_identity=None):

        ## 先给玩家看自己手中的牌
        MessagePoster.post_hint(hint_type='player_show_cards',
                                unshowed_cards=str(self.cards))

        ## 让用户一直出牌, 直到牌大过上家或者放弃出牌
        while True:
            raw_order = MessageGetter.get_order(order_type='deal_cards')

            ## 退出游戏
            if isinstance(raw_order, GameExiter):
                return GameExiter()

            ## 如果玩家要不起/不要, 则返回None
            if raw_order == 'p':

                ## 有牌权出牌不能跳过
                if last_cards is not None:
                    MessagePoster.post_hint(
                        hint_type='person_abandon_dealing_cards',
                        output_name=self.output_name)
                    return
                else:
                    MessagePoster.post_hint(
                        hint_type=
                        'player_can_not_skip_deal_cards_without_last_cards')
                    continue

            undealed_cards = Cards([Card(pattern) for pattern in raw_order])

            ## 牌的验证
            ## 牌的子集验证
            if not undealed_cards in self.cards:
                MessagePoster.post_hint(
                    hint_type='invaild_cards_pattern_or_too_many_cards')
                continue
            meta_data = undealed_cards.cal_meta_data()

            ## 牌的元数据验证(实际是有效性验证)
            if meta_data is None:
                MessagePoster.post_hint(hint_type='invaild_cards_species')
                continue

            ## 出牌
            ## 如果是有牌权出牌, 可以直接出
            if last_cards is None:
                MessagePoster.post_hint(hint_type='person_dealed_cards',
                                        output_name=self.output_name,
                                        unprinted_cards=str(undealed_cards))
                self.cards -= undealed_cards
                return undealed_cards

            ## 牌型相符且牌比上家大(考虑到炸弹类型)
            elif undealed_cards > last_cards:
                MessagePoster.post_hint(hint_type='person_dealed_cards',
                                        output_name=self.output_name,
                                        unprinted_cards=str(undealed_cards))
                self.cards -= undealed_cards
                return undealed_cards

            ## 牌型不符或牌型一样但没有上家大
            else:
                MessagePoster.post_hint(hint_type='cards_size_too_small')
                continue