def test_no_name_input(self): """בודקת האם המשחק עובד כאשר לא מזינים בכלל פרטים. לא כמות קלפים לחלוקה ולא שמות שחקנים""" self.game_test = CardGame() self.assertEqual(self.game_test.player_1.name, "player-1") self.assertEqual(self.game_test.player_2.name, "player-2") self.assertEqual(self.game_test.player_1.num_cards, 10) self.assertEqual(self.game_test.player_2.num_cards, 10)
def test_new_game_deck_not_full(self): """checks the function wont start a new game if the deck is not full""" cardgame = CardGame('ohad', 'polly') self.assertEqual(len(cardgame.player1.player_hand), 10) self.assertEqual(len(cardgame.player2.player_hand), 10) self.assertEqual(len(cardgame.deck.list_cards), 32) cardgame.new_game() self.assertNotEqual(len(cardgame.deck.list_cards), 52)
def test_get_winner_draw(self): """checks if the result is draw""" player1 = Player("ohad") player2 = Player("polly") game = CardGame(player1.name, player2.name) game.player2.player_hand = [Card(8, 3), Card(9, 4), Card(13, 4)] game.player1.player_hand = [Card(7, 3), Card(10, 4), Card(12, 4)] winner = game.get_winner() self.assertEqual(None, winner)
def test_get_winner_player1_win(self): """checks thw winner is player 1""" player1 = Player("ohad") player2 = Player("polly") game = CardGame(player1.name, player2.name) game.player2.player_hand = [Card(8, 3), Card(9, 4), Card(13, 4)] game.player1.player_hand = [Card(7, 3)] winner = game.get_winner() self.assertEqual(player1.name, winner)
def test_num_cards_not_int(self): """בודקת שהמערכת מציגה שגיאה כאשר כמות הקלפים לחלוקה אינו מספר תקין""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", "bdika")
def test_new_game_30(self): """בודקת מה קורה אם הזנו מעל 26 קלפים לכל אחד""" self.game_test = CardGame("dima", "shachar", 30) self.assertEqual(len(self.game_test.player_1.player_deck), 26)
def setUp(self): self.game_test = CardGame("dima", "shachar")
def test_new_game_minus(self): """בודקת שמחזירה שגיאה כאשר מספר הקלפים לחלוקה הוא מינוס""" with self.assertRaises(SystemExit): self.game_test = CardGame("dima", "shachar", -5)
def test_new_game_20(self): """בודקת שבאמת מחלקת את כמות הקלפים שהמשתמש ביקש""" self.game_test = CardGame("dima", "shachar", 20) self.assertEqual(len(self.game_test.player_1.player_deck), 20) self.assertEqual(len(self.game_test.player_2.player_deck), 20)
def test_new_game_checking(self): """checking the function is really gives cards to the players""" cg = CardGame('ohad', 'polly') self.assertEqual(len(cg.player1.player_hand), 10) self.assertEqual(len(cg.player2.player_hand), 10)
def test_card_num__init__(self): """checks card number will be 10 as default""" cg = CardGame("aa", "bb") self.assertEqual(cg.num_cards, 10)
from games_cards.CardGame import CardGame play1 = CardGame("dima", "shachar") print(play1.player_1.show()) print(play1.player_2.show()) print("=====================") count = 0 for i in range(1, 11): count += 1 # count בודקת לנו האם המשחק רץ לפחות סיבוב אחד print(f"round {i}!!!") card1 = play1.player_1.get_card() # שולפת קלף משחקן ראשון print(f"card of {play1.player_1.name}: {card1}") card2 = play1.player_2.get_card() # שולפת קלף משחקן שני print(f"card of {play1.player_2.name}: {card2}") if card1 > card2: # בודקת מי המנצח בסיבוב הנוכחי play1.player_2.add_card(card1) play1.player_2.add_card(card2) print(f"the winner is {play1.player_1.name}") else: play1.player_1.add_card(card1) play1.player_1.add_card(card2) print(f"the winner is {play1.player_2.name}") print(play1.player_1.show()) print(play1.player_2.show()) print("=====================") if len(play1.player_1.player_deck) == 0 or len( play1.player_2.player_deck) == 0: # אם לאחד מהשחקנים נגמר הקלפים המשחק נגמר והוא המנצח print("\ngame over") break
from games_cards.DeckOfCards import DeckOfCards from games_cards.Player import Player from games_cards.CardGame import CardGame # d = DeckOfCards() # my_game = CardGame(5) # my_game.new_game() # print(my_game) # for i in range(5): # for player in my_game.players: # player.reduce_amount(100 * i) # pack = [] # suits = ["Diamond", "Spade", "Heart", "Club"] # for suit in suits: # for num in range(1, 14): # c = Card(num, suit) # pack.append(c) # # print(pack) # # p = pack[1] # print(p.value) my_game = CardGame(5) my_game.new_game_n() for i in range(1, 5): my_game.game_move(i) print(f"the whiner are- {my_game.win()[0]} with {my_game.win()[1]} dollars")
def setUp(self): print("Set_up") self.my_game = CardGame(5) self.my_game.new_game_n()
from games_cards.CardGame import CardGame from games_cards.Player import Player player1 = Player(input("enter player 1 name,(name must be letters only): ")) player2 = Player(input("enter player 2 name,(name must be letters only): ")) game = CardGame(player1.name, player2.name) print(game.player1.show()) print(game.player2.show()) for i in range(10): print(f"Round {i+1}") a = (game.player1.get_card()) b = (game.player2.get_card()) print(a) print(b) if a > b: game.player2.add_card(b) game.player2.add_card(a) print(f"the winner is {player1.name}") if a < b: game.player1.add_card(b) game.player1.add_card(a) print(f"the winner is {player2.name}") print(f" The winner of the game is : {game.get_winner()}")