Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question must be answered using python. Thank you in advance! Question 4 (20 points) You have just started your new job as a puzzle engineer
Question must be answered using python. Thank you in advance!
Question 4 (20 points) You have just started your new job as a puzzle engineer at Sierra Studios. Your first task is to create a simple escape the room' type game in the Python programming language. An escape the room' game is defined as follows. When the program runs, a description of a room with no exits will be given to the user (listing objects and people in the room). The user will then be given a chance to type in a command to interact with the objects and/or people in some way (e.g., 'examine the table' or 'talk to Bob'). Interacting in this manner will give responses containing hints as to how to escape the room. For example, after examining the table and talking with Bob, the user might discover they have to flip the lightswitch in order for a secret door to open. Then, if the user enters 'flip the lightswitch, they will win and the game will be over. Your 'escape room' implementation must contain at least the following elements: A function escape_room that returns True only when the player has escaped the room suc- cessfully. (E.g., in the above example, True would be returned if the user enters the phrase 'flip the lightswitch'.) . The function should start by printing a description of the room, including the objects you can examine and people you can talk to. Commands should be stored in a dictionary, with each key being a command and each value being the message to print when that command is entered. Inside a loop, the user should be asked to enter a command, and then the corresponding message in the dictionary should be printed. If the command is not present in the dictionary, "Invalid command." should be printed. The command should be turned into lowercase, so if the user uses capitals in an otherwise valid command, the command will still work. Two special commands, not stored in the dictionary, should also be available for the user. One is the command 'commands', which should display to the user all commands present in the dictionary. The other command will be the special command that lets the user escape the room (e.g., 'flip the lightswitch' in the example above). This command should print a message like 'You have found the secret door!' and then return True. Try to make this command easy to guess, or allow multiple ways for the user to express it (e.g., 'enter 0 in keypad' might also be expressed as 'press O' or 'enter O' or 'press key 0'). There should be at least one object in the room for the user to examine, and when the user types 'examine (object]', a hint should be given about how to escape the room. This object should be listed in the description. Note that it does not have to be an object, but at minimum something that can be examined (e.g., texture of the walls of the room, rug on the floor, etc). There should be at least one named person in the room for the user to talk to, and when the user types 'talk to (person', a hint should be given about how to escape the room. This person should be listed in the description. Note that it does not have to be a person, but minimally something that can give and/or receive input (e.g., computer, intercom, keypad, etc). . At the top of your code file, give your escape room a name by defining the ROOM_NAME variable, 10 and write your name in the AUTHOR variable. (These will have no use for your code, but we will use them in grading.) Any submission meeting these requirements will get full marks, but you are encouraged to go beyond them, either in terms of creativity of descriptions, complexity of puzzles, or technical sophistication. The most impressive submissions (as judged by our TAS) will be shown in class and/or stitched together into a combined work. Filename You must write this program in a file called dungeon.py. Some code is already provided to you. Examples (as executed in Thonny) EXAMPLE 1: >>> %Run dungeon.py You find yourself in a dark room. A candle lies on a small table in front of 4 you, providing a small amount of light. You cannot see any door or exit. 4 However, there is what seems to be a keypad on one of the walls. > EXAMINE CANDLE The candle is tall and thin. You decide to pick it up to examine the rest of 4 the room more closely. You think you can make out half of a mathematical 4 equation on the walls: e to the power i times pi... > examine keypad It is a standard keypad, with digits from 0-9. Looking closely, you think you 4 can make out half of a mathematical equation scratched into the wall above 4 it: + 1... > smash keypad Invalid command. > Commands Commands are: examine candle, examine keypad > enter 0 in keypad A secret door opens ! EXAMPLE 2: >>> %Run dungeon.py You have walked deep into a cave, looking for treasure, when suddenly you 4 wander down a dead-end and hear the tumble of rocks from behind you. You are trapped! In front of you, the rock face is smooth and glistening with 4 moisture. Moss of many different hues grows on the surface. There is an 4 eerie silence, punctuated only by the drops of water from the ceiling into 4 a small pond next to you. What do you do? > commands examine moss examine pond > examine moss You examine the moss closely. Most of the moss are hues of green, but there is 4 one very small area where it is bright purple. You suddenly realize this 4 purple moss is displayed in the shape of a key hole. Perhaps if you had a 4 key, you could use it here. > examine pond You kneel down and peer into the pond. In the reflection of the water, you see 4 yourself with a key in your hand. Your reflection then smiles and puts the 4 key in your pocket. Startled, you stand up and feel inside your pocket -- 4 there is a key there! If only you knew where to use it. > put key in keyhole A secret door opens in the rock wall! Question 4 (20 points) You have just started your new job as a puzzle engineer at Sierra Studios. Your first task is to create a simple escape the room' type game in the Python programming language. An escape the room' game is defined as follows. When the program runs, a description of a room with no exits will be given to the user (listing objects and people in the room). The user will then be given a chance to type in a command to interact with the objects and/or people in some way (e.g., 'examine the table' or 'talk to Bob'). Interacting in this manner will give responses containing hints as to how to escape the room. For example, after examining the table and talking with Bob, the user might discover they have to flip the lightswitch in order for a secret door to open. Then, if the user enters 'flip the lightswitch, they will win and the game will be over. Your 'escape room' implementation must contain at least the following elements: A function escape_room that returns True only when the player has escaped the room suc- cessfully. (E.g., in the above example, True would be returned if the user enters the phrase 'flip the lightswitch'.) . The function should start by printing a description of the room, including the objects you can examine and people you can talk to. Commands should be stored in a dictionary, with each key being a command and each value being the message to print when that command is entered. Inside a loop, the user should be asked to enter a command, and then the corresponding message in the dictionary should be printed. If the command is not present in the dictionary, "Invalid command." should be printed. The command should be turned into lowercase, so if the user uses capitals in an otherwise valid command, the command will still work. Two special commands, not stored in the dictionary, should also be available for the user. One is the command 'commands', which should display to the user all commands present in the dictionary. The other command will be the special command that lets the user escape the room (e.g., 'flip the lightswitch' in the example above). This command should print a message like 'You have found the secret door!' and then return True. Try to make this command easy to guess, or allow multiple ways for the user to express it (e.g., 'enter 0 in keypad' might also be expressed as 'press O' or 'enter O' or 'press key 0'). There should be at least one object in the room for the user to examine, and when the user types 'examine (object]', a hint should be given about how to escape the room. This object should be listed in the description. Note that it does not have to be an object, but at minimum something that can be examined (e.g., texture of the walls of the room, rug on the floor, etc). There should be at least one named person in the room for the user to talk to, and when the user types 'talk to (person', a hint should be given about how to escape the room. This person should be listed in the description. Note that it does not have to be a person, but minimally something that can give and/or receive input (e.g., computer, intercom, keypad, etc). . At the top of your code file, give your escape room a name by defining the ROOM_NAME variable, 10 and write your name in the AUTHOR variable. (These will have no use for your code, but we will use them in grading.) Any submission meeting these requirements will get full marks, but you are encouraged to go beyond them, either in terms of creativity of descriptions, complexity of puzzles, or technical sophistication. The most impressive submissions (as judged by our TAS) will be shown in class and/or stitched together into a combined work. Filename You must write this program in a file called dungeon.py. Some code is already provided to you. Examples (as executed in Thonny) EXAMPLE 1: >>> %Run dungeon.py You find yourself in a dark room. A candle lies on a small table in front of 4 you, providing a small amount of light. You cannot see any door or exit. 4 However, there is what seems to be a keypad on one of the walls. > EXAMINE CANDLE The candle is tall and thin. You decide to pick it up to examine the rest of 4 the room more closely. You think you can make out half of a mathematical 4 equation on the walls: e to the power i times pi... > examine keypad It is a standard keypad, with digits from 0-9. Looking closely, you think you 4 can make out half of a mathematical equation scratched into the wall above 4 it: + 1... > smash keypad Invalid command. > Commands Commands are: examine candle, examine keypad > enter 0 in keypad A secret door opens ! EXAMPLE 2: >>> %Run dungeon.py You have walked deep into a cave, looking for treasure, when suddenly you 4 wander down a dead-end and hear the tumble of rocks from behind you. You are trapped! In front of you, the rock face is smooth and glistening with 4 moisture. Moss of many different hues grows on the surface. There is an 4 eerie silence, punctuated only by the drops of water from the ceiling into 4 a small pond next to you. What do you do? > commands examine moss examine pond > examine moss You examine the moss closely. Most of the moss are hues of green, but there is 4 one very small area where it is bright purple. You suddenly realize this 4 purple moss is displayed in the shape of a key hole. Perhaps if you had a 4 key, you could use it here. > examine pond You kneel down and peer into the pond. In the reflection of the water, you see 4 yourself with a key in your hand. Your reflection then smiles and puts the 4 key in your pocket. Startled, you stand up and feel inside your pocket -- 4 there is a key there! If only you knew where to use it. > put key in keyhole A secret door opens in the rock wallStep 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