CollegeWork/OOP/Card Game/main.py

55 lines
1.3 KiB
Python

# Python OOP implementation of blackjack.
from random import choice
class Card:
def __init__(self):
# Set colour as random between red and black
self.colour = choice(["red", "black"])
# Set suit depending on colour since a suit has an allocated colour
self.suit = choice(["heart", "diamond"]) if self.colour == "red" else choice(["club", "spade"])
# Set value
self.value = choice(["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"])
# Set whether the value is a face card or not
self.face = True if self.value in ["J", "Q", "K"] else False
class Player:
def __init__(self, number=None):
self.name = f"player{number}"
self.cards = []
def show_cards(self):
pass
class Dealer(Player):
def __init__(self):
super().__init__(self)
self.name = "dealer"
def show_cards(self):
...
class Game:
def __init__(self):
self.players = [Dealer()]
for player_num in range(1):
self.players.append(Player(player_num-1))
self.deal_cards()
for player in self.players:
print(player.cards)
def deal_cards(self):
for player in self.players:
for _ in range(2):
player.cards.append(Card())
if __name__ == "__main__":
game = Game()