예제 #1
0
 def test_get_card(self):
     ben = Player("Ben", 2)
     ben.hand = [Card(1, 1), Card(2, 1)]
     c = ben.get_card()
     self.assertTrue(type(c) == Card)
     self.assertTrue(c == Card(1, 1) or c == Card(2, 1))
     after = ben.hand.copy()
     self.assertNotIn(c, after)
예제 #2
0
def get_cards_csv():
    with open(card_csv_path) as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        for row in csv_reader:
            card = Card(row[0], row[1], row[2], row[3], row[4], row[5], row[6],
                        row[7])
            cards.append(card)
    csv_file.close()
예제 #3
0
 def test_constructor(self):
     for s in range(1, 5):
         for v in range(1, 14):
             card = Card(v, s)
             if card not in self.d.deck:
                 self.assertTrue(False)
     else:
         self.assertTrue(True)
예제 #4
0
 def test_eq_notBetweenCards(self):
     c1 = Card(1, 2)
     c2 = "Card(1, 1)"
     try:
         c1 == c2
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #5
0
def get_cards_db(cards_db):
    global cards
    cards = []

    for card_db in cards_db:
        card = Card(card_db[1], card_db[2], card_db[3], card_db[4], card_db[5],
                    card_db[6], card_db[7], card_db[8])
        cards.append(card)
예제 #6
0
 def test_gt_notBetweenCards(self):
     c = Card(1, 1)
     b = "string"
     try:
         c > b
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #7
0
def edit_card(input_boxes):
    print("edition d'une carte")
    validated = validate_boxes(input_boxes)
    if validated == False:
        return False

    edited_card = Card(input_boxes[0].getInput(), input_boxes[1].getInput(),
                       input_boxes[2].getInput(), input_boxes[3].getInput(),
                       input_boxes[4].getInput(), input_boxes[5].getInput(),
                       input_boxes[6].getInput(), input_boxes[7].getInput())

    print(edited_card.get_name())

    n = find_card_index(edited_card.get_name())
    if n:
        cards[n] = edited_card
        edit_csv()

    return True
예제 #8
0
    def add_card_to_hand(deck, joueur, delete=False):
        card_from_hand_to_deck = random.choice(deck.get_cards_from_deck())
        card_to_add = Card(
            card_from_hand_to_deck[1], card_from_hand_to_deck[2],
            card_from_hand_to_deck[3], card_from_hand_to_deck[4],
            card_from_hand_to_deck[5], card_from_hand_to_deck[6],
            card_from_hand_to_deck[7], card_from_hand_to_deck[8])
        joueur.hand.append(card_to_add)

        if delete:
            deck.del_card_from_deck(card_from_hand_to_deck)
예제 #9
0
def generate_card(input_boxes):
    validated = validate_boxes(input_boxes)
    if validated == False:
        return False

    new_card = Card(input_boxes[0].getInput(), input_boxes[1].getInput(),
                    input_boxes[2].getInput(), input_boxes[3].getInput(),
                    input_boxes[4].getInput(), input_boxes[5].getInput(),
                    input_boxes[6].getInput(), input_boxes[7].getInput())
    cards.append(new_card)

    return True
예제 #10
0
 def test_invalid_suit(self):
     try:
         c = Card(6, "b")
         self.assertTrue(False)
     except TypeError:
         self.assertTrue(True)
예제 #11
0
 def test_invalid_value(self):
     try:
         c = Card("a", 3)
         self.assertTrue(False)
     except TypeError:
         self.assertTrue(True)
예제 #12
0
 def test_higher_suit_notInRange(self):
     try:
         c = Card(3, 5)
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #13
0
 def test_higher_value_notInRange(self):
     try:
         c = Card(14, 2)
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #14
0
 def test_lower_suit_notInRange(self):
     try:
         c = Card(1, 0)
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #15
0
 def test_lower_value_notInRange(self):
     try:
         c = Card(0, 1)
         self.assertTrue(False)
     except ValueError:
         self.assertTrue(True)
