Fixed passing 'players' list to other classes
This commit is contained in:
parent
c467e7b98c
commit
b0882de943
@ -23,7 +23,7 @@ class Player:
|
|||||||
# Then the dealer can take his cards
|
# Then the dealer can take his cards
|
||||||
self.done = False
|
self.done = False
|
||||||
|
|
||||||
def show_cards(self, players):
|
def show_cards(self):
|
||||||
print(f"{self.name}'s cards:")
|
print(f"{self.name}'s cards:")
|
||||||
for card in self.cards:
|
for card in self.cards:
|
||||||
print(f"> {card.value} of {card.suit}")
|
print(f"> {card.value} of {card.suit}")
|
||||||
@ -46,10 +46,9 @@ class Dealer(Player):
|
|||||||
super().__init__(self)
|
super().__init__(self)
|
||||||
self.name = "dealer"
|
self.name = "dealer"
|
||||||
|
|
||||||
def show_cards(self, players):
|
def show_cards(self, game):
|
||||||
print(f"{self.name}'s cards:")
|
print(f"{self.name}'s cards:")
|
||||||
for player in players[1:]:
|
if not game.players_are_done():
|
||||||
if player.done is False:
|
|
||||||
print(f"> {self.cards[0].value} of {self.cards[0].suit}")
|
print(f"> {self.cards[0].value} of {self.cards[0].suit}")
|
||||||
for card in self.cards[1:]:
|
for card in self.cards[1:]:
|
||||||
print(f"> HIDDEN")
|
print(f"> HIDDEN")
|
||||||
@ -72,14 +71,23 @@ class Game:
|
|||||||
def main_loop(self):
|
def main_loop(self):
|
||||||
system("cls" if os_name == "nt" else "clear")
|
system("cls" if os_name == "nt" else "clear")
|
||||||
|
|
||||||
for player in self.players:
|
self.overview()
|
||||||
player.show_cards(self.players)
|
|
||||||
|
|
||||||
def deal_cards(self):
|
def deal_cards(self):
|
||||||
for player in self.players:
|
for player in self.players:
|
||||||
for _ in range(2):
|
for _ in range(2):
|
||||||
player.cards.append(Card())
|
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__":
|
if __name__ == "__main__":
|
||||||
@ -87,7 +95,6 @@ if __name__ == "__main__":
|
|||||||
game.main_loop()
|
game.main_loop()
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - Fix the dealer being passed the players attribute
|
|
||||||
# - Win checking
|
# - Win checking
|
||||||
# - Player choice (hit, stand)
|
# - Player choice (hit, stand)
|
||||||
# - Dealers turn
|
# - Dealers turn
|
||||||
|
Loading…
Reference in New Issue
Block a user