Esempio n. 1
0
    def take_human_turn(self):
        # This is where a player will select the number of dice they wish to use, roll them, and learn the result
        # of their play.
        eh = ErrorHandling()

        name = self.player_turn_player.player_name
        dice_amount_text = name + ", please select the number of dice you wish to use: "

        # TODO This should have an error handling range of 3-7.
        dice_amount = eh.range_integer_input_checking(dice_amount_text, 3, 7)

        self.roll_results(dice_amount, self.player_turn_player)
Esempio n. 2
0
 def merch_list_testing(self, merch_list):
     eh = ErrorHandling()
     if eh.nonblank_string(merch_list[0]) == False:
         failure_list = [False, "The type field must be filled."]
         return failure_list
     elif eh.float_check_range(merch_list[1], 0, float('inf')) == False:
         failure_list = [False, "The price field must be an number."]
         return failure_list
     elif eh.float_check_range(merch_list[2], 0, float('inf')) == False:
         failure_list = [False, "The unit cost must be a positive number."]
         return failure_list
     elif eh.range_integer_input_checking(merch_list[3], 0, float('inf')) == False:
         failure_list = [False, "The quanitity must be a positive number."]
         return failure_list
     else:
         success_list = [True, "All input fields have been entered correctly."]
         return success_list
Esempio n. 3
0
    def game_opening(self):

        eh = ErrorHandling()

        # This continues to run the game until the players quit.
        while True:
            game_continue = True

            # The players can choose to either read the rules of Press Your Bunco or else play the game.
            choice_text = (
                "\n1: Play Press Your Bunco. \n2: See the rules.\n3: See the all time winners list"
                "\nChoose an option: "
            )
            choice = eh.range_integer_input_checking(choice_text, 1, 3)
            if choice == 1:
                game_continue = self.game_start()
            elif choice == 2:
                self.press_your_bunco_rules()
            elif choice == 3:
                self.all_time_winner_list()

            if game_continue is False:
                break
Esempio n. 4
0
    def game_start(self):

        eh = ErrorHandling()

        human_players_input = "How many human players? "
        human_players = eh.range_integer_input_checking(human_players_input, 1, float("inf"))
        # human_players = eh.positive_integer_input_checking(human_players_input)

        counter = 0
        player_list = []

        # This adds the number of players to the player_list, creating a new instance of each player.
        while counter < human_players:
            name_text = "What is player " + str((counter + 1)) + "'s name? "
            name = eh.nonblank_string(name_text)
            p = Players(name, 0, 0, False)
            player_list.append(p)

            counter += 1

        computer_players_input = "How many computer players? "
        computer_players = eh.range_integer_input_checking(computer_players_input, 0, float("inf"))

        computer_count = 0

        while computer_count < computer_players:
            computer_player_name = "Computer Player " + str(computer_count + 1)
            p = Players(computer_player_name, 0, 0, True)
            player_list.append(p)
            computer_count += 1

        print("Let's play Press Your Bunco!")

        # This is where the game is played. First the board is set up. Then the game is played by people.
        game = GameBoard(player_list)
        return game.play_game()
