class Director: def __init__(self): self.keep_playing = True self.score = 300 self.dealer = Dealer() self.current_card = 0 def start_game(self): while self.keep_playing: #self.get_inputs() #self.do_updates() self.do_outputs() def get_inputs(self): self.dealer.deal_card() def do_updates(self): points = self.dealer.get_points() self.score += points def do_outputs(self): if len(self.dealer.cards) == 13: self.current_card = self.dealer.deal_card() print(f"The card is: {self.current_card}") if self.dealer.can_deal() and self.score != 0: choice = input("Higher or lower? [h/l] ") new_card = self.dealer.deal_card() if (choice == "h" and new_card > self.current_card) or (choice == "l" and new_card < self.current_card): self.score += 100 elif (choice == "h" and new_card < self.current_card) or (choice == "l" and new_card > self.current_card): self.score -= 75 else: print("That wasn't an option. You lose 200 points.") self.score -= 200 print(f"Next card was: {new_card}") print(f"Your score is: {self.score}") self.current_card = new_card play_more = input("Draw again? [y/n] ") self.keep_playing = (play_more == "y") else: self.keep_playing = False
class Director: """A code template for a person who directs the game. The responsibility of this class of objects is to keep track of the score and control the sequence of play. Attributes: keep_playing (boolean): Whether or not the player wants to keep playing. score (number): The total number of points earned. thrower (Thrower): An instance of the class of objects known as Thrower. """ def __init__(self): """The class constructor. Args: self (Director): an instance of Director. """ self.keep_playing = True self.score = 300 self.dealer = Dealer() def start_game(self): """Starts the game loop to control the sequence of play. Args: self (Director): an instance of Director. """ while self.keep_playing: self.get_inputs() self.do_updates() self.do_outputs() def get_inputs(self): """Gets the inputs at the beginning of each round of play. In this case, that means throwing the dice. Args: self (Director): An instance of Director. """ self.dealer.draw_card() def do_updates(self): """Updates the important game information for each round of play. In this case, that means updating the score. Args: self (Director): An instance of Director. """ print(f"\nThe card was: {self.dealer.card}") choice1 = input("Higher or lower? [h/l] ") points = self.dealer.get_points(choice1) self.score += points def do_outputs(self): """Outputs the important game information for each round of play. In this case, that means the dice that were rolled and the score. Args: self (Director): An instance of Director. """ print(f"Next card was: {self.dealer.card}") if (self.dealer.right_v_wrong): print(Fore.GREEN + f"Your score is: {self.score}" + Style.RESET_ALL) else: print(Fore.RED + f"Your score is: {self.score}" + Style.RESET_ALL) if self.dealer.can_shuffle(self.score): choice2 = input("Keep playing? [y/n] ") self.keep_playing = (choice2 == "y") else: print("Better luck next time!\n") self.keep_playing = False
class Director: # ********************** Will inizialite the game def __init__(self): """"Class Constructor: will inizialite a dictionary and the num_throws to count the amount of times he is going to throw it""" self.keep_playing = True self.guess = True self.dealer = Dealer() self.score = 300 # ********************** Start Game def start_game(self): """Starts the game loop to control the sequence of play. Args: self (Director): an instance of Director. """ while self.keep_playing: self.get_inputs() self.do_outputs() self.do_updates() # ********************** Get imputs def get_inputs(self): """Gets the inputs at the beginning of each round of play. In this case, that means throwing the cards. """ self.dealer.deal_cards() # ********************** do outputs def do_outputs(self): """Outputs the important game information for each round of play. In this case, that means the dealer will get a card and do the score """ print(f"\nThe Card is : {self.dealer.cards[0]}") self.dealer.guess() # ********************** Do updates def do_updates(self): """Updates the important game information for each round of play. In this case, that means updating the score. """ print(f"Next Card was : {self.dealer.cards[1]}") self.score = self.dealer.get_points() print(f"Your score is {self.score}") if self.dealer.can_deal(): choice = input("Keep playing? [y/n] ") if choice == "n": print("Thanks for playing have a nice day") self.keep_playing = (choice == "y") else: self.keep_playing = False print("You Lost but Thanks for Playing!!")