Fixed passing 'players' list to other classes

This commit is contained in:
Evelyne 2023-04-25 14:10:18 +01:00
parent c467e7b98c
commit b0882de943

View File

@ -23,7 +23,7 @@ class Player:
# Then the dealer can take his cards
self.done = False
def show_cards(self, players):
def show_cards(self):
print(f"{self.name}'s cards:")
for card in self.cards:
print(f"> {card.value} of {card.suit}")
@ -46,10 +46,9 @@ class Dealer(Player):
super().__init__(self)
self.name = "dealer"
def show_cards(self, players):
def show_cards(self, game):
print(f"{self.name}'s cards:")
for player in players[1:]:
if player.done is False:
if not game.players_are_done():
print(f"> {self.cards[0].value} of {self.cards[0].suit}")
for card in self.cards[1:]:
print(f"> HIDDEN")
@ -72,14 +71,23 @@ class Game:
def main_loop(self):
system("cls" if os_name == "nt" else "clear")
for player in self.players:
player.show_cards(self.players)
self.overview()
def deal_cards(self):
for player in self.players:
for _ in range(2):
player.cards.append(Card())
def overview(self):
self.players[0].show_cards(self)
for player in self.players[1:]:
player.show_cards()
def players_are_done(self):
for player in self.players[1:]:
if not player.done:
return False
return True
if __name__ == "__main__":
@ -87,7 +95,6 @@ if __name__ == "__main__":
game.main_loop()
# TODO:
# - Fix the dealer being passed the players attribute
# - Win checking
# - Player choice (hit, stand)
# - Dealers turn