made it functional

This commit is contained in:
2025-10-29 21:01:03 +01:00
parent a4cdd72ac9
commit 197572567a
3 changed files with 66 additions and 8 deletions

View File

@@ -1,4 +1,3 @@
import re
from pyjack.dealer import Dealer
from pyjack.deck import Deck
from pyjack.player import Player
@@ -65,18 +64,70 @@ class Game:
second card is shown or concealed."""
player_cards = self.player.hand.cards
player_hand = self.player.hand
dealer_cards = self.dealer.hand.cards
dealer_hand = self.dealer.hand
print("--Player Cards:--")
for card in player_cards:
print(str(card))
print(f"Hand value: {player_hand.value}")
if hide_dealer:
card = dealer_cards[0]
print("--Dealer Cards:--")
print(str(card))
print("XXXX")
print("XXXX\n")
else:
print("--Dealer Cards:--")
for card in dealer_cards:
print(str(card))
print(f"Hand value: {dealer_hand.value}\n")
def show_player_cards(self) -> None:
"""Displays the players hand"""
player_cards = self.player.hand.cards
player_hand = self.player.hand
print("--Player Cards:--")
for card in player_cards:
print(str(card))
print(f"Hand value: {player_hand.value}")
def play_round(self) -> None:
"""Logic of a game round"""
# Simplify value calls:
deck = self.deck
player = self.player
dealer = self.dealer
# beginning of a round, shuffle deck and deal cards
deck.shuffle()
player.hand.add_card(deck.deal_card())
player.hand.add_card(deck.deal_card())
dealer.hand.add_card(deck.deal_card())
dealer.hand.add_card(deck.deal_card())
self.show_cards(hide_dealer=True)
player_turn = True
while player_turn:
if input("Do you want another card? [y] ") == "y":
player.hit(deck)
self.show_player_cards()
else:
print("\n")
player.stand()
player_turn = False
# self.show_cards()
dealer.play(deck)
self.show_cards()
print(self.compare_hands(0))
player.hand.clear_hand()
dealer.hand.clear_hand()

View File

@@ -32,3 +32,7 @@ class Hand:
if self.value > 21 and self.aces > 0:
self.value -= 10
self.aces -= 1
def clear_hand(self) -> None:
"""Clears the hand"""
self.cards = []

View File

@@ -1,9 +1,12 @@
from pyjack.player import Player
from pyjack.dealer import Dealer
from pyjack.card import Card
from pyjack.hand import Hand
from pyjack.deck import Deck
import os
from pyjack.game import Game
if __name__ == "__main__":
print("Hello World!")
os.system("clear")
print("pyjack by cerberus")
print("do you wanna play a round??")
game = Game()
game.play_round()