class DieRollTest(unittest.TestCase):
    """Test the functionality of the Die class' roll function."""

    def setUp(self):
        self.possibleValues = [1, 2, 3, "Dog", "Cat", "Hippo"]
        self.new_die = Die(self.possibleValues)

    def tearDown(self):
        del self.possibleValues
        del self.new_die

    def test_roll_once(self):
        """Roll the die once and ensure the returned value is in possibleValues"""
        self.assertIn(self.new_die.roll(), self.possibleValues,
                      "Rolled value was not in possibleValues of Die")

    def test_rolled_value_changes(self):
        """Roll the die a number of times and make sure it changes value"""

        holding_value = self.new_die.roll()
        for i in range(10):
            if self.new_die.roll() != holding_value:
                self.assertTrue(True)
                return

        self.assertTrue(False, "Die Value did not change from Holding Value "
                               "for 10 rolls")

    def test_currentValue_is_updated_to_rolled_value(self):
        """Make sure that the Die's currentValue is updated to match what is rolled."""
        self.new_die.currentValue = 5
        self.assertEqual(self.new_die.roll(), self.new_die.currentValue,
                         "Current Value was not different from rolled")
Ejemplo n.º 2
0
    def __init__(self):
        """ Intializes the AngyDice class """

        self.die_a = Die(["1", "2", "ANGRY", "4", "5", "6"])
        self.die_b = Die(["1", "2", "ANGRY", "4", "5", "6"])
        self.stage = 1
        self.userInput = ""
        self.outcome = ""
        self.finalCheck = False  # breaks the main method upon a win
 def setUp(self):
     self.possibleValues = [1, 2, 3, "Dog", "Cat", "Hippo"]
     self.new_die = Die(self.possibleValues)
Ejemplo n.º 4
0
 def test_init(self):
   myDie = Die(["test1", "test2", "test3", "test4"])
   self.assertIn(str(myDie), ["test1", "test2", "test3", "test4"])
Ejemplo n.º 5
0
class Launch():
    """
  Launches the game of ANGRY dice
  """
    def __init__(self):
        self.level = 1
        self.userInput_list = []
        self.die_a = Die(["1", "2", "ANGRY", "4", "5", "6"])
        self.die_b = Die(["1", "2", "ANGRY", "4", "5", "6"])

    def instructions(self):
        print(
            "Welcome to Angry Dice! Roll the two dice until you get thru the 3 Stages!"
        )
        print("Stage 1 you need to roll 1 & 2")
        print("Stage 2 you need to roll ANGRY & 4")
        print("Stage 3 you need to roll 5 & 6")
        print("You can lock a die needed for your current stage and")
        print("just roll the other one, but beware!")
        print("If you ever get 2 ANGRY's at once, you have to restart")
        print("to Stage 1! Also, you can never lock a 6! That's cheating!")
        print("To roll the dice, simply input the name of the die")
        print("you want to roll. Their names are a and b.\n")
        input("Press ENTER to start!\n")

    def print_results(self):
        print("-------------------------------")
        print("You rolled:")
        print("a = [  {}  ]".format(self.die_a))
        print("b = [  {}  ]".format(self.die_b))
        self.user_input()

    def user_input(self):
        """
    Take the user input and allow for the user to stay or roll
    """
        if self.level == 4:
            exit()

        userInput = ""
        while "a" not in userInput or "b" not in userInput:
            userInput = input("\nDecision: ")
            self.userInput_list.append(userInput)

            if "a" in userInput and "b" in userInput:
                self.die_a.roll()
                self.die_b.roll()
                self.test_input(self.die_a, self.die_b)
                break
            elif "a" in userInput:
                self.die_a.roll()
                self.test_input(self.die_a, self.die_b)
                break
            elif "b" in userInput:
                self.die_b.roll()
                self.test_input(self.die_a, self.die_b)
                break
            else:
                print("I do not understand, try again: ")

        self.print_results()

    def test_input(self, a, b):
        """
    Test the userInput for each roll to determine the status of game
    """
        a = self.die_a.currentValue
        b = self.die_b.currentValue
        userInput = self.userInput_list[-1]  # test recent userInput

        # always test for a reset to level one
        if a == "ANGRY" and b == "ANGRY":
            print("\nWOW, you're ANGRY!")
            print("Time to go back to Stage 1!")
            self.level = 1
            return

        if self.level == 3 and (a == "6" or b == "6"):
            while (a == "6"
                   and "a" not in userInput) or (b == "6"
                                                 and "b" not in userInput):
                print(
                    "You're cheating! You cannot lock a 6! You cannot win until you reroll it!"
                )
                self.print_results()
        self.test_stage(self.level)

    def test_stage(self, level):
        """
    Determine the current stage of the user
    """
        a = self.die_a.currentValue
        b = self.die_b.currentValue

        if self.level == 1:
            self.stage_1(a, b)

        elif self.level == 2:
            self.stage_2(a, b)

        else:
            self.stage_3(a, b)

    def stage_1(self, a, b):
        a = self.die_a.currentValue
        b = self.die_b.currentValue

        print("\nStage 1!")
        if (a == "1" and b == "2") or (a == "2" and b == "1"):
            self.level = 2
            print("\nStage 2!")

    def stage_2(self, a, b):
        a = self.die_a.currentValue
        b = self.die_b.currentValue

        print("\nStage 2!")
        if (a == "ANGRY" and b == "4") or (a == "4" and b == "ANGRY"):
            self.level = 3
            print("\nStage 3!")

    def stage_3(self, a, b):
        a = self.die_a.currentValue
        b = self.die_b.currentValue

        print("\nStage 3!")
        if (a == "5" and b == "6") or (a == "6" and b == "5"):
            print("\nStage 3!")
            print("-------------------------------")
            print("-------------------------------")
            print("You've won! Calm down!")
            self.level = 4
