Question
So, I'm learning how to code but am a little confused at the moment. Can someone show me a simple code that can made a
So, I'm learning how to code but am a little confused at the moment. Can someone show me a simple code that can made a game using the following condtions below if possible (this is just some pointers he game to quide me) For instance, start in the bedroom move to the kitchen to find keys go to the car and drive, if you dont have the keys and go directly to the car you loose. Some simple example like that. A critical concept in this project is the Player's State. The game works in a while loop that repeatedly changes the current player's state, depending on the commands they choose. You will model the player's state using a Dictionary with at least 4 fields. The Player State Dictionary has two required fields: 'game status', which will always be one of the following string values: 'playing', 'quit', 'won', or 'lost' 'location', which will always have a string value indicating the player's current position. main: This function is given to you. Read over its implementation very carefully to fully understand how all the game components work together. print_introduction: 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. get_initial_state: 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 field's of this dictionary must be 'game status', and its value should initially be 'playing'. print_current_state: 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. get_options: This function consumes the current player's state dictionary and returns a list of strings representing commands available to the user right now (e.g., 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 if/else 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. print_options: This function consumes the list of strings (commands) returned by the result of get_optionsand prints each one on its own line. You are free to indent each command and add decorative text (e.g., bullets) as you see fit. The function takes no user input and returns nothing. get_user_input: This function consumes the list of strings (commands) returned by the result of get_optionsand 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!). process_command: 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 'win' or 'lose'. Most likely, this is where you would have the character update their location based on their command, among many other possible updates. print_game_ending: 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 outcomes. You must always print out something, no matter what game state is passed in. This function returns nothing and takes no user input. Developing a game can be tricky. We recommend that you write and try out each function independently (e.g., by writing your own test cases). However, you could instead comment out parts of the main function that you haven't reached yet. A third option is to write in an "Agile" style, always having a "minimally working game" that you slowly and incrementally build.
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