Example #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)
Example #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)
Example #3
0
 def test_deck(self):
     deck = Deck()
     assert 52 == len(deck.get_deck()) and 0 == len(deck.get_discard_pile())
Example #4
0
 def test_take_card(self):
     deck = Deck()
     card = deck.take_card()
     assert isinstance(card, Card)
     assert len(deck.get_deck()) == 51
Example #5
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())
Example #6
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())
Example #7
0
 def test_deal(self):
     dealer = Dealer()
     deck = Deck()
     assert len(dealer.deal(deck.get_deck()).hand) == dealer.cardCount