changes to file structure + card game
This commit is contained in:
parent
26341b390f
commit
add4b42d12
@ -7,20 +7,26 @@ class Card:
|
|||||||
# Set colour as random between red and black
|
# Set colour as random between red and black
|
||||||
self.colour = choice(["red", "black"])
|
self.colour = choice(["red", "black"])
|
||||||
# Set suit depending on colour since a suit has an allocated colour
|
# 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"])
|
self.suit = choice(["hearts", "diamonds"]) if self.colour == "red" else choice(["clubs", "spades"])
|
||||||
# Set value
|
# Set value
|
||||||
self.value = choice(["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"])
|
self.value = choice(["Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"])
|
||||||
# Set whether the value is a face card or not
|
# Set whether the value is a face card or not
|
||||||
self.face = True if self.value in ["J", "Q", "K"] else False
|
self.face = True if self.value in ["Jack", "Queen", "King"] else False
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, number=None):
|
def __init__(self, number=None):
|
||||||
self.name = f"player{number}"
|
self.name = f"player-{number}"
|
||||||
self.cards = []
|
self.cards = []
|
||||||
|
# This is so each player can take cards until they are "done"
|
||||||
|
# Then the dealer can take his cards
|
||||||
|
self.done = False
|
||||||
|
|
||||||
def show_cards(self):
|
def show_cards(self, players):
|
||||||
pass
|
print(f"{self.name}'s cards:")
|
||||||
|
for card in self.cards:
|
||||||
|
print(f"> {card.value} of {card.suit}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
class Dealer(Player):
|
class Dealer(Player):
|
||||||
@ -28,19 +34,29 @@ class Dealer(Player):
|
|||||||
super().__init__(self)
|
super().__init__(self)
|
||||||
self.name = "dealer"
|
self.name = "dealer"
|
||||||
|
|
||||||
def show_cards(self):
|
def show_cards(self, players):
|
||||||
...
|
print(f"{self.name}'s cards:")
|
||||||
|
for player in players[1:]:
|
||||||
|
if player.done is False:
|
||||||
|
print(f"> {self.cards[0].value} of {self.cards[0].suit}")
|
||||||
|
for card in self.cards[1:]:
|
||||||
|
print(f"> HIDDEN")
|
||||||
|
print()
|
||||||
|
return
|
||||||
|
for card in self.cards:
|
||||||
|
print(f"> {card.value} of {card.suit}")
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.players = [Dealer()]
|
self.players = [Dealer()]
|
||||||
for player_num in range(1):
|
for player_num in range(1):
|
||||||
self.players.append(Player(player_num-1))
|
self.players.append(Player(player_num+1))
|
||||||
self.deal_cards()
|
self.deal_cards()
|
||||||
|
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
print(player.cards)
|
player.show_cards(self.players)
|
||||||
|
|
||||||
|
|
||||||
def deal_cards(self):
|
def deal_cards(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user