Ejemplo n.º 6
0
 def __init__(self):
     self.level = 1
     self.userInput_list = []
     self.die_a = Die(["1", "2", "ANGRY", "4", "5", "6"])
     self.die_b = Die(["1", "2", "ANGRY", "4", "5", "6"])
Ejemplo n.º 7
0
class AngryDice:
    """ A program that lets a Single Player play Angry Dice """

    def __init__(self):
        """ Intializes the AngyDice class """

        self.die_a = Die(["1", "2", "ANGRY", "4", "5", "6"])
        self.die_b = Die(["1", "2", "ANGRY", "4", "5", "6"])
        self.stage = 1
        self.userInput = ""
        self.outcome = ""
        self.finalCheck = False  # breaks the main method upon a win

    def instructions(self):
        """ Output instructions for the user """

        text = "\nWelcome to Angry Dice! Roll the two dice until you get thru the 3 Stages!\n"
        text += "Stage 1 you need to roll 1 & 2\n"
        text += "Stage 2 you need to roll ANGRY & 4\n"
        text += "Stage 3 you need to roll 5 & 6\n"
        text += "You can lock a die needed for your current stage and\n"
        text += "just roll the other one, but beware!\n"
        text += "If you ever get 2 ANGRY's at once, you have to restart\n"
        text += "to Stage 1! Also, you can never lock a 6! That's cheating!\n"
        text += "To roll the dice, simply input the name of the die\n"
        text += "you want to roll. Their names are a and b.\n"
        print(text)
        input("Press ENTER to start! ") + "\n"

    def print_results(self):
        """ Output status of the game """

        print("\nYou are in Stage {}".format(self.stage))
        print("-------------------------------")
        print("You rolled:")
        print("a = [  {}  ]".format(self.die_a))
        print("b = [  {}  ]".format(self.die_b))
        print("{}".format(self.outcome))

    def main(self):
        """ Driving function for the entire game """

        self.instructions()
        self.print_results()

        # maintains the game flow until user wins depending on userInput
        while self.finalCheck == False:
            self.outcome = ""  # resets the outcome statement
            self.userInput = input("Roll dice: ") + "\n"
            self.check_userInput()
            self.check_stage()
            self.print_results()

    def check_userInput(self):
        """ Check the userInput and if the user is cheating. """

        a = self.die_a.currentValue
        b = self.die_b.currentValue
        invalid_userInput = True  # invalid input by the user

        # check if the user is cheating
        # call the is_cheating helper function
        is_cheating = self.cheating_status(a, b)

        # if a is input by the user
        if "a" in self.userInput and is_cheating == False:
            self.die_a.roll()
            invalid_userInput = False

        # if b is input by the user
        if "b" in self.userInput and is_cheating == False:
            self.die_b.roll()
            invalid_userInput = False

        # if a or b not rolled because of incorrect input by the user
        if invalid_userInput and is_cheating == False:
            self.outcome = "\nI do not understand, try again...\n"

    def cheating_status(self, a, b):
        """ Helper function check_userInput, cheating if level 3 currentValue 6 """

        if self.stage == 3 and (a == "6" or b == "6"):
            if (a == "6" and "a" not in self.userInput) or (b == "6" and "b" not in self.userInput):
                self.outcome = "\nYou're cheating! You cannot lock a 6!\n" "You cannot win until you re-roll it!\n"
                return True
        return False

    def check_stage(self):
        """ Determine the current stage of the user """

        a = self.die_a.currentValue
        b = self.die_b.currentValue

        # check for 2 Angrys, which resets to stage one
        if a == "ANGRY" and b == "ANGRY":
            self.stage = 1
            self.outcome = "\nWOW, you're ANGRY!\n" "Time to go back to Stage 1!\n"

        # if stage 1, call the stage_1 helper function
        if self.stage == 1:
            self.stage_1(a, b)

        # if stage 2, call the stage_2 helper function
        elif self.stage == 2:
            self.stage_2(a, b)

        # if stage 3, call the stage_3 helper function
        else:
            self.stage_3(a, b)

    def stage_1(self, a, b):
        """ Helper for check_stage: Logic for Stage 1 """

        a = self.die_a.currentValue
        b = self.die_b.currentValue

        if (a == "1" and b == "2") or (a == "2" and b == "1"):
            self.stage = 2
            self.outcome = "\n>>> Stage 1 completed!\n"

    def stage_2(self, a, b):
        """ Helper for check_stage: Logic for Stage 2 """

        a = self.die_a.currentValue
        b = self.die_b.currentValue

        if (a == "ANGRY" and b == "4") or (a == "4" and b == "ANGRY"):
            self.stage = 3
            self.outcome = "\n>>> Stage 2 completed!\n"

    def stage_3(self, a, b):
        """ Helper for check_stage: Logic for Stage 3 """

        a = self.die_a.currentValue
        b = self.die_b.currentValue

        if (a == "5" and b == "6") or (a == "6" and b == "5"):
            self.outcome = (
                "\n-------------------------------" "\n-------------------------------" "\nYou've won! Calm down!\n"
            )
            self.finalCheck = True