Untitled Document
Untitled Document
", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+", "=", "/", ]
numPlayers = int(input("How many players will be playing? (No spaces, characters, or
alphabets) "))
if (numPlayers < 0):
numPlayers = int(input("Negative players cannot play this game. Please enter another
number. "))
if (numPlayers > 4):
numPlayers = int(input("More than 4 players cannot play this game. Please enter another
number. "))
if (numPlayers == 0):
numPlayers = int(input("0 players cannot play this game. Please enter another number. "))
if (numPlayers == 1):
numPlayers = int(input("You cannot play by yourself. Please enter another number. "))
red = "\033[31m"
black = "\033[30m"
import random
cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, "K", "Q", "J"]
suits = [(red + "♥" + black), (black + "♠" + black), (black + "♣" + black), (red + "♦" + black)]
class Card:
def __init__(self, suit, value):
self.suit = suit
self.value = value
if self.value == "K":
self.value = 13
elif self.value == "Q":
self.value = 12
elif self.value == "J":
self.value = 11
elif self.value == "A":
self.value = 14
else:
self.value = value
def __repr__(self):
if self.value == 1:
return("A" + str(self.suit))
else:
return(str(self.suit) + str(self.value))
# Deck contains all logic for game
class Deck:
def __init__(self):
self.deck_Of_Cards = []
# creates deck in a list with string in each index
def createDeck(self):
for s in suits:
for c in cards:
self.deck_Of_Cards.append(Card(s, c))
# gives 3 cards to each player on default
def deal(self, num_cards = 2, num_players = numPlayers):
self.players = [[]for i in range (num_players)]
random.shuffle(self.deck_Of_Cards)
for i in range(num_cards):
for x in range(num_players):
if(len(self.deck_Of_Cards)) != 0:
self.players[x].append(self.deck_Of_Cards.pop())
if(len(self.deck_Of_Cards) == 0):
break