def setUp(self):
     self.deck = Deck()
     self.deck.populate()
     self.player = Player("Jake")
     self.card = Card("Spades", 10)
     self.card2 = Card("Spades", 10)
     self.card3 = Card("Spades", 5)
Пример #2
0
def search_name_card() -> object:
    codeCard: int = inform_code('Card')

    if codeCard == 0:
        return Card(0, '')
    # Check if have the card exist
    regcard: Card = Card(codeCard, Card.findcode(codeCard).strip())

    return regcard
Пример #3
0
def update(option: int) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option)
        if int(regcard.codeCard) > 0:
            regcard.nameCard = inform_name('Card')
            Card.updatedb(regcard)

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N}? ')
Пример #4
0
def insert(option: int) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option)
        if int(regcard.codeCard) > 0:
            # the code informed is ok
            regcard.nameCard = inform_name('Card')
            Card.insertdb(regcard)

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N]? ')
Пример #5
0
    def populate(self):
        all_suits = Suit()
        all_values = CardValue()
        all_cards = []

        for value in all_values.symbols:
            for suit in all_suits.suits:
                new_card = Card(suit, value)
                new_card.add_value()
                all_cards.append(new_card)

        self.cards = all_cards
Пример #6
0
class TestCard(unittest.TestCase):
    def setUp(self):
        self.card = Card("Spades", "Ten")

    def test_has_suit(self):
        self.assertEqual("Spades", self.card.suit)

    def test_has_symbol(self):
        self.assertEqual("Ten", self.card.symbol)

    def test_can_add_value(self):
        self.card.add_value()
        self.assertEqual(10, self.card.value)
Пример #7
0
def insert(option: int, dfcard: DataFrame) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option, dfcard)
        if int(regcard.codeCard) > 0:
            # the code informed is ok
            regcard.nameCard = inform_name('Card')

            dfcard.loc[len(dfcard) + 1] = [regcard.codeCard, regcard.nameCard]
            Card.insertdb(regcard)

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N]? ')
Пример #8
0
    def test_threeOfAKind(self):
        ranks = [7, 7, 7, 4, 5]
        suits = ['d', 'c', 'h', 's']
        hand = Hand(
            [Card(suits[random.randint(0, 3)], ranks[i]) for i in range(5)])

        assert hand.isThreeOfAKind() == True
Пример #9
0
    def test_sighCardWithoutAce(self):
        ranks = [3, 7, 11, 4, 5]
        suits = ['d', 'c', 'h', 's']
        hand = Hand(
            [Card(suits[random.randint(0, 3)], ranks[i]) for i in range(5)])

        assert hand.highCard() == 11
Пример #10
0
    def test_straightEdgeCase(self):
        ranks = [10, 11, 12, 13, 1]
        suits = ['d', 'c', 'h', 's']
        hand = Hand(
            [Card(suits[random.randint(0, 3)], ranks[i]) for i in range(5)])

        assert hand.isStraight() == True
Пример #11
0
    def test_straight(self):
        ranks = [1, 2, 3, 4, 5]
        suits = ['d', 'c', 'h', 's']
        hand = Hand(
            [Card(suits[random.randint(0, 3)], ranks[i]) for i in range(5)])

        assert hand.isStraight() == True
Пример #12
0
def menu():
    option = ' '
    dfcard = Card.upload_dataframe(self=object)
    while option != '0':
        print('''Select the option Card
        1 - Insert
        2 - Update
        3 - Delete
        4 - List
        0 - Exit''')
        option = input('option: ').strip()
        if option == '0':
            continue
        elif option == '1':
            insert(int(option), dfcard)
        elif option == '2':
            update(int(option), dfcard)
        elif option == '3':
            delete(int(option), dfcard)
        elif option == '4':
            list(dfcard)
        else:
            print('-' * 40)
            print('\33[1;31mInvalid option\33[m')
            print('-' * 40)
    print('-' * 40)
Пример #13
0
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent

        self.hand_frame_height = 315
        self.result_text = tk.StringVar()
        self.image_manager = ImageManager()
        self.result_label = tk.Label(self,
                                     font=('', 24),
                                     textvariable=self.result_text)
        self.dealer_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.player_hand_frame = HandFrame(self, bg='#f0f0f0', bd=10)
        self.hit_button = tk.Button(self,
                                    text='Hit',
                                    font=('', 16),
                                    command=self.hit_button_pressed)
        self.pass_button = tk.Button(self,
                                     text='Pass',
                                     font=('', 16),
                                     command=self.pass_button_pressed)
        self.play_button = tk.Button(self,
                                     text='Play',
                                     font=('', 20),
                                     command=self.play_button_pressed)
        self.parent = parent
        self.game = Game()
        self.resized_card_images = {}

        self.hidden_card = Card('', '', 'red_back', 0)
        self.add_card_image(self.hidden_card)

        self.play_button.place(rely=0.47, relx=0.46)
Пример #14
0
    def test_notTwoPair(self):
        ranks = [1, 2, 3, 4, 5]
        suits = ['d', 'c', 'h', 's']
        hand = Hand(
            [Card(suits[random.randint(0, 3)], ranks[i]) for i in range(5)])

        assert hand.isTwoPair() == False
