Ejemplo n.º 1
0
class Round(Dealer):
    first_player = 0
    current_player = 0
    turn = 1
    last_turn = 1
    knocked = False

    def __init__(self, players):
        super().__init__()
        self.players = players
        self.deck = Deck()

    def prepare_new_round(self):
        self.turn = 1
        self.last_turn = 1
        self.knocked = False
        self.deck = Deck()

    def deal_cards(self, players):
        for p in players:
            p.hand = self.deal(self.deck.get_deck())

    def prepare_turn(self):
        self.deck.check_stack()
        self.check_knocked()

    def get_turn(self, round):
        # Todo: find out why round is being passed back to itself
        return "Turn %i, %s\n" % (round.turn, round.get_current_players_name())

    def get_current_players_hand(self):
        return self.players[self.current_player].get_hand_to_print()

    def end_turn(self):
        self.switch_current_player()
        self.turn += 1

    def check_knocked(self):
        if self.knocked:
            self.last_turn += 1

    def switch_current_player(self):
        self.current_player = (self.current_player + 1) % len(self.players)

    def rotate_first_player(self):
        self.first_player += 1
        self.current_player = self.first_player % len(self.players)
Ejemplo n.º 2
0
class Round(Dealer):
    first_player = 0
    current_player = 0
    turn = 1
    last_turn = 1
    knocked = False

    def __init__(self, players):
        super().__init__()
        self.players = players
        self.deck = Deck()

    def prepare_new_round(self):
        self.turn = 1
        self.last_turn = 1
        self.knocked = False
        self.deck = Deck()

    def deal_cards(self, players):
        for p in players:
            p.hand = self.deal(self.deck.get_deck())

    def prepare_turn(self):
        self.deck.check_stack()
        self.check_knocked()

    def end_turn(self):
        self.switch_current_player()
        self.turn += 1

    def check_knocked(self):
        if self.knocked:
            self.last_turn += 1

    def switch_current_player(self):
        self.current_player = (self.current_player + 1) % len(self.players)

    def rotate_first_player(self):
        self.first_player += 1
        self.current_player = self.first_player % len(self.players)
Ejemplo n.º 3
0
 def prepare_new_round(self):
     self.turn = 1
     self.last_turn = 1
     self.knocked = False
     self.deck = Deck()
Ejemplo n.º 4
0
 def __init__(self, players):
     super().__init__()
     self.players = players
     self.deck = Deck()
Ejemplo n.º 5
0
 def test_discard_card(self):
     hand = Dealer().deal(Deck().deck)
     hand.discard_card(0)
     assert len(hand.hand) == 6
Ejemplo n.º 6
0
 def test_hand_string(self):
     hand = Dealer().deal(Deck().deck)
     assert len(re.findall(r'[ATJQK2-9].*?[♥♣♦♠]', str(hand))) == 7
Ejemplo n.º 7
0
 def test_deck(self):
     deck = Deck()
     assert 52 == len(deck.get_deck()) and 0 == len(deck.get_discard_pile())
Ejemplo n.º 8
0
 def test_discard_card(self):
     deck = Deck()
     deck.discard_card(deck.take_card())
     assert len(deck.get_discard_pile()) == 1
Ejemplo n.º 9
0
    def test_inspect_discard(self):
        deck = Deck()

        deck.discard_card(deck.take_card())
        assert isinstance(deck.inspect_discard(), Card)
        assert len(deck.get_discard_pile()) == 1
Ejemplo n.º 10
0
 def test_take_card(self):
     deck = Deck()
     card = deck.take_card()
     assert isinstance(card, Card)
     assert len(deck.get_deck()) == 51
Ejemplo n.º 11
0
 def test_take_discard(self):
     deck = Deck()
     deck.discard_card(deck.take_card())
     discard = deck.take_discard()
     assert isinstance(discard, Card)
     assert len(deck.get_discard_pile()) == 0
Ejemplo n.º 12
0
 def test_has_discard(self):
     deck = Deck()
     deck.discard_card(deck.take_card())
     assert deck.has_discard()
Ejemplo n.º 13
0
 def test_show_discard(self):
     deck = Deck()
     deck.discard_card(deck.take_card())
     assert re.match(r'[ATJQK2-9].*?[♥♣♦♠]', deck.show_discard())
Ejemplo n.º 14
0
 def test_check_stack(self):
     deck = Deck()
     for _ in range(52):
         deck.discard_card(deck.take_card())
     deck.check_stack()
     assert 52 == len(deck.get_deck()) and 0 == len(deck.get_discard_pile())
Ejemplo n.º 15
0
 def test_draw_all_cards(self):
     deck = Deck()
     for _ in range(52):
         deck.discard_card(deck.take_card())
     assert 0 == len(deck.get_deck()) and 52 == len(deck.get_discard_pile())
Ejemplo n.º 16
0
 def test_deal(self):
     dealer = Dealer()
     deck = Deck()
     assert len(dealer.deal(deck.get_deck()).hand) == dealer.cardCount