added game and Game()

This commit is contained in:
2025-10-26 22:00:11 +01:00
parent 86522ff189
commit 4a9b01582b

56
src/pyjack/game.py Normal file
View File

@@ -0,0 +1,56 @@
from pyjack import hand, player
from pyjack import dealer
from pyjack.dealer import Dealer
from pyjack.deck import Deck
from pyjack.player import Player
class Game:
"""The Game class is the central coordinator, managing the flow of
the entire round, from setup to payout."""
def __init__(self) -> None:
"""Creates instances of 'Deck', 'Player', and 'Dealer'."""
self.deck = Deck()
self.player = Player(0)
self.dealer = Dealer(1000)
def compare_hands(self, bet: int) -> str:
"""*Resolution/Payout*: Compares final hand values, checks for
Bust, Blackjack, and highest value.
*Updates* player.chips based on the outcome and the bet.
*Returns* the result string (e.g., "Player Wins!")."""
# HACK: this might work but certainly needs to be fixed.
# check if Player or Dealer busts
if self.player.hand.value > 21:
return "Player Lost"
elif self.dealer.hand.value > 21 and self.player.hand.value < 22:
self.player.chips += bet
return "Player Wins"
elif self.dealer.hand.value < 22 and self.player.hand.value < 22:
# Checks for Blackjack
if self.player.hand.value == 21 and self.dealer.hand.value != 21:
return "Player Wins 3:2"
else:
if self.dealer.hand.value == 21:
if self.player.hand.value == 21:
return "Tie"
else:
return "Player Lost"
# Checks the values if either the Player busts or has
# Blackjack
elif self.player.hand.value > self.dealer.hand.value:
return "Player Wins"
else:
if self.player.hand.value == self.dealer.hand.value:
return "Tie"
else:
return "Player Lost"
else:
return "Values could not be compared."