Пример #15
0
def update(option: int, dfcard: DataFrame) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option, dfcard)
        if int(regcard.codeCard) > 0:
            regcard.nameCard = inform_name('Card')

            nameAnt = dfcard.Name
            dfcard['Name'].replace(to_replace=[nameAnt],
                                   value=regcard.nameCard,
                                   inplace=True)

            Card.updatedb(regcard)

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N}? ')
Пример #16
0
 def __init__(self, card: Card, sold_at_turn, seller_player_id,
              owner_player_id):
     self.card = card
     self.bought = False
     self.sold_at_turn = sold_at_turn
     self.seller_player_id = seller_player_id
     self.owner_player_id = owner_player_id
     self.card_data = card.get_default_card_data()
Пример #17
0
def delete(option: int, dfcard: DataFrame) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option, dfcard)
        if int(regcard.codeCard) > 0:
            resp = ' '
            while resp.upper() not in 'YN':
                resp = input(f'Confirm the delete the {regcard.codeCard} - '
                             f'{regcard.nameCard} [Y/N]? ')
            if resp.upper() == 'Y':
                dfcard = dfcard.drop(
                    dfcard[(dfcard.Code == regcard.codeCard)].index)

                Card.deletedb(regcard)

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N}? ')
Пример #18
0
def delete(option: int) -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        regcard: Card = validcard(option)
        if int(regcard.codeCard) > 0:
            countcodepouch = Pouch.countcodepouchcard(regcard.codeCard)

            if countcodepouch == 0:
                resp = ' '
                while resp.upper() not in 'YN':
                    resp = input(
                        f'Confirm the delete the {regcard.codeCard} - '
                        f'{regcard.nameCard} [Y/N]? ')
                    if resp.upper() == 'Y':
                        Card.deletedb(regcard)
            else:
                print(f'\33[1;31mHave Pouch registered\33[m')
        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N}? ')
Пример #19
0
def validcard(option: int) -> Card:
    regok: bool = False
    while not regok:
        regcard: Card = search_name_card()
        # the code informed is ok
        if int(regcard.codeCard) == 0:
            regcard: Card = Card(0, '')
            break
        if option == 1:  # INSERT
            if regcard.nameCard == '':
                # the card not exist
                regok = True
            else:
                print(f'\33[1;31mCard Code exist\33[m')
        else:  # UPDATE / DELETE
            if regcard.nameCard != '':
                # the card exist
                regok = True
            else:
                print(f'\33[1;31mCard Code not exist\33[m')
    return regcard
Пример #20
0
def insert() -> None:
    resp = 'Y'
    while resp.upper() == 'Y':
        code = input('Pouch Code (0 - exit): ').strip()

        if code == '0':
            return

        if code == '' or code is None:
            print('\33[1;31mPouch is empty\33[m')
            continue
        # verify if code pouch have only zeros
        if len(code) == code.count('0'):
            print('\33[1;31mPouch have only zeros\33[m')
            continue

        codePouchIN: str = code
        # check if codePouch exist
        codePouchOUT = Pouch.findcodepouch(codePouchIN)

        if codePouchOUT == '' or codePouchOUT == None:
            # the codePouch isn't exist
            regcard: Card = Card.validcard(0)  # SEARCH
            if int(regcard.codeCard) > 0:
                regsynd, regcomp = Company.validcompany(0)
                if int(regcomp.codeComp) > 0:
                    dtarrived = inform_date(False)
                    quant = inform_quant()
                    value = inform_value()
                    regpouch: Pouch = Pouch(codePouchIN, regcard.codeCard,
                                            regsynd.codeSynd, regcomp.codeComp,
                                            dtarrived, quant, value)
                    Pouch.insertdb(regpouch)
        else:
            print(f'\33[1;31mCode already exist\33[m')
            continue

        resp = ' '
        while resp.upper() not in 'YN':
            resp = input('Do you want continue [Y/N]? ')
Пример #21
0
 def __init__(self):
     self.deck = []
     for suit in suits:
         for rank, value in ranks.items():
             self.deck.append(Card(suit, rank, value[0], value[1]))
Пример #22
0
    def test_threeOfAKind(self):
        ranks = [1, 3, 3, 3, 5]
        suits = ['d', 'c', 'h', 's', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Three of a kind"
Пример #23
0
    def test_flush(self):
        ranks = [1, 2, 7, 11, 5]
        suits = ['d', 'd', 'd', 'd', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Flush"
Пример #24
0
def list():
    # List all cards
    Card.findall(self=object)
Пример #25
0
    def test_fullHouse(self):
        ranks = [1, 1, 1, 5, 5]
        suits = ['d', 'c', 'h', 's', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Full House"
Пример #26
0
    def test_fourOfAKind(self):
        ranks = [4, 4, 4, 4, 13]
        suits = ['d', 'c', 'h', 's', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Four of a kind"
Пример #27
0
    def test_straightFlush(self):
        ranks = [1, 2, 3, 4, 5]
        suits = ['d', 'd', 'd', 'd', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Straight flush"
Пример #28
0
    def test_royalFlush(self):
        ranks = [1, 10, 11, 12, 13]
        suits = ['d', 'd', 'd', 'd', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Royal flush"
Пример #29
0
    def test_highCard(self):
        ranks = [1, 2, 8, 4, 5]
        suits = ['d', 'c', 'h', 's', 'd']
        hand = Hand([Card(suits[i], ranks[i]) for i in range(5)])

        assert hand.valueAsText == "Highcard of A"
Пример #30
0
def list(dfcard: DataFrame):
    # List all cards
    Card.findall(dfcard)