Esempio n. 1
0
 def start_play(self):
     points = 0
     self.the_pair = PairOfDice()
     text = input("Press enter to roll the dice...\n")
     if text == "":
         self.the_pair.roll_dice()
         first_roll = self.the_pair.current_value()
         if (first_roll == 2 or first_roll == 3 or first_roll == 12):
             print("You rolled", first_roll, ". You lose!")
         elif (first_roll == 7 or first_roll == 11):
             print("You rolled", first_roll, ". You win!")
         else:
             points = self.the_pair.current_value()
             print("Your point is", points)
             self.the_pair.roll_dice()
             next_roll = self.the_pair.current_value()
             while (next_roll != points or next_roll != 7):
                 text = input("Press enter to roll the dice...\n")
                 if text == "":
                     self.the_pair.roll_dice()
                     next_roll = self.the_pair.current_value()
                     if next_roll == points:
                         print("You rolled", next_roll, ". You win.")
                         break
                     elif next_roll == 7:
                         print("You rolled 7. You lose.")
                         break
                     else:
                         print("You rolled", next_roll, ".")
                 else:
                     print("Press enter to roll the dice...\n")
     else:
         print("Press enter to roll the dice...\n")
Esempio n. 2
0
class GameController:
    """A controller for a simple Street Craps game"""
    def __init__(self):
        ''' create the PairOfDice object '''
        self.PairOfDice = PairOfDice()

    def start_play(self):
        ''' start the play '''
        print(input("Press Enter to roll the dice...\n"))
        self.play()

    def play(self):
        ''' check if the player loses or wins in the first throw according
to game rules. If not, go to the repeat function '''
        die_sum = self.PairOfDice.current_value()

        if die_sum in (2, 3, 12):
            ''' the player loses if s/he throws 2, 3 or 12 in the first
turn '''
            self.do_busted(die_sum)

        elif die_sum in (7, 11):
            ''' the player wins if s/he throws 7 or 11 in the first
turn '''
            self.do_win(die_sum)

        else:
            self.repeat(die_sum)

    def do_busted(self, x):
        print("You rolled", x, ". You lose!")
        sys.exit()

    def do_win(self, x):
        print("You rolled", x, ". You win!")
        sys.exit()

    def repeat(self, die_sum):
        ''' check until the next throw shows the value equal to the
first point thrown or until 7 shows, which ever is first. If 7
player loses. '''
        point = die_sum
        print("Your point is : ", point)
        new_sum = 0

        while new_sum != point:
            if new_sum == 7:
                print("You rolled 7. You lose.")
                sys.exit()

            input("Press Enter to roll the dice...\n")
            new_sum = self.PairOfDice.current_value()
            print("You rolled :", new_sum)

        print("You win!")
        sys.exit()
Esempio n. 3
0
class GameController:
    '''A controller for a simple dice game'''
    def __init__(self):
        self.player_dice = PairOfDice()

    def start_game(self):
        '''interact with user, roll the pair of die and
        determine whether the user wins or not.
        None -> None'''

        input("Press enter to roll the dice...")
        self.player_dice.roll_dice()
        result = self.player_dice.current_value()
        if result == 7 or result == 11:
            print("You rolled " + str(result) + ". You win!")
        elif result == 2 or result == 3 or result == 12:
            print("You rolled " + str(result) + ". You lose.")
        else:
            done = False
            point = result
            while not done:
                print("Your point is " + str(point) + ".")
                input("Press enter to roll the dice...")
                self.player_dice.roll_dice()
                result = self.player_dice.current_value()
                if result == point:
                    print("You rolled " + str(result) + ". You win!")
                    done = True
                elif result == 7:
                    print("You rolled " + str(result) + ". You lose.")
                    done = True
Esempio n. 4
0
class GameController:
    def __init__(self):
        """creat a PairOfDice() object, initialize the point and score value"""
        self.pair = PairOfDice()
        self.point = None
        self.origin_point = None

    def start_play(self):
        """Start to play the game, roll the dice and get current value"""
        input("Please enter to roll the dice...\n")
        self.pair.roll_dice()
        self.point = self.pair.current_value()

    def show_result(self):
        """get the result based on the rules"""
        WIN_POINTS = [7, 11]
        LOSE_POINTS = [2, 3, 12]
        if self.point in LOSE_POINTS:
            print("You rolled {}. You lose.".format(self.point))
        elif self.point in WIN_POINTS:
            print("You rolled {}. You win.".format(self.point))
        else:
            print("You point is {}".format(self.point))
            self.origin_point = self.point
            self.continue_game()

    def continue_game(self):
        """didn't get the result, continue to play,
        compare the point with the origin_point"""
        LOSE_POINT = 7
        self.start_play()
        while self.point != self.origin_point and self.point != LOSE_POINT:
            print("You rolled {}.".format(self.point))
            self.start_play()
        else:
            if self.point == self.origin_point:
                print("You rolled {}. You win.".format(self.point))
            else:
                print("You rolled {}. You lose.".format(self.point))
