def startGame(): sourceDeck = Deck() sourceDeck.shuffleDeck() dealTo = 1 player1_cards = [] player2_cards = [] for cardIndex in range(0, len(sourceDeck.cards)): if dealTo == 1: nextCard = sourceDeck.drawCard() player1_cards.append(nextCard) dealTo = 2 elif dealTo == 2: nextCard = sourceDeck.drawCard() player2_cards.append(nextCard) dealTo = 1 player1_deck = Deck(cards=player1_cards) player1Name = input("What is the name of the first player? ") player1 = Player(player1Name, deck=player1_deck) player2_deck = Deck(cards=player2_cards) player2Name = input("What is the name of the second player? ") player2 = Player(player2Name, deck=player2_deck) print() print("Turn 1:") players = (player1, player2) return players
def main(): # Set up game variables, Create deck and player objects global winner deck = Deck() user = Player('Your') dealer = Player('Dealer') # Main game structure printTitle(hello) deal(deck, user, dealer) playerState(dealer) playerState(user) userTurn(deck, user) # Skip dealer turn if player hits blackjack or busts if winner == False: dealerTurn(deck, dealer) gameResult(user, dealer) # Reset global winner var winner = False
def startGame(): sourceDeck = Deck() player1Name = input("What is the name of the first player? ") player1 = Player(player1Name) player2Name = input("What is the name of the second player? ") player2 = Player(player2Name) sourceDeck.shuffleDeck() dealTo = 1 for card in sourceDeck.cards: if dealTo == 1: player1.deck.cards.append(sourceDeck.drawCard()) dealTo = 2 elif dealTo == 2: player1.deck.cards.append(sourceDeck.drawCard()) dealTo = 1 players = (player1, player2) return players
def __init__(self, name, deck=Deck([])): self.name = name self.deck = deck
def setUp(self): self.deck = Deck()
class DeckTests(unittest.TestCase): def setUp(self): self.deck = Deck() def test_init(self): self.assertEqual(len(self.deck.cards), 52) def test_repr(self): self.assertEqual(repr(self.deck), "Deck of 52 cards") def test_count(self): self.assertEqual(self.deck.count(), 52) self.deck.cards.pop() self.assertEqual(self.deck.count(), 51) def test_deal_sufficient(self): cards = self.deck._deal(10) self.assertEqual(len(cards), 10) self.assertEqual(self.deck.count(), 42) def test_deal_insufficient(self): cards = self.deck._deal(60) self.assertEqual(len(cards), 52) self.assertEqual(self.deck.count(), 0) def test_deal_empty(self): self.deck._deal(self.deck.count()) with self.assertRaises(ValueError): self.deck._deal(1) def test_deal_card(self): card = self.deck.cards[-1] dealt_card = self.deck.deal_card() self.assertEqual(card, dealt_card) self.assertEqual(self.deck.count(), 51) def test_deal_hand(self): cards = self.deck.deal_hand(20) self.assertEqual(len(cards), 20) self.assertEqual(self.deck.count(), 32) def test_shuffle_full(self): cards = self.deck.cards[:] self.deck.shuffle() self.assertNotEqual(cards, self.deck.cards) self.assertEqual(self.deck.count(), 52) def test_shuffle_not_full(self): self.deck._deal(1) with self.assertRaises(ValueError): self.deck.shuffle()
def __init__(self, name, deck=Deck("empty")): self.name = name self.deck = deck