Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this milestone, we will be submitting a working draft of the code for a simplified version of the text-based game that we are developing
For this milestone, we will be submitting a working draft of the code for a simplified version of the text-based game that we are developing for Project Two. We will focus on displaying how a room dictionary works with the "move" commands. This will include the if, else, and elif statements that move the adventurer from one room to another.
- Before beginning this milestone, it is important to understand the required functionality for this simplified version of the game. The game should prompt the player to enter commands to either move between rooms or exit the game.
- In PyCharm, we will create a new code file titled "ModuleSixMilestone.py." As we develop we code, we must use industry-standard best practices, including in-line comments and appropriate naming conventions, to enhance the readability and maintainability of the code.
- Next, copy the following dictionary into a PY file. This dictionary links rooms to one another and will be used to store all possible moves per room, in order to properly validate player commands (input). This will allow the player to move only between rooms that are linked.
- Next, we will develop code to meet the required functionality, by prompting the player to enter commands to move between the rooms or exit the game. To achieve this, we must develop the following:
- A gameplay loop that includes:
- Output that displays the room the player is currently in
- Decision branching that tells the game how to handle the different commands. The commands can be to either move between rooms (such as go North, South, East, or West) or exit.
- If the player enters a valid "move" command, the game should use the dictionary to move them into the new room.
- If the player enters "exit," the game should set their room to a room called "exit."
- If the player enters an invalid command, the game should output an error message to the player (input validation).
- A way to end the gameplay loop once the player is in the "exit" room
- A gameplay loop that includes:
- As we develop, we should debug our code to minimize errors and enhance functionality. After we have developed all of our code, be sure to run the code to test and make sure it is working correctly.
- What happens if the player enters a valid direction? Does the game move them to the correct room?
- What happens if the player enters an invalid direction? Does the game provide the correct output?
- Can the player exit the game?
#A dictionary for the simplified dragon text game #The dictionary links a room to other rooms. rooms = { 'Great Hall': {'South': 'Bedroom'}, 'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'}, 'Cellar': {'West': 'Bedroom'} }
17 ... 2 1 2 3 4 5 CABLGH2H359887 10 11 12 13 14 15 16 17 18 19 20 21 PP python Project1 Version control Module Six Milestone.py x rooms = { } 'Great Hall': {'South': 'Bedroom'}, 'Bedroom': {'North': 'Great Hall', 'East': 'Cellar'}, 'Cellar': {'West': 'Bedroom'} DIRECTIONS = ['North', 'South', 'East', 'West'] EXIT_COMMAND = "Exit" VALID_INPUTS = DIRECTIONS + [EXIT_COMMAND] 22 23 24 25 26 27 28 29 30 31 32 33 ! 34 35 99 navigate() O python Project1 > INVALID_DIRECTION = "That is not a valid direction. You need to enter one of: " + \ str(VALID_INPUTS) + "." CANNOT GO THAT WAY = "You bumped into a wall." GAME_OVER = "Thanks for playing." EXIT_ROOM_SENTINEL = "exit" def navigate(current_room: str user command: str): next_room = current_room err_msg = " if user_command in rooms[current_room] : # If the direction the user wants to go is in rooms [current_room] next_room= rooms [current_room] [user_command] # It will assign the next room as rooms [current_room] [user_input] elif user_command == EXIT_COMMAND: # If the user wants to exit the game return EXIT_ROOM_SENTINEL, GAME_OVER # It will give the user the exit message elif user_command not in DIRECTIONS: # If the user input is not a valid direction return current_room, INVALID_DIRECTION # It will show up as the invalid direction error message elif user_command not in rooms [current_room]: # If there is no room in the direction the user wants to go return current_room, CANNOT_GO_THAT_WAY # It will show up as the wall error message return next room. err msa Module SixMilestone.py Module Six Milestone 15:1 LF UTF-8 & Q A1 ^ A E 2= UTF-8 4 spaces Python 3.12 (python Project1) d
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