Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make sure it is all in python Once the loop ends (i.e. the in-progress variable is False), check if the elf got enough calories. If

Make sure it is all in python

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Once the loop ends (i.e. the in-progress variable is False), check if the elf got enough calories. If it did, print a success message and quit. Otherwise, print a failure message and quit. - a show_help(self) method that prints out a help message and all the commands from the command dictionary's keys. This method must also post the current time. You will need to read the datetime documentation to do this - https://docs.python.org/3/library/datetime.html. Print the time in a nicely formatted string, but you can decide if you wish to use 12 or 24 -hour time. - a talk(self, target) -> None method. This method will check if the provided NPC is in the current room. If it is, it will call the NPC's get_message method and print the resulting message. - a meet (self, target) None method. It will check if the NPC is in the room, and if it is will ask the NPC for its description and print it. - a take (self, target) None method. If the target item is in the room it will remove it from the room's inventory, add it to the user's inventory, and add the weight of the item to the user's carried weight. - a give (self, target) None method. Removes the target item (if it exists) from the user's inventory, adds it to the current location's inventory and decreases the user's carried weight. The function will then check if the current location is the woods. If it is, it will check if the item given was edible. If the item is edible, reduce the number of calories the item has from the total the elf needs. If the item was not edible, transport the player to a new location by setting the current location equal to the return from random_location. - a go(self, target) None method. Sets the current location's visited status to True. Checks if the player has over 30 weight; prints a message and returns if so. Otherwise, it checks if provided direction exists in the current location's neighbor dictionary. If so, sets the current location equal to the value from the dictionary. - a show_items (self, args: str = None) None method. This method doesn't need any parameters but has an args parameter so it can be called with the same syntax as the other commands. It should print all items the player is carrying, and the current amount of weight carried. - a look (self, args: str = None) None method. This method doesn't need parameters either but has args for the same reason as given above. This method will print the current location, a list of Item s in the location or a message indicating there are none, a list of NPC s in the room or the message "You are alone.", and a list of directions in which the player can go. If a location has been visited previously, print the direction and the location. Otherwise, simply print the direction. - a quit(self, args: str = None) None method that prints a failure message and exits the game. This implicitly concatenates the two strings together, so formatting this way poses no issues. In this function you will need to add all s and NPC s to the rooms in which they belong, as well as add each to the neighbors to which it needs to connect. Also, be sure to add each to the list. Because there will be so much setup code, you may wish to break the function into commented regions, wherein each region focuses on the creation and setup of a single . Your game needs at least 8 s. There is no requirement for how many Item s and_ s, but your game in each does need at least 10 s and 5s. - a setup_commands (self) -> Dict[str, Callable] method. This method will create a new dictionary. The keys will be a command such as talk, give, go, etc. The values of the dictionary will be the names of the functions that should be called for each of those commands. Note that we can have more than one command per function; for instance, we could have both "?" and "help" correspond to a method. Be sure this function returns the dictionary. - a random_location(self) -> Location method that selects a random from the locations list and returns that - a method. This is the core game loop. It should first print a message describing the game, then call the method to list all commands. Then, while the game is still in progress, it will loop. In the loop, we will prompt the user for a command. The user may enter multiple words in a prompt. We will split the user's input into a list of words. We can split on spaces with code tokens = user_response.split () . Once we have the tokens list, create a variable called and set it equal to the first element in the list. Then, remove the first element with the command. Then, use the code code to put the remaining tokens together. Thus, if the user enters class will require the most code to be written. It needs - a constructor that takes no parameters (other than . The constructor will set the commands dictionary equal to the return call from our function. It will call the method. It will then set default values for all other variables. Set the current location to a random location selected from the method. - a create_world(self) , None method that creates all the, and in the game. This function can get messy, as it will have a lot of text for names and descriptions of objects. Remember that your code should not be more than 72 characters long (this is marked in PyCharm with a vertical line). If a line goes beyond that, you should separate it into more than one line. You can do this by splitting the string: kirkhoff_upstairs = Location("kirkhoff upstairs", "The student union. There are restaurants, a store, and places to congregate.") becomes kirkhoff_upstairs = Location("kirkhoff upstairs", "The student union. There are restaurants, a store, and " "places to congregate.") This implicitly concatenates the two strings together, so formatting this way poses no issues. In this function you will need to add all s and s to the rooms in which they belong, as well as add each to the neighbors to which it needs to connect. Also, be sure to add each Location to the self._locations list. Because there will be so much setup code, you may wish to break the function into commented regions, wherein each region focuses on the creation and setup of a single . Your game needs at least 8 i. There is no requirement for how many Item s and , but your game does need at least 10 s and 5 NPC s. Game The game takes place in a world of connected locations. The purpose of the game is to collect edible items and then bring them to the elf in the woods behind campus. The elf needs 500 calories of edible food before it will save GVSU. Each item can have 0 or more calories. If a player gives the elf something inedible (something with 0 calories), the elf will be displeased and will teleport the player to a random location in the world. The player can only carry 30 pounds at a time, so multiple trips to the elf may be needed. Once the elf has enough calories, it will save campus and the game will end. The class holds all the logic for a game instance. This class will hold several pieces of data. Make sure it has - a dictionary of commands - a list of Item s the player currently has in their inventory - an int that holds the current weight the player is carrying - a of Location s that exist in the world - a variable to hold the player's current location - an to hold the number of calories the elf needs before it will save the campus - a bool to store whether the game is still in progress will adhere to the Command Pattern. Instead of having a loop body with a large number of statements, for instance Location Each represents a place on campus that may be visited. A location holds a name, a description a bool that indicates if it has been yet visited, a dictionary of neighbors, a list of NPC s, and a list of items. The neighbors dictionary will have a key that is a direction, that refers to a Location as its value. For instance, if we have a called and another called , would have a dictionary entry "west" that holds kirkhoff. We then want to hold in its dictionary a key-value pair of "east" that refers to . we want to have two locations attached such that the player can enter but not exit the way they came, we can merely leave the entry off one of the objects. For instance, we could have a Location that has a "through" key pointing to but no corresponding key-value pair in the neighbor dictionary. must implement: - a constructor that takes a name and description - a function that returns the neighbors dictionary - an add_location(self, direction: str, location: 'Location') None method. This function will add the location into the dictionary with the provided direction string. If the string is blank, raise a . If the key already exists in the dictionary, raise a - an add_npc (self, npc: NPC) method for adding an to the list, and a get_npcs(self) List [NPC] function that returns the list of NPC s. - an add_item(self, item: Item) method for adding an to the NPC list, and a get_items (self) List[Item] method to return the s. - a set_visited(self) > None method that changes the visited variable to True. Once a location is visited, it can no longer be False. Also, include a get_visited(self) -> bool function for checking if the location has been visited. - method that returns the name and description formatted as NAME - DESCRIPTION, i.e. "'Padnos Hall - Lots of science labs are in this building. The NPC class represents information about a character that can be in a . An NPC has a name, description, message number, and list of messages. Each time the player speaks to an NPC, the message number should increase by 1 , resulting in the next message in the list being printed the next time the player speaks to the character. The message number should go back to 0 after it goes past the length of the message list. The class must have: - a constructor that accepts a name and a description - - getters for name and description - a getter for a message that returns the current message (as indicated by message number), then changes the message number appropriately - a __str_(self) str method that returns only the name of the NPC ltem An represents objects the player may encounter along the way, and is an object that has a name, a description, the number of calories it can provide (0 if it isn't edible), and a weight. It must provide: - A constructor that can take a name, description, calories, and weight. - You must ensure the following: - the name variable cannot be blank. Raise a with an appropriate message if a blank string is passed in. - the calorie variable cannot be less than 0 or more than 1000 and must be an . - the description cannot be blank. - the weight must be an and must be between 0 and 500 . - A method that returns a string representing the The format should be NAME - X lb - DESCRIPTION, i.e. Rusty Nail - 1 lb - A rusty nail (I hope you've had a tetanus shot) You can ensure that a variable is of the desired type with the function (https://docs.python.org/3/library/functions.html\#isinstance). If, for instance, you wanted to make sure length was a floating point number, you could type if isinstance(length, float): do something.. Once the loop ends (i.e. the in-progress variable is False), check if the elf got enough calories. If it did, print a success message and quit. Otherwise, print a failure message and quit. - a show_help(self) method that prints out a help message and all the commands from the command dictionary's keys. This method must also post the current time. You will need to read the datetime documentation to do this - https://docs.python.org/3/library/datetime.html. Print the time in a nicely formatted string, but you can decide if you wish to use 12 or 24 -hour time. - a talk(self, target) -> None method. This method will check if the provided NPC is in the current room. If it is, it will call the NPC's get_message method and print the resulting message. - a meet (self, target) None method. It will check if the NPC is in the room, and if it is will ask the NPC for its description and print it. - a take (self, target) None method. If the target item is in the room it will remove it from the room's inventory, add it to the user's inventory, and add the weight of the item to the user's carried weight. - a give (self, target) None method. Removes the target item (if it exists) from the user's inventory, adds it to the current location's inventory and decreases the user's carried weight. The function will then check if the current location is the woods. If it is, it will check if the item given was edible. If the item is edible, reduce the number of calories the item has from the total the elf needs. If the item was not edible, transport the player to a new location by setting the current location equal to the return from random_location. - a go(self, target) None method. Sets the current location's visited status to True. Checks if the player has over 30 weight; prints a message and returns if so. Otherwise, it checks if provided direction exists in the current location's neighbor dictionary. If so, sets the current location equal to the value from the dictionary. - a show_items (self, args: str = None) None method. This method doesn't need any parameters but has an args parameter so it can be called with the same syntax as the other commands. It should print all items the player is carrying, and the current amount of weight carried. - a look (self, args: str = None) None method. This method doesn't need parameters either but has args for the same reason as given above. This method will print the current location, a list of Item s in the location or a message indicating there are none, a list of NPC s in the room or the message "You are alone.", and a list of directions in which the player can go. If a location has been visited previously, print the direction and the location. Otherwise, simply print the direction. - a quit(self, args: str = None) None method that prints a failure message and exits the game. This implicitly concatenates the two strings together, so formatting this way poses no issues. In this function you will need to add all s and NPC s to the rooms in which they belong, as well as add each to the neighbors to which it needs to connect. Also, be sure to add each to the list. Because there will be so much setup code, you may wish to break the function into commented regions, wherein each region focuses on the creation and setup of a single . Your game needs at least 8 s. There is no requirement for how many Item s and_ s, but your game in each does need at least 10 s and 5s. - a setup_commands (self) -> Dict[str, Callable] method. This method will create a new dictionary. The keys will be a command such as talk, give, go, etc. The values of the dictionary will be the names of the functions that should be called for each of those commands. Note that we can have more than one command per function; for instance, we could have both "?" and "help" correspond to a method. Be sure this function returns the dictionary. - a random_location(self) -> Location method that selects a random from the locations list and returns that - a method. This is the core game loop. It should first print a message describing the game, then call the method to list all commands. Then, while the game is still in progress, it will loop. In the loop, we will prompt the user for a command. The user may enter multiple words in a prompt. We will split the user's input into a list of words. We can split on spaces with code tokens = user_response.split () . Once we have the tokens list, create a variable called and set it equal to the first element in the list. Then, remove the first element with the command. Then, use the code code to put the remaining tokens together. Thus, if the user enters class will require the most code to be written. It needs - a constructor that takes no parameters (other than . The constructor will set the commands dictionary equal to the return call from our function. It will call the method. It will then set default values for all other variables. Set the current location to a random location selected from the method. - a create_world(self) , None method that creates all the, and in the game. This function can get messy, as it will have a lot of text for names and descriptions of objects. Remember that your code should not be more than 72 characters long (this is marked in PyCharm with a vertical line). If a line goes beyond that, you should separate it into more than one line. You can do this by splitting the string: kirkhoff_upstairs = Location("kirkhoff upstairs", "The student union. There are restaurants, a store, and places to congregate.") becomes kirkhoff_upstairs = Location("kirkhoff upstairs", "The student union. There are restaurants, a store, and " "places to congregate.") This implicitly concatenates the two strings together, so formatting this way poses no issues. In this function you will need to add all s and s to the rooms in which they belong, as well as add each to the neighbors to which it needs to connect. Also, be sure to add each Location to the self._locations list. Because there will be so much setup code, you may wish to break the function into commented regions, wherein each region focuses on the creation and setup of a single . Your game needs at least 8 i. There is no requirement for how many Item s and , but your game does need at least 10 s and 5 NPC s. Game The game takes place in a world of connected locations. The purpose of the game is to collect edible items and then bring them to the elf in the woods behind campus. The elf needs 500 calories of edible food before it will save GVSU. Each item can have 0 or more calories. If a player gives the elf something inedible (something with 0 calories), the elf will be displeased and will teleport the player to a random location in the world. The player can only carry 30 pounds at a time, so multiple trips to the elf may be needed. Once the elf has enough calories, it will save campus and the game will end. The class holds all the logic for a game instance. This class will hold several pieces of data. Make sure it has - a dictionary of commands - a list of Item s the player currently has in their inventory - an int that holds the current weight the player is carrying - a of Location s that exist in the world - a variable to hold the player's current location - an to hold the number of calories the elf needs before it will save the campus - a bool to store whether the game is still in progress will adhere to the Command Pattern. Instead of having a loop body with a large number of statements, for instance Location Each represents a place on campus that may be visited. A location holds a name, a description a bool that indicates if it has been yet visited, a dictionary of neighbors, a list of NPC s, and a list of items. The neighbors dictionary will have a key that is a direction, that refers to a Location as its value. For instance, if we have a called and another called , would have a dictionary entry "west" that holds kirkhoff. We then want to hold in its dictionary a key-value pair of "east" that refers to . we want to have two locations attached such that the player can enter but not exit the way they came, we can merely leave the entry off one of the objects. For instance, we could have a Location that has a "through" key pointing to but no corresponding key-value pair in the neighbor dictionary. must implement: - a constructor that takes a name and description - a function that returns the neighbors dictionary - an add_location(self, direction: str, location: 'Location') None method. This function will add the location into the dictionary with the provided direction string. If the string is blank, raise a . If the key already exists in the dictionary, raise a - an add_npc (self, npc: NPC) method for adding an to the list, and a get_npcs(self) List [NPC] function that returns the list of NPC s. - an add_item(self, item: Item) method for adding an to the NPC list, and a get_items (self) List[Item] method to return the s. - a set_visited(self) > None method that changes the visited variable to True. Once a location is visited, it can no longer be False. Also, include a get_visited(self) -> bool function for checking if the location has been visited. - method that returns the name and description formatted as NAME - DESCRIPTION, i.e. "'Padnos Hall - Lots of science labs are in this building. The NPC class represents information about a character that can be in a . An NPC has a name, description, message number, and list of messages. Each time the player speaks to an NPC, the message number should increase by 1 , resulting in the next message in the list being printed the next time the player speaks to the character. The message number should go back to 0 after it goes past the length of the message list. The class must have: - a constructor that accepts a name and a description - - getters for name and description - a getter for a message that returns the current message (as indicated by message number), then changes the message number appropriately - a __str_(self) str method that returns only the name of the NPC ltem An represents objects the player may encounter along the way, and is an object that has a name, a description, the number of calories it can provide (0 if it isn't edible), and a weight. It must provide: - A constructor that can take a name, description, calories, and weight. - You must ensure the following: - the name variable cannot be blank. Raise a with an appropriate message if a blank string is passed in. - the calorie variable cannot be less than 0 or more than 1000 and must be an . - the description cannot be blank. - the weight must be an and must be between 0 and 500 . - A method that returns a string representing the The format should be NAME - X lb - DESCRIPTION, i.e. Rusty Nail - 1 lb - A rusty nail (I hope you've had a tetanus shot) You can ensure that a variable is of the desired type with the function (https://docs.python.org/3/library/functions.html\#isinstance). If, for instance, you wanted to make sure length was a floating point number, you could type if isinstance(length, float): do something

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

develop ideas for a research project;

Answered: 1 week ago