Ejemplo n.º 1
0
    def test_deck_should_be_throw_exception_no_more_cards(self):
        deck = Deck([])

        with pytest.raises(Exception) as ex:
            deck.put_card()

        self.assertEqual(str(ex.value), 'No more cards. =(')
Ejemplo n.º 2
0
    def test_deck_should_be_put_a_card(self):
        cards = [
            Mock(),
            Mock(),
            Mock(),
        ]
        deck = Deck(cards)

        deck.put_card()

        self.assertEqual(len(deck.get_cards()), 2)
Ejemplo n.º 3
0
class BlackJack21(object):
    def __init__(self, player: Player):
        _cards = [
            Ace(),
            Two(),
            Three(),
            Four(),
            Five(),
            Six(),
            Seven(),
            Eight(),
            Nine(),
            Ten(),
            K(),
            Q(),
            J(),
        ]
        self._deck = Deck(_cards)
        self._player = player
        self._tapped_cards = []
        self._score = 0

    def start(self):
        _loading()
        print('==== Embaralhando ====')
        self._deck.shuffle()
        time.sleep(1.5)
        _clear()
        print('==== Mesa pronta, podemos começar ====')
        while self._deck.has_more_cards():
            input('---- Pressione ENTER para virar uma carta jogador {} ----'.
                  format(self._player))
            tapped_card = self._deck.put_card()
            self._tapped_cards.append(tapped_card)
            print('---- Carta virada ----', tapped_card)
            print(' Calculando ...')
            self._calculate_score()
            if self._is_done():
                break
            print('=== Pontuação {} ===='.format(self._score))
        self._finish()

    def _is_done(self):
        if self._score <= 21:
            return False
        return True

    def _calculate_score(self):
        self._score = sum(
            map(lambda card: card.get_value(), self._tapped_cards))

    def _finish(self):
        _clear()
        print('==== Acabou o jogo ====')
        print('==== Calculando ====')
        _loading()
        _clear()
        print('O Resultado é: {}'.format(self._score))