예제 #16
0
 def test_add_card(self):
     Eyal = Player("Eyal")
     Eyal.add_card(Card(3, 3))
     after = Eyal.hand.copy()
     self.assertIn(Card(3, 3), after)
예제 #17
0
 def test_higher_inRange(self):
     c = Card(13, 4)
     self.assertEqual(c.value, 13)
     self.assertEqual(c.suit, 4)
예제 #18
0
class TestPlayer(TestCase):

    # testing player's name with invalid type (isn't 'str')
    def test_invalid_name(self):
        try:
            p = Player(123)
            self.assertTrue(False)
        except TypeError:
            self.assertTrue(True)

# testing player's name with valid type ('str'), and that default cards_num is 10

    def test_valid_name(self):
        p = Player("Dor")
        self.assertTrue(p.name == "Dor")
        self.assertTrue(p.cards_num == 10)

# testing player's cards_num with invalid type (isn't 'int')

    def test_invalid_CardsNum(self):
        try:
            p = Player("Eyal", "string")
            self.assertTrue(False)
        except TypeError:
            self.assertTrue(True)

# testing player's low cards_num that not in range (less than 0)

    def test_low_CardsNum_notInRange(self):
        try:
            p = Player("Eyal", -1)
            self.assertTrue(False)
        except TypeError:
            self.assertTrue(True)

# testing player's high cards_num that not in range (if more than 26, it will be set to 26)

    def test_high_CardsNum_notInRange(self):
        p = Player("Eyal", 27)
        self.assertTrue(p.cards_num == 26)

# testing player's low cards_num that in range (0)

    def test_low_CardsNum_inRange(self):
        p = Player("Eyal", 0)
        self.assertTrue(p.cards_num == 0)

# testing player's high cards_num that in range (26)

    def test_high_CardsNum_inRange(self):
        p = Player("Eyal", 26)
        self.assertTrue(p.cards_num == 26)

# testing the hand after we get card.
# if the returned card isn't 'Card' the test will fail.
# if the card is in the hand after we get it, the test will fail.

    def test_get_card(self):
        ben = Player("Ben", 2)
        ben.hand = [Card(1, 1), Card(2, 1)]
        c = ben.get_card()
        self.assertTrue(type(c) == Card)
        self.assertTrue(c == Card(1, 1) or c == Card(2, 1))
        after = ben.hand.copy()
        self.assertNotIn(c, after)
        # if c not in after:
        #     self.assertTrue(True)
        # else:
        #     self.assertTrue(False)

# testing the hand after we add card.
# if the card is in the hand after we add it, the test will pass.

    def test_add_card(self):
        Eyal = Player("Eyal")
        Eyal.add_card(Card(3, 3))
        after = Eyal.hand.copy()
        self.assertIn(Card(3, 3), after)
        # if Card(3, 3) in after:
        #     self.assertTrue(True)
        # else:
        #     self.assertTrue(False)

#

    @mock.patch('Classes.DeckOfCards.DeckOfCards.deal_one',
                return_value=Card(1, 1))
    def test_set_hand(self, mock_deal_one):
        deck = DeckOfCards()
        guy = Player("Guy", 3)
        guy.set_hand(deck)
        self.assertIn(Card(1, 1), guy.hand)
        self.assertEqual(guy.hand.count(Card(1, 1)), 3)
예제 #19
0
 def test_gt_betweenCards_sameValue_false(self):
     c1 = Card(1, 1)
     c2 = Card(1, 2)
     self.assertFalse(c1 > c2)
예제 #20
0
 def test_gt_betweenCards_sameValue_true(self):
     c1 = Card(1, 2)
     c2 = Card(1, 1)
     self.assertTrue(c1 > c2)
예제 #21
0
 def test_lower_inRange(self):
     c = Card(1, 1)
     self.assertEqual(c.value, 1)
     self.assertEqual(c.suit, 1)