Esempio n. 5
0
    def play_game(self):
        round_number = 1

        while round_number <= 6:

            round_won = False

            while round_won is False:

                # This is where the game turns actually happen. Turns happen in order until a player reaches 21 points.
                for player in self.players_list:
                    print("\nThis is round " + str(round_number))
                    print("Score: ")
                    for player_name in self.players_list:
                        print(player_name.player_name + ": " + str(player_name.points) + " points")
                    turn = PlayerTurn(player, round_number)

                    if player.is_comp is True:
                        turn.take_computer_turn(self.players_list)
                    elif player.is_comp is False:
                        turn.take_human_turn()

                    if player.points >= 21:
                        print(player.player_name + " wins the round!")
                        player.won_round()
                        round_won = True
                        break
            round_number += 1

            # resets the points after each round.
            for player in self.players_list:
                player.reset_points()

        dummy = Players("", -1, -1, True)
        winner_list = [dummy]

        # Once all six rounds have been played, this check determines who won.
        for player in self.players_list:
            check = winner_list[0]
            check_rounds = check.rounds
            player_rounds = player.rounds
            if player_rounds > check_rounds:
                winner_list.clear()
                winner_list.append(player)

            elif player_rounds == check_rounds:
                winner_list.append(player)

        if len(winner_list) == 1:
            verb_tense = " is"
        else:
            verb_tense = "s are"
        print("Your winner" + verb_tense + ": ")
        for winner in winner_list:
            print(winner.player_name)
        print("Congratulations!!!")

        # opens up the winners file to edit it to reflect the new winner.
        file = open('alltimewinners.txt', 'r')
        winners_dictionary = {}
        for line in file:
            print("Line test: " + line)
            line = line.strip("\n")
            line_list = line.split(" , ")
            winners_dictionary[line_list[0]] = line_list[1]

        file.close()
        file = open("alltimewinners.txt", "w")

        keys = winners_dictionary.keys()

        # adds the winner's name to the list of winners. If the winner has won before, increases their number of wins.
        for winner in winner_list:
            if winner.is_comp is True:
                winner_name = "Computer"
            else:
                winner_name = winner.player_name

            new = True
            for key in keys:
                if winner_name == key:
                    winners_dictionary[key] = str(int(winners_dictionary.get(key)) + 1)
                    new = False
                    break

            if new is True:
                winners_dictionary[winner_name] = 1

        winners_writing_list = []
        for key in winners_dictionary:
            winner_string = str(key) + " , " + str(winners_dictionary.get(key)) + "\n"
            winners_writing_list.append(winner_string)

        for line in winners_writing_list:
            file.write(line)

        file.close()

        # This allows the players to decide if they want to continue playing.
        # This is bounced back up to the gameStart in Main, which bounces it back up to game_opening to see if the
        # game will be replayed.
        eh = ErrorHandling()
        continue_choice_text = "\n1: Yes\n2: No\nWould you like to continue? "
        continue_choice = eh.range_integer_input_checking(continue_choice_text, 1, 2)

        if continue_choice == 1:
            return True
        elif continue_choice == 2:
            return False
Esempio n. 6
0
 def test_is_nonblank_string_is_true(self):
     self.assertTrue(eh.is_nonblank_string_truth_check(eh(), "test"), "test_is_nonblank_string_is_true failed")
Esempio n. 7
0
 def test_range_provided_truth_check_is_false(self):
     self.assertFalse(eh.range_provided_truth_check(eh(), 3, 0, 2), "test_range_provided_truth_check_is_true failed")
Esempio n. 8
0
 def test_is_nonblank_string_is_false(self):
     self.assertFalse(eh.is_nonblank_string_truth_check(eh(), ""), "test_is_nonblank_string_is_false failed")
Esempio n. 9
0
 def test_new_tour_date(self, new_date):
     eh = ErrorHandling()
     if eh.nonblank_string(new_date[0]) == False:
         failure_list = [False, "The address field must be filled."]
         return failure_list
     elif eh.nonblank_string(new_date[1]) == False:
         failure_list = [False, "The city field must be filled."]
         return failure_list
     elif eh.variable_length_checking(new_date[2], 2) == False:
         failure_list = [False, "The state field must be with a state abbreviation."]
         return failure_list
     elif eh.variable_length_checking(new_date[3], 5) == False:
         failure_list = [False, "The zip code field must be filled."]
         return failure_list
     elif eh.nonblank_string(new_date[4]) == False:
         failure_list = [False, "The venue field must be filled."]
         return failure_list
     elif eh.variable_length_checking(new_date[5], 10) == False:
         failure_list = [False, "The phone number field must be filled."]
         return failure_list
     elif eh.nonblank_string(new_date[6]) == False:
         failure_list = [False, "The date field must be filled."]
         return failure_list
     elif eh.range_integer_input_checking(new_date[7], 0, 99999) == False:
         failure_list = [False, "The capacity field must be filled."]
         return failure_list
     elif eh.float_check_range(new_date[8], 0, float('inf')) == False:
         failure_list = [False, "The cover charge field must be a positive integer."]
         return failure_list
     elif eh.float_check_range(new_date[9], 0, float('inf')) == False:
         failure_list = [False, "The door pay field must be filled."]
         return failure_list
     else:
         success_list = [True, "All input fields have been entered correctly."]
         return success_list