代写猜词游戏Guessing Game.
OBJECTIVE
Utilize strings, lists and files to create a guessing game.
THE GAME
The program will read a sequence of strings representing picture cards from a
file. Each line of the file represents a picture card and each picture card is
represented by a color followed by an item, such as red box or blue dog. The
game starts by presenting the user with a menu of guesses, where the guesses
are a combination of all of the colors and items read from the file. The
computer will randomly choose a picture card from all the input values and the
user will be given 3 tries to guess the picture card by selecting a guess from
the menu. The user may play this game repeatedly in rounds if they wish, and a
score evaluating their guessing ability will be output when the game is
finished.
THE PROGRAM
Input File Format
Each line of the input file containing all of the picture cards will represent
one picture card. Each line will be formatted so that it consists of two
components and each component is 10 characters in length. The first component
of the string will be a color and the second component will be an item. If the
color or item is not 10 characters in length, the remainder of the string will
be padded with blanks to fill it out to the 10-character length. Be sure when
creating your test input files that you intentionally fill the blank padding
spaces by hitting the space bar on the keyboard. So for instance, the sequence
blue dog would consist of the word blue followed by 6 blank spaces followed by
the word dog followed by 7 blank spaces.
Initializations and Set-up
The program first asks the user if they want to run the program in Play Mode
(enter a P or p) or Test Mode (enter a T or t) and should re-prompt until a
valid value is entered. Test mode will output additional information that will
allow the validity of the game to be tested, but will make the game far less
fun to play, since the user will be seeing the answers. The information that
will be output in Test Mode is described below.
The program will then prompt the user for the name of the file containing the
picture cards. You may assume a well-behaved user who will enter a valid file
name. The program will then read in and save the cards from the file into a
list guess_deck. Two other lists should also be formed. The first,
colors_list, will contain all the colors that are encountered in the picture
cards. There should be no duplicates in this list. So, for example, if the
file contains a picture card yellow house and a picture card yellow bird,
yellow should only appear in the colors_list once. The second list,
items_list, should likewise contain one copy of every item contained in the
picture card file. So, for example, if blue house and yellow house are in the
picture card file, house should only appear in items_list once.
Your program will then construct the menu_list, which will be used to display
the guess choices for the user. For guessing purposes, the user will be
presented with a numbered menu containing all the combinations of all colors
and items that were contained in the file. The values in this menu will be
held in menu_list, as the program should not repeatedly do the work of
generating all of these combinations. The menu_list is formed by taking each
item in turn from colors_list and pairing it with each item in the items_list.
For example, if the original picture cards in the file were red box and blue
dog, the following menu of choices should be displayed (from menu_list) for
the user:
1: red box
2: red dog
3: blue box
4: blue dog
Finally, the user will be prompted to enter the number of rounds that they
want to play the game. Your program should make sure that a number greater
than or equal to 1 is entered and re-prompt the user if it is not (you may
assume an integer is entered).
Playing the Game
The game then begins and each round has the following format:
- The program randomly selects and removes a card from the guess_deck and the object of the game is for the user to correctly guess the picture on that card.
- The user is then presented with a numbered menu of choices (from menu_list) and asked to make a selection. Your program will re-prompt the user until the user enters a number that is a valid selection. The user is given 3 tries to guess the card correctly. If they have not guessed the card correctly in 3 tries, the card is displayed with an appropriate message and they earn no points. If the user guesses correctly before they have used all 3 tries, they will receive points. The program will give the user 3 points if they guess correctly on the first try, 2 points on the second try, 1 point on the third try and no points if they do not guess the card in 3 tries. If the user guesses correctly, the card is displayed, along with a message indicating that they guessed correctly and the number of points earned on this card. (It should be noted that the points earned should be calculated in a general manner, so that if the game is changed to allow the user 10 tries to guess the card, the user would be awarded 10 points if they guess correctly on the first try, 9 points on the second try etc. This change should only involve changing the number of tries, which should cause all other changes to happen automatically).
- The picture card is then randomly inserted back into guess_deck.
- The process of choosing a card, displaying the guess menu, processing the guesses and re-inserting the card into guess_deck continues for as many rounds as the user indicated they wanted to play the game. After all of the rounds are complete, the number of cards drawn, the total number guesses, the number of cards guessed correctly, the total number of incorrect guesses and the total number of points should be output. So for example, assume that the user played 3 rounds and they guessed the first card in 2 tries, the second card in 1 try and the failed to guess the third card. The number of cards drawn would be 3, the total number of guesses would be 6, the number of times the card was guessed correctly would be 2, the total number of incorrect guesses would be 4 and the total number of points would be 5.
If the game is being played in Testing Mode, the contents of guess_deck,
color_list and items_list are output before the game starts. Then, for each
round of the game, the contents of guess_deck, the randomly generated number
that represents the position of the card to be drawn from the deck and the
value of the picture card drawn are output before the menu is printed. This
information should be output in a labeled, easy to read horizontal format
(hint: concatenate the contents of a list, one element at a time, together to
form a string, being sure to concatenate a few blank spaces between each
value. Then output the string, with a label). Your program should not just
dump of the contents of a list.
IMPORTANT NOTES
- Write a logical outline of your program first, then fill in details in pseudo-code.
- Draw diagrams to help you visualize the lists.
- Write and test the program in pieces (for example, try to open a file and read it into guess_list, then add code for creating the colors_list and items_list and test the code etc.).
- Cross check your program with the description to make sure that you have done everything that is required.
- Test your program under a variety of conditions.
- Use blank lines in your code and output to increase clarity and readability.
- Again, please consult the Style Guide on moodle and make sure your program is written with good programming style, which also extends to the user interface (input and output format and clarity).
- After your program is tested, please drop it in the moodle drop box.