예제 #22
0
 def test_gt_betweenCards_notSameValue_false(self):
     c1 = Card(2, 1)
     c2 = Card(5, 1)
     self.assertFalse(c1 > c2)
예제 #23
0
 def test_set_hand(self, mock_deal_one):
     deck = DeckOfCards()
     guy = Player("Guy", 3)
     guy.set_hand(deck)
     self.assertIn(Card(1, 1), guy.hand)
     self.assertEqual(guy.hand.count(Card(1, 1)), 3)
예제 #24
0
def cards_list():
    continuer = True

    # begin of the loop
    n = 0
    # end of the loop
    m = 3

    # get_cards_csv()
    # for card in cards:
    #     print(card)

    test_cards = mysql_connexion.readCards()
    get_cards_db(test_cards)
    nb_cards = len(cards)

    while continuer:
        mx, my = pygame.mouse.get_pos()
        screen.fill((192, 192, 192))

        button_option_1 = pygame.Rect(20, 20, 100, 40)
        #pygame.draw.rect(screen, (0, 0, 0), button_option_1)
        #text_tools.draw_text('Retour', font_text, (255, 255, 255), screen, 35, 25)

        button_option_2 = pygame.Rect(20, 820, 150, 40)

        pygame.draw.rect(screen, (255, 0, 0), button_option_1)
        pygame.draw.rect(screen, (255, 0, 0), button_option_2)

        text_tools.draw_text('Retour', font_text, (0, 0, 0), screen, 35, 25)
        text_tools.draw_text('Créer carte', font_text, (0, 0, 0), screen, 35,
                             825)

        button_edit_1 = pygame.Rect(150, 720, 100, 40)
        button_delete_1 = pygame.Rect(270, 720, 140, 40)
        button_edit_2 = pygame.Rect(500, 720, 100, 40)
        button_delete_2 = pygame.Rect(620, 720, 140, 40)
        button_edit_3 = pygame.Rect(850, 720, 100, 40)
        button_delete_3 = pygame.Rect(970, 720, 140, 40)

        #
        # add_buttons(screen, button_edit_1, button_delete_1, 110)
        # add_buttons(screen, button_edit_2, button_delete_2, 460)
        # add_buttons(screen, button_edit_3, button_delete_3, 810)

        #cards = mysql_connexion.readCards()
        #nb_cards = len(cards)

        fond_carte_po = pygame.image.load(
            "ressources/fonds de cartes/fond_carte_13.png").convert_alpha()
        fond_carte_pm = pygame.image.load(
            "ressources/fonds de cartes/fond_carte_11.png").convert_alpha()
        fond_carte_pa = pygame.image.load(
            "ressources/fonds de cartes/fond_carte_09.png").convert_alpha()

        left_arrow = pygame.image.load(
            "ressources/images/left arrow.png").convert_alpha()
        left_arrow_small = pygame.transform.scale(left_arrow, (50, 50))
        button_left_arrow = pygame.Rect(5, 430, 50, 50)
        pygame.draw.rect(screen, (192, 192, 192), button_left_arrow)

        right_arrow = pygame.image.load(
            "ressources/images/right arrow.png").convert_alpha()
        right_arrow_small = pygame.transform.scale(right_arrow, (50, 50))
        button_right_arrow = pygame.Rect(1225, 430, 50, 50)
        pygame.draw.rect(screen, (192, 192, 192), button_right_arrow)

        x = 110
        y = 200

        # On veut afficher juste 3 cartes à la fois
        for card in cards[n:m]:

            add_buttons(screen, button_edit_1, button_delete_1, 110)
            if len(cards) > n + 1:
                add_buttons(screen, button_edit_2, button_delete_2, 460)
            if len(cards) > n + 2:
                add_buttons(screen, button_edit_3, button_delete_3, 810)

            # card_set[card[0]] = pygame.Rect(x, y, 340, 474)
            # pygame.draw.rect(screen, (192, 192, 192), card_set[card[0]])

            if card.get_ressource_type() == "PO":
                screen.blit(fond_carte_po, (x, y))
            elif card.get_ressource_type() == "PM":
                screen.blit(fond_carte_pm, (x, y))
            elif card.get_ressource_type() == "PA":
                screen.blit(fond_carte_pa, (x, y))

            if n > 0:
                screen.blit(left_arrow_small, (5, 430))
            if nb_cards > n + 3:
                screen.blit(right_arrow_small, (1225, 430))

            text_tools.draw_text(card.get_name(), font_text, (0, 0, 0), screen,
                                 x + 50, y + 20)
            text_tools.draw_text(
                'Cost : ' + str(card.get_cost()) + ' ' +
                card.get_ressource_type(), font_text, (0, 0, 0), screen,
                x + 50, y + 100)
            text_tools.draw_text(
                'Effect : ' + str(card.get_value()) + ' ' + card.get_target() +
                ' ' + card.get_effect(), font_text, (0, 0, 0), screen, x + 50,
                y + 125)
            text_tools.draw_text('Rarity : ' + card.get_rarity(), font_text,
                                 (0, 0, 0), screen, x + 50, y + 150)
            y2 = 400
            for line in break_text(card.get_description()):
                text_tools.draw_text(line, font_text, (0, 0, 0), screen,
                                     x + 50, y2)
                y2 = y2 + 25

            x += 350

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    continuer = False
            if event.type == MOUSEBUTTONDOWN:
                if button_option_1.collidepoint(mx, my) and event.button == 1:
                    continuer = False
                if button_option_2.collidepoint(mx, my) and event.button == 1:
                    new_card = Card('', '', '', '', '', '', '', '')
                    create_card(new_card, "create")

                if button_left_arrow.collidepoint(
                        mx, my) and event.button == 1 and n > 0:
                    n = n - 3
                    m = m - 3
                elif button_right_arrow.collidepoint(
                        mx, my) and event.button == 1 and nb_cards > n + 3:
                    n = n + 3
                    m = m + 3
                if button_edit_1.collidepoint(mx, my) and event.button == 1:
                    create_card(cards[n], "edit")
                if button_edit_2.collidepoint(mx, my) and event.button == 1:
                    create_card(cards[n + 1], "edit")
                if button_edit_3.collidepoint(mx, my) and event.button == 1:
                    create_card(cards[n + 2], "edit")
                if button_delete_1.collidepoint(mx, my) and event.button == 1:
                    delete_card(cards[n])
                if button_delete_2.collidepoint(mx, my) and event.button == 1:
                    delete_card(cards[n + 1])
                if button_delete_3.collidepoint(mx, my) and event.button == 1:
                    delete_card(cards[n + 2])

        pygame.display.update()
예제 #25
0
 def test_gt_betweenCards_notSameValue_true(self):
     c1 = Card(3, 1)
     c2 = Card(2, 1)
     self.assertTrue(c1 > c2)
예제 #26
0
 def test_eq_betweenCards_true(self):
     c1 = Card(1, 1)
     c2 = Card(1, 1)
     self.assertTrue(c1 == c2)
예제 #27
0
 def test_ace_VS_king(self):
     c1 = Card(1, 1)
     c2 = Card(13, 1)
     self.assertTrue(c1 > c2)
예제 #28
0
 def test_eq_betweenCards_false_value(self):
     c1 = Card(5, 1)
     c2 = Card(1, 1)
     self.assertFalse(c1 == c2)
예제 #29
0
 def __init__(self):
     self.deck = []
     for s in range(1, 5):
         for v in range(1, 14):
             card = Card(v, s)
             self.deck.append(card)
예제 #30
0
 def test_eq_betweenCards_false_suit(self):
     c1 = Card(1, 2)
     c2 = Card(1, 1)
     self.assertFalse(c1 == c2)