def test_players_cards_3( self): # test that negative number of cards will cause an error. try: testgame2 = cardgame(500, -5) except: pass else: self.fail()
def test_players_cards_4( self): # test that "str" amount of cards will cause an error. try: testgame2 = cardgame(500, "str") except: pass else: self.fail()
def test_players_cards_2( self): # test that zero cards will cause an error. try: testgame2 = cardgame(500, 0) except: pass else: self.fail()
def test_players_money_4( self): # test that when given "str" in money will cause an error. try: testgame2 = cardgame("str") except: pass else: self.fail()
def test_players_money_3( self ): # test that when given negative number of money will cause an error. try: testgame2 = cardgame(-500) except: pass else: self.fail()
from games.cards.cardgame import cardgame import random import time # creating a card game named: "war" war = cardgame((random.randint(5000,10000)),5) # all players start with the same amount of money, randomly from 5,000-10,000) # all players get 5 cards for player1 in war.playerslist: pp = war.playerslist.index(player1) + 1 player1.name = input("Enter Player "+str(pp)+" name:") if player1.name == "": # if the user enters an empty name for the player - the default will be - "player" plus the number of the player. player1.name = f'Player {pp}' print("=================================================") for pl in war.playerslist: print(pl) print("=================================================") time.sleep(3) for t in range (1,6): # the game has 5 rounds, one for each player's card. bank = 0 roundbet = 100*t # each round - the players are betting the amount of money from their hand, depanding on the number of the round. thisroundcards = [] # a list of the round's cards. for pl in war.playerslist: pl.reduceamount(roundbet) bank = bank + roundbet thisroundcards.append(pl.cardsinhand[0]) # moving the top card of each player to this round's cards list. # the following code lines refrences to the __gt__ function written in the "card" module. # deciding which card from this round's cards, is "stronger". max1 = 0 max2 = 0
def setUp(self): print("setUp:") self.testgame = cardgame(1000, 5) print("=================================================")
def test_players_money_2( self): # test that when given zero money, will work. testgame2 = cardgame(0) for player in testgame2.playerslist: self.assertTrue(player.money_amount == 0)