Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The diagram above shows the control flow of the code. Square boxes are functions that you will need to define, and their color indicates whether
The diagram above shows the control flow of the code. Square boxes are functions that you will need to define, and their color indicates whether they read, make, update, or have no interactions with the main Player State Dictionary.
main: This function is given to you. Read over its implementation very carefully to fully understand how all the game components work together.
printintroduction: This function consumes nothing, takes no user input, and returns nothing. Instead, it is responsible for printing an introductory message to introduce your game. There are no requirements on what it can print, except that you must print something.
getinitialstate: This function consumes nothing, takes no user input, and prints nothing. Instead, it must return a dictionary representing the initial state of the player. Remember that one of the fields of this dictionary must be 'game status', and its value should initially be 'playing'.
printcurrentstate: This function consumes the current player's state dictionary and prints out information about it It takes no user input and returns nothing. The only required thing to print is the player's current 'location'. It doesn't matter what you print alongside it as long as the field's value gets printed. After that, you should print out some other supplementary text to describe your player's current state. There is no maximum amount of text, but you must print out something relevant to the player's state. For instance, if your game had a 'poisoned? mechanic, you might print out, "You are poisoned! You need to find an antidote or you will collapse." Or if you had an inventory mechanic, you might print out each item of the inventory.
getoptions: This function consumes the current player's state dictionary and returns a list of strings representing commands available to the user right now eg places to move to commands to execute, things available to be collected It should take no user input and prints nothing. You might organize this using ifelse statements, dictionaries, or helper functions. For example, you could check the player's location and offer them other locations to move to You should never return an empty list from this function.
printoptions: This function consumes the list of strings commands returned by the result of getoptions and prints each one on its own line. You are free to indent each command and add decorative text eg bullets as you see fit. The function takes no user input and returns nothing.
getuserinput: This function consumes the list of strings commands returned by the result of getoptions and let's the user input which command they want to choose. The function must repeatedly loop internally until the user types in one of the valid commands OR the user types "quit". The function should then return the user's inputted command. Notice that this function takes user input, takes an argument, returns a value, and can print if you want it to you are free to print whatever you'd like Also note that the function has its own loop separate from the main game loop it should be similar to code you've written for the lesson on While loops!
processcommand: Given a command string and a player' state dictionary modify the dictionary so that the player's state is changed. Notice that this function does not return anything, but instead mutates the given dictionary. You are free to make it print, if that is relevant to your game, but it is not required. At the minimum, this function should change the 'game status' field to 'quit' if the player quits, and should also have some way of changing the 'game status' to 'won' or 'lost'. Most likely, this is where you would have the character update their location based on their command, among many other possible updates.
printgameending: This function consumes the current player's state dictionary and prints out a different message depending on whether they won, lost, or quit the game. You are free to customize this message however you see fit perhaps having different kinds of victory conditions but you must print out a different message for the three possible gameending outcomes. Additionally, you must always print out something, no matter what game state is passed in including the 'playing' state it can be useful for debugging to print a "THIS SHOULD NEVER HAPPEN" message to catch a problem just in case the function is ever called in the 'playing' state This function returns nothing and takes no user input.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started