Project 2 Info IT 140 SNHU
Project 2 Info IT 140 SNHU
Scenario
You work for a small company that creates text-based games. You recently
pitched your design ideas for a text-based adventure game to your team. Your
team was impressed by all of your designs, and would like you to develop the
game! You will be able to use the map and the pseudocode or flowcharts from
your designs to help you develop the code for the game. In your code, you
have been asked to include clear naming conventions for functions, variables,
and so on, along with in-line comments. Not only will these help you keep
track as you develop, but they will help your team read and understand your
code. This will make it easier to adapt for other games in the future.
Recall that the game requires players to type in a command line prompt to
move through the different rooms and get items from each room. The goal of
the game is for the player to get all of the items before encountering the room
that contains the villain. Each step of the game will require a text output to let
the player know where they are in the game, and an option of whether or not
to obtain the item in each room.
Directions
In Project One, you designed pseudocode or flowcharts for the two main
actions in the game: moving between rooms and gathering items. In this
project, you will write the code for the full game based on your designs. You
will also need to include some additional components beyond your original
designs to help your game work as intended. You will develop all of your code
in one Python (PY) file, titled “TextBasedGame.py.”
#In this solution, the player’s status would be shown in a separate function.
#You may organize your functions differently.
3. Next, begin developing a main function in your code. The main function
will contain the overall gameplay functionality. Review the Project Two
Sample Text Game Flowchart, located in the Supporting Materials
section, to help you visualize how main() will work.
For this step, simply add in a line of code to define your main function,
and a line at the end of your code that will run main(). You will develop
each of the pieces for main() in Steps #4–7.
Here is an example of a dictionary for a few of the rooms from the sample dragon text game.
#A dictionary linking a room to other rooms
#and linking one item for each room except the Start room (Great Hall) and the room
containing the villain
rooms = {
'Great Hall' : { 'South' : 'Bedroom', 'North': 'Dungeon', 'East' : 'Kitchen', 'We
: 'Library' },
'Bedroom' : { 'North' : 'Great Hall', 'East' : 'Cellar', 'item' : 'Armor' },
'Cellar' : { 'West' : 'Bedroom', 'item' : 'Helmet' },
'Dining Room' : { 'South' : 'Kitchen', 'item' : 'Dragon' } #villain
}
#The same pattern would be used for the remaining rooms on the map.
5. The bulk of the main function should include a loop for the gameplay. In
your gameplay loop, develop calls to the function(s) that show the
player’s status and possible commands. You developed these in Step #2.
When called, the function(s) should display the player’s current room and
prompt the player for input (their next command). The player should
enter a command to either move between rooms or to get an item, if one
exists, from a room.
6.
Note: If you completed the Module Six milestone, you have already
developed the basic structure of the gameplay loop, though you may not
have included functions. Review any feedback from your instructor,
copy your code into your “TextBasedGame.py” file, make any necessary
adjustments, and finish developing the code for the gameplay loop.
7. Within the gameplay loop, you should include decision branching to
handle different commands and control the program flow. This should
tell the game what to do for each of the possible commands (inputs)
from the player. Use your pseudocode or flowcharts from Project One to
help you write this code.
o What should happen if the player enters a command to move
between rooms?
o What should happen if the player enters a valid command to get
an item from the room?
Note: If you completed the Module Six milestone, you have already
developed a portion of this code by handling “move” commands. Review
any feedback from your instructor, copy your code into your
“TextBasedGame.py” file, make any necessary adjustments, and finish
developing the code.
Hint: What is the number of items the player needs to collect? How
could you use this number to signal to the game that the player has
won?
Here is a sample from the dragon text game of the output that will result if the player wins the game:
Congratulations! You have collected all items and defeated the dragon!
Thanks for playing the game. Hope you enjoyed it.
If the player loses the game, they will see the following output:
NOM NOM...GAME OVER!
Thanks for playing the game. Hope you enjoyed it.
9.
Note: If you completed the Module Six milestone, the gameplay loop
ended through the use of an “exit” room. You will need to remove the
“exit” room condition and adjust the code so that the game ends when
the player either wins or loses, as described above.
10. As you develop, you should be sure to debug your code to
minimize errors and enhance functionality. After you have developed all
of your code, be sure to run the code and use the map you designed to
navigate through the rooms, testing to make sure that the game is
working correctly. Be sure to test different scenarios such as the
following:
o What happens if the player enters a valid direction? Does the
game move them to the correct room?
o When the player gets an item from a room, is the item added to
their inventory?
o What happens if the player enters an invalid direction or item
command? Does the game provide the correct output?
o What happens if the player wins the game? What happens if the
player loses the game?
What to Submit
To complete this project, you must submit the following:
TextBasedGame.py
Develop and submit the “TextBasedGame.py” file using PyCharm. Include your
full name in a comment at the top of the code. Be sure to submit the code that
you have completed, even if you did not finish the full game.