示例#1
0
class TestPlayer(TestCase):
    def setUp(self):
        self.player1=Player("ori",DeckOfCards(),26)
        self.deck1=DeckOfCards

    def test_set_hand(self):
        self.player2=Player("snir",DeckOfCards(),30)
        self.player3=Player("roie",DeckOfCards(),0)
        self.player4=Player("itay",DeckOfCards(),-4)

        self.assertEqual(self.player2.pack,26)
        self.assertEqual(self.player3.pack,0)
        self.assertEqual(self.player4.pack,-4)


    def test_get_card(self):
        self.assertNotIn(self.player1.get_card(),self.player1.hand())

    def test_add_card(self):
        #self.add= self.player1.add_card(self)
        self.card =Card(10,4)
        yad = self.player1.hand.copy()
        self.player1.add_card(self.card)

        self.assertNotEqual(self.player1.hand,yad)

    def test_show(self):
        pass
class Card_Game:
    def __init__(self, player1, player2, pack=10):
        self.gameon = False
        self.deck = DeckOfCards()
        print(self.deck)
        self.player1 = Player(player1, self.deck, pack)
        print(self.player1)
        self.player2 = Player(player2, self.deck, pack)
        print(self.player2)
        self.new_game()

    def new_game(self):
        if self.gameon == True:
            return "error"

        self.deck.shuffle()
        self.player1.set_hand(10, self.deck)
        self.player2.set_hand(10, self.deck)
        self.gameon = True

    def get_winner(self):
        if len(self.player1.hand) < len(self.player2.hand):
            return self.player1
        if len(self.player2.hand) < len(self.player1.hand):
            return self.player2
        if self.player1 == self.player2:
            return
        else:
            return None
示例#3
0
    def test_set_hand(self):
        self.player2=Player("snir",DeckOfCards(),30)
        self.player3=Player("roie",DeckOfCards(),0)
        self.player4=Player("itay",DeckOfCards(),-4)

        self.assertEqual(self.player2.pack,26)
        self.assertEqual(self.player3.pack,0)
        self.assertEqual(self.player4.pack,-4)
 def __init__(self, player1, player2, pack=10):
     self.gameon = False
     self.deck = DeckOfCards()
     print(self.deck)
     self.player1 = Player(player1, self.deck, pack)
     print(self.player1)
     self.player2 = Player(player2, self.deck, pack)
     print(self.player2)
     self.new_game()
from games.cards.Class_Card_Game import Card_Game
from games.cards.Class_Player import Player

player1 = Player(input("player 1 name: "))
player2 = Player(input("player 2 name: "))
game1 = Card_Game(player1.name, player2.name)
print(game1.player1.show())
print(game1.player2.show())

for i in range(10):
    card1 = game1.player1.get_card()
    card2 = game1.player2.get_card()
    print(card1)
    print(card2)

    if card1 < card2:
        game1.player2.add_card(card1)
        game1.player2.add_card(card2)
        print(f"{player2.name} has won")
    else:
        card2 < card1
        game1.player1.add_card(card1)
        game1.player1.add_card(card2)
        print(f"{player1.name} has won")
 def setup(self):
     self.game1 = Card_Game("ori", "snir", 15)
     self.player1 = Player("ori",DeckOfCards,15)
     self.player2 = Player("snir",DeckOfCards,15)
 def test_get_winner(self):
     self.player1 = Player("ori", DeckOfCards, 15)
     self.player2 = Player("snir", DeckOfCards, 15)
     self.assertTrue(len(self.player1.hand) == len(self.player2.hand))
示例#8
0
 def setUp(self):
     self.player1=Player("ori",DeckOfCards(),26)
     self.deck1=DeckOfCards