Apr 16, 2025 | 1702 words | 17 min read
12.2.1. Code Breakers#
Introduction#
Create the game “Code Breakers”, which is a guessing game based on the game Mastermind created in the \(1970\)s. In this game, a random code will be generated by the computer which is between \(4\) and \(6\) characters long and only contains the digits \(0\) through \(5\) (inclusive). Similarly to Wordle, the player attempts to guess the hidden code and is given clues about how close to the correct code they are. After each guess, the program informs the player how many of the digits were of the correct value in the correct location, and how many digits were of the correct value but were in the wrong location. The game ends with a victory message if the player guesses the correct code within \(10\) guesses. Otherwise, the game ends with a defeat message.
At the start of your program, the player is presented some introductory text followed by a main menu from which they can choose between; \(1\). Rules to view the rules, \(2\). New Game to start a new game, \(3\). Load Game to load a saved game, or \(4\). Quit to exit the program. If the player enters an invalid choice, the program displays an appropriate error message and lets the player try again until a valid selection is made.
Note
Other than the function generate_solution
described below, you are free to
design your program however you like. You may use object-oriented programming techniques
but are not required to do so.
Sample Output#
Use the values in Table 12.1 below to test your program.
Case |
Inputs |
---|---|
1 |
Spam, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: Spam Please enter 1, 2, 3, or 4.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
1: Rules#
When the player chooses to view the rules, the program presents the rules as depicted below, and then returns to the main menu.
Sample Output#
Use the values in Table 12.2 below to test your program.
Case |
Inputs |
---|---|
1 |
1, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 1
Rules: -------------------------------------------------------------------------- 1. You get 10 guesses to break the lock.
2. Guess the correct code to win the game.
3. Codes can be either 4, 5, or 6 digits in length.
4. Codes can only contain digits 0, 1, 2, 3, 4, and 5.
5. Clues for each guess are given by a number of red and white pins.
5-a. The number of red pins in the R column indicates the number of digits in the correct location. 5-b. The number of white pins in the W column indicates the number of digits in the code, but in the wrong location. 5-c. Each digit of the solution code or guess is only counted once in the red or white pins.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
2: New Game#
After the player chooses to start a new game, the program must call a function
to produce the game’s solution code named generate_solution
. This
function takes two arguments, the code’s minimum length, and its maximum length,
and returns the solution code as a string. Even though the game will only need
codes with lengths of \(4\), \(5\), or \(6\) digits, this function
is able to generate codes of any length within the bounds of its arguments. Both
the length of the solution code, and the digits it contains (\(0\),
\(1\), \(2\), \(3\), \(4\), and/or \(5\)) are determined at
random. No other portion of your program will involve random chance.
Once the new solution code is generated, the player is given up to 10 chances to
guess the code. Before each guess, the game board, which tracks the status of
the game, should be displayed as shown in the examples below. The top row of the
board is for the solution. It is initially disguised as \(6\) o
’s
regardless of the solution’s length, and is revealed only when the game is
complete. The left side of the board tracks the player’s guesses. It has space
for guesses of up to 6 digits, and its rows are filled from the bottom up. Empty
spaces on the board are represented with the letter o
. The right side of the
board has columns labeled R
and W
. These are used to provide clues for
each guess according to rules that will be explained shortly.
Beneath the game board, the player is prompted to enter their next guess. The
player may enter either q
to quit the game, s
to save and quit, or
enter a valid guess of \(4\) to \(6\) characters containing only the
digits \(0\) through \(5\). Invalid guesses are not accepted and do not
count. If the player enters a guess that is the wrong length, or contains
invalid characters, they are prompted to try again.
Sample Output#
Use the values in Table 12.3 below to test your program.
Case |
Inputs |
---|---|
1 |
2, 123, 123123123, 4567, spam, q, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 123 Your guess was "123". Invalid guess type! Your guess is too short. Guess lengths must be between 4 and 6. What is your guess (q to quit, s to save and quit): 123123123 Your guess was "123123123". Invalid guess type! Guess lengths must be between 4 and 6. What is your guess (q to quit, s to save and quit): 4567 Your guess was "4567". Invalid guess type! The guess must be only numbers 0 through 5. What is your guess (q to quit, s to save and quit): spam Your guess was "spam". Invalid guess type! The guess must be only numbers! What is your guess (q to quit, s to save and quit): q Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Clues#
After the player inputs a valid guess, a clue is displayed on the right side of
the game board as a number of red pins (the R
column), and a number of white
pins (the W
column). The number of red pins indicates how many digits in the
guess are in the correct position and have the correct value. The number of
white pins indicates how many digits in the guess are in the solution code, but
are not in the correct position. Each digit of the solution code or guess can
only be counted once in the red or white pins.
For example, given the solution code \(550022\) and the guess \(153455\), the correct clue is \(1\) red pin and \(1\) white pin. The matching \(5\)s in the \(2\)nd position earn the red pin. Since only one other \(5\) remains in the code, only one white pin is assigned for the two \(5\)s at the end of the guess. Similarly, if the code contains more of a value than the guess, only as many of that value as are in the guess can contribute to the pin count. For example in the case of code \(550033\) and guess \(24311\) the \(3\) in the guess only earns one white pin even though the solution code contains two \(3\)s.
Sample Output#
Use the values in Table 12.4 below to test your program.
Case |
Inputs |
---|---|
1 |
2, 153455, q, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 153455 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): q Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Ending The Game#
The game ends when the player makes a correct guess or after their 10th
incorrect guess. In either case the game board is displayed one more time with
the solution code revealed in the top row. The game will also end if the player
enters q
to quit or s
to save and quit instead of a guess. After the
game ends, the player is returned to the main menu.
Sample Output#
Use the values in Table 12.5 below to test your program.
Case |
Inputs |
---|---|
1 |
2, 153455, 550022, 4 |
2 |
2, 153455, 012345, 543210, 111222, 123123, 112233, 554433, 543210, 551123, 550122, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 153455 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 550022 =+=================+====+= 5 5 0 0 2 2 | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 5 5 0 0 2 2 | 6 0 1 5 3 4 5 5 | 1 1 =+=================+====+= You did it! You got Timmy's book! Now Timmy can achieve his dreams of being a CS 15900 TA! ... Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Case 2 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 153455 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 012345 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 543210 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 111222 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 123123 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 112233 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 1 2 2 3 3 | 0 2 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 554433 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 5 5 4 4 3 3 | 2 0 1 1 2 2 3 3 | 0 2 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 543210 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 5 4 3 2 1 0 | 1 2 5 5 4 4 3 3 | 2 0 1 1 2 2 3 3 | 0 2 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 551123 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 5 5 1 1 2 3 | 3 0 5 4 3 2 1 0 | 1 2 5 5 4 4 3 3 | 2 0 1 1 2 2 3 3 | 0 2 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= What is your guess (q to quit, s to save and quit): 550122 =+=================+====+= 5 5 0 0 2 2 | R W =+=================+====+= 5 5 0 1 2 2 | 5 0 5 5 1 1 2 3 | 3 0 5 4 3 2 1 0 | 1 2 5 5 4 4 3 3 | 2 0 1 1 2 2 3 3 | 0 2 1 2 3 1 2 3 | 1 1 1 1 1 2 2 2 | 2 0 5 4 3 2 1 0 | 1 2 0 1 2 3 4 5 | 0 3 1 5 3 4 5 5 | 1 1 =+=================+====+= You hear a machine yell OUT OF TRIES! ... With your frustration at its limit, you tell Timmy you couldn't do it and IU steals the book. ... Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Saving#
When the player enters s
to save the game, the program displays a save game menu.
This menu allows the player to choose one of three save slots in which to save the game.
Each slot displays the name, date, and time of the last save to that slot. If a slot
has never been used, it displays empty
. The player selects a save slot by its number
(\(1\), \(2\), or \(3\)). If the player enters c
the save is cancelled,
they are returned to the active game. If the player enters an invalid choice, they are
prompted to try again. After selecting a valid save slot, the player is prompted to
enter their name. Names containing any characters other than letters, numbers, and
spaces are rejected, and the player is prompted to try again. Once a valid name is
entered, the game state is saved such that saved games are persistent between program
runs.
Hint
The date and time can be captured using Python’s datetime
module.
For example:
datetime.datetime.now().isoformat(timespec="seconds")
Sample Output#
Use the values in Table 12.6 below to test your program.
Case |
Inputs |
---|---|
1 |
2, 1232, s, c, q, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 1232 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 2 3 2 o o | 0 2 =+=================+====+= What is your guess (q to quit, s to save and quit): s
Files: -------------------------------------------------------------------------- 1: empty 2: Tim the Enchanter - Time: 2024-11-01T20:32:58 3: empty What save would you like to overwrite (1, 2, 3, or c to cancel): c cancelled =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 2 3 2 o o | 0 2 =+=================+====+= What is your guess (q to quit, s to save and quit): q Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Sample Output#
Use the values in Table 12.7 below to test your program.
Case |
Inputs |
---|---|
1 |
2, 1232, s, 4, spam, 3, $pam, King Arthur, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 2
New Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 =+=================+====+= What is your guess (q to quit, s to save and quit): 1232 =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 1 2 3 2 o o | 0 2 =+=================+====+= What is your guess (q to quit, s to save and quit): s
Files: -------------------------------------------------------------------------- 1: empty 2: Tim the Enchanter - Time: 2024-11-01T20:32:58 3: empty What save would you like to overwrite (1, 2, 3, or c to cancel): 4 Please pick a valid save file. What save would you like to overwrite (1, 2, 3, or c to cancel): spam Please pick a valid save file. What save would you like to overwrite (1, 2, 3, or c to cancel): 3 What is your name (no special characters): $pam That is an invalid name. What is your name (no special characters): King Arthur Game saved in slot 3 as King Arthur. Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
3: Loading#
The load game menu option takes the player to a menu similar to the save game menu. This
menu allows the player to choose to load a saved game from one of three save slots.
Typing c
in this menu takes the player back to the main menu. Other entries besides
1
, 2
, and 3
result in an error message and the player is prompted to choose again.
If the player chooses an empty slot, they are informed and prompted to try again. Once a
valid save slot is selected, the game is loaded, displaying the game board as it
appeared when saved. This game resumes with the same solution code and all previous
guesses and clues. Note that a new solution must NOT be generated when a game is loaded.
Sample Output#
Use the values in Table 12.8 below to test your program.
Case |
Inputs |
---|---|
1 |
3, c, q, 4 |
2 |
3, 4, 12, spam, 1, 3, q, 4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 3
Files: -------------------------------------------------------------------------- 1: empty 2: Tim the Enchanter - Time: 2024-11-01T20:32:58 3: King Arthur - Time: 2024-08-01T17:55:37 What save would you like to load (1, 2, 3, or c to cancel): c cancelled
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: q Please enter 1, 2, 3, or 4.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Case 2 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 3
Files: -------------------------------------------------------------------------- 1: empty 2: Tim the Enchanter - Time: 2024-11-01T20:32:58 3: King Arthur - Time: 2024-08-01T17:55:37 What save would you like to load (1, 2, 3, or c to cancel): 4 Please pick a valid save file. What save would you like to load (1, 2, 3, or c to cancel): 12 Please pick a valid save file. What save would you like to load (1, 2, 3, or c to cancel): spam Please pick a valid save file. What save would you like to load (1, 2, 3, or c to cancel): 1 That file is empty! What save would you like to load (1, 2, 3, or c to cancel): 3
Resume Game: -------------------------------------------------------------------------- =+=================+====+= o o o o o o | R W =+=================+====+= o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 o o o o o o | 0 0 5 2 3 1 o o | 1 3 =+=================+====+= What is your guess (q to quit, s to save and quit): q Ending Game.
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
4: Quitting#
The program should only end if the player chooses to quit from the main menu.
Sample Output#
Use the values in Table 12.9 below to test your program.
Case |
Inputs |
---|---|
1 |
4 |
Ensure your program’s output matches the provided samples exactly. This includes all characters, white space, and punctuation. In the samples, user input is highlighted like this for clarity, but your program should not highlight user input in this way.
Case 1 Sample Output
$ python3 final_project_login.py You were on your way home to Purdue when you received a text from your friend, Timmy. They seemed to have forgotten their favorite COMP 15200-C textbook in CBOB building. However, CBOB has recently added a new feature to thier doors... A PASWORD LOCK! OH NO! There's more... IU is trying to steal the sacred COMP 15200-C textbook. You need to guess the password before they find the textbook and return it Timmy!
Will you be able to break this lock before the sacred text is lost forever?
Menu: -------------------------------------------------------------------------- 1: Rules 2: New Game 3: Load Game 4: Quit Choice: 4 Goodbye
Deliverables#
Save your finished program as final_project_login.py
,
replacing login
with your Purdue login. Then submit it along with
all the deliverables listed in
Table 12.10 below.
Deliverable |
Description |
---|---|
|
Your finished program. |