added comments

This commit is contained in:
2025-11-06 19:40:47 +01:00
parent acd5fa7201
commit 8c3dbc8fcd

View File

@@ -8,9 +8,6 @@ class Game:
"""The Game class is the central coordinator, managing the flow of """The Game class is the central coordinator, managing the flow of
the entire round, from setup to payout.""" the entire round, from setup to payout."""
# TODO: - play_round() function
# - show_cards function
def __init__(self) -> None: def __init__(self) -> None:
"""Creates instances of 'Deck', 'Player', and 'Dealer'.""" """Creates instances of 'Deck', 'Player', and 'Dealer'."""
self.deck = Deck() self.deck = Deck()
@@ -93,6 +90,7 @@ class Game:
print("--Player Cards:--") print("--Player Cards:--")
for card in player_cards: for card in player_cards:
print(str(card)) print(str(card))
print(f"Hand value: {player_hand.value}") print(f"Hand value: {player_hand.value}")
def play_round(self) -> None: def play_round(self) -> None:
@@ -105,8 +103,8 @@ class Game:
player = self.player player = self.player
dealer = self.dealer dealer = self.dealer
# beginning of a round, shuffle deck and deal cards # Beginning of the round, the deck gets shuffled and all the
# player cards are shown, while the dealer only shows one card.
deck.shuffle() deck.shuffle()
player.hand.add_card(deck.deal_card()) player.hand.add_card(deck.deal_card())
@@ -115,6 +113,8 @@ class Game:
dealer.hand.add_card(deck.deal_card()) dealer.hand.add_card(deck.deal_card())
self.show_cards(hide_dealer=True) self.show_cards(hide_dealer=True)
# Player picks a card and adds it to his hand.
player_turn = True player_turn = True
while player_turn: while player_turn:
if input("Do you want another card? [y] ") == "y": if input("Do you want another card? [y] ") == "y":
@@ -125,13 +125,16 @@ class Game:
player.stand() player.stand()
player_turn = False player_turn = False
# self.show_cards() # Dealers turn and showing the cards of both player and dealer.
dealer.play(deck) dealer.play(deck)
self.show_cards() self.show_cards()
# Comparing hands and returning the winner of the game.
os.system("clear") os.system("clear")
print(self.compare_hands(0)) print(self.compare_hands(0))
# After each full round, the players and dealers hand get
# cleared and a new deck is created.
player.hand.__init__() player.hand.__init__()
dealer.hand.__init__() dealer.hand.__init__()
deck.__init__() deck.__init__()