Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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:
        start_game: starts the game
        points: The total number of points earned.
        play_again: An instance of the class of objects known as Thrower.
        get_choice: See if they want to go high or low. 

    General Workflow:
        get_inputs
        do_updates
        do_outputs
    """
    def __init__(self):
        self.points = 0
        self.keep_playing = True
        self.user_H_L_choice = ""
        self.play_again = True
        self.get_choice = ""
        self.dealer = Dealer()
        self.highscore = Highscore()

    def start_game(self):
        """
        Starts the game loop
        """

        while self.keep_playing:
            self.get_inputs()
            self.do_updates()
            self.do_outputs()

    def get_inputs(self):
        """
        Prints and asks for the user input
        """
        self.dealer.draw_card()
        print(f"The card is {self.dealer.prev_card}")
        self.user_H_L_choice = input("Higher or Lower? [h/l] ")
        print(f"The next card was {self.dealer.current_card}")


    def do_updates(self):
        """
        This will adjust data based off of user's choices

        """
        if self.user_H_L_choice == self.dealer.determine_result():
            self.points += 100
        elif self.user_H_L_choice != self.dealer.determine_result():
            self.points -= 75
        else:
            self.points += 0

    def do_outputs(self):
        """
        Outputs the last bit of data, as well as some last minute proccessing
        """
        self.highscore.get_highscore()
        check_points = int(self.points)
        self.highscore.check_highscore(check_points)
        self.highscore.save_highscore
        if self.points <= 0:
            print('YOU LOSE')
            self.keep_playing == False
            quit()
        else:
            print(f'Points = {self.points}')
            self.get_choice = input("Keep Playing? [y/n] ")

            if self.get_choice == 'y':
                self.keep_playing == True
            elif self.get_choice == 'n':
                self.highscore.get_highscore()
                check_points = int(self.points)
                self.highscore.check_highscore(check_points)
                self.highscore.save_highscore()
                print(f'Your highscore was: {self.highscore.highscore}')
                self.keep_playing == False
                quit()