Esempio n. 5
0
class GameController:
    """Manage the rolling, scoring, and user interaction"""
    def __init__(self):
        self.the_pair = PairOfDice()

    def start_play(self):
        points = 0
        self.the_pair = PairOfDice()
        text = input("Press enter to roll the dice...\n")
        if text == "":
            self.the_pair.roll_dice()
            first_roll = self.the_pair.current_value()
            if (first_roll == 2 or first_roll == 3 or first_roll == 12):
                print("You rolled", first_roll, ". You lose!")
            elif (first_roll == 7 or first_roll == 11):
                print("You rolled", first_roll, ". You win!")
            else:
                points = self.the_pair.current_value()
                print("Your point is", points)
                self.the_pair.roll_dice()
                next_roll = self.the_pair.current_value()
                while (next_roll != points or next_roll != 7):
                    text = input("Press enter to roll the dice...\n")
                    if text == "":
                        self.the_pair.roll_dice()
                        next_roll = self.the_pair.current_value()
                        if next_roll == points:
                            print("You rolled", next_roll, ". You win.")
                            break
                        elif next_roll == 7:
                            print("You rolled 7. You lose.")
                            break
                        else:
                            print("You rolled", next_roll, ".")
                    else:
                        print("Press enter to roll the dice...\n")
        else:
            print("Press enter to roll the dice...\n")
Esempio n. 6
0
class GameController:
    """"A controller for street craps game"""
    def __init__(self):
        self.dice = PairOfDice()
        self.first_value = 0

    def start_play(self):
        """Whole game process"""
        self.first_value = self.roll()
        self.first_rule(self.first_value)
        self.second_rule()

    def roll(self):
        """return rolled values"""
        input("Press enter to roll the dice...\n")
        value = self.dice.roll_dice()
        return value

    def first_rule(self, first_value):
        """Rule for first rolling value"""
        win_list = [7, 11]
        lose_list = [2, 3, 12]
        if first_value in win_list:
            print("You rolled {}. You win!".format(first_value))
            sys.exit()
        elif first_value in lose_list:
            print("You rolled {}. You lose.".format(first_value))
            sys.exit()
        else:
            print("Your point is", first_value)

    def second_rule(self):
        """Rules for later roll"""
        value = self.roll()
        while (value != self.first_value and value != 7):
            print("You rolled", value)
            value = self.roll()
        if value == self.first_value:
            print("You rolled {}. You win!".format(value))
        elif value == 7:
            print("You rolled 7. You lose.")
        sys.exit()
Esempio n. 7
0
 def start_play(self):
     pairofdice = PairOfDice()
     # If you roll 7 or 11 on your first roll, you win.
     if pairofdice.current_value() in FIRST_ROUND_WIN:
         print(f"You rolled {pairofdice.current_value()}. You win!")
     # If you roll 2, 3, or 12 on your first role, you lose.
     elif pairofdice.current_value() in FIRST_ROUND_LOSE:
         print(f"You rolled {pairofdice.current_value()}. You lose.")
     # If you roll anything else, that's your 'point', and
     # you keep rolling until you either roll your point
     # again (win) or roll a 7 (lose)
     else:
         point = pairofdice.current_value()
         print(f"Your point is {point}")
         input("Press enter to roll the dice...\n")
         pairofdice.roll_dice()
         while pairofdice.current_value() not in [point, LOSING_NUM]:
             print(f"You rolled {pairofdice.current_value()}.")
             input("Press enter to roll the dice...\n")
             pairofdice.roll_dice()
         if pairofdice.current_value() == point:
             print(f"You rolled {pairofdice.current_value()}. You win!")
         else:
             print(f"You rolled {pairofdice.current_value()}. You lose.")
Esempio n. 8
0
 def __init__(self):
     ''' create the PairOfDice object '''
     self.PairOfDice = PairOfDice()
Esempio n. 9
0
 def __init__(self):
     self.player_dice = PairOfDice()
Esempio n. 10
0
 def __init__(self):
     """creat a PairOfDice() object, initialize the point and score value"""
     self.pair = PairOfDice()
     self.point = None
     self.origin_point = None
Esempio n. 11
0
 def __init__(self):
     self.the_pair = PairOfDice()
Esempio n. 12
0
 def __init__(self):
     self.dice = PairOfDice()
     self.first_value = 0
Esempio n. 13
0
 def __init__(self):
     self.pair_of_dice = PairOfDice()
Esempio n. 14
0
class GameController:
    '''game controller for the dice game'''
    def __init__(self):
        self.pair_of_dice = PairOfDice()

    print("-------------------------")
    print("Welcome to street craps!")
    print("If you roll 7 or 11 on your first roll, you win.")
    print("If you roll 2, 3, or 12 on your first role, you lose.")
    print("If you roll anything else, that's your 'point', and")
    print("you keep rolling until you either roll your point")
    print("again (win) or roll a 7 (lose)")
    enter = input("Press enter to roll the dice...")

    def situations(self):
        WIN = [7, 11]
        LOSE = [2, 3, 12]
        SEVEN = 7
        # situation: win at the first time
        if (self.pair_of_dice.current_value() in WIN):
            print("You rolled",
                  str(self.pair_of_dice.current_value()) + ". You Win!")
        # situation: lose at the first time
        elif (self.pair_of_dice.current_value() in LOSE):
            print("You rolled",
                  str(self.pair_of_dice.current_value()) + ". You Lose.")
        # situation: roll until same point or magic num 7
        else:
            print("Your point is", self.pair_of_dice.current_value())
            point = self.pair_of_dice.current_value()
            self.pair_of_dice.roll_dice()
            while self.pair_of_dice.current_value() != point:
                enter = input("Press enter to roll the dice...")
                self.pair_of_dice.roll_dice()
                print("You rolled", self.pair_of_dice.current_value())
                if self.pair_of_dice.current_value() == SEVEN:
                    print(
                        "You rolled",
                        str(self.pair_of_dice.current_value()) + ". You Lose.")
                    break
            else:
                print("You rolled",
                      str(self.pair_of_dice.current_value()) + ". You Win!")
        # I will revisit this part to try to put win/lose/continue rolling
        # situations in three objects once I learned more OOD

    def start_play(self):
        self.pair_of_dice.roll_dice()
        self.situations()