-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
169 lines (130 loc) · 4.93 KB
/
template.py
File metadata and controls
169 lines (130 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""
##### 0) Header #####
# Text Adventure Game
A chance to make your own Text Adventure Game.
This is an INDIVIDUAL project. Do not consult with others or share code.
Refer to the instructions on Canvas for more information.
# When You Are Done
When you pass all tests, remember to clean and document your code.
Be sure to unit test and document your functions.
"""
##### 1) Author Info #####
# Change these three fields
__author__ = "your email goes here@udel.edu"
__title__ = "Name of your game goes here"
__description__ = "Replace this with a quick description of your game."
# Leave these two fields unchanged
__version__ = 1
__date__ = "Spring 2019"
##### 2) Record Definitions #####
# Add a new record and modify the existing ones to fit your game.
'''
Records:
World:
status (str): Whether or not the game is "playing", "won",
"quit", or "lost". Initially "playing".
map (dict[str: Location]): The lookup dictionary matching
location names to their
information.
player (Player): The player character's information.
Player:
location (str): The name of the player's current location.
inventory (list[str]): The player's collection of items.
Initially empty.
Location:
about (str): A sentence that describes what this location
looks like.
neighbors (list[str]): A list of the names of other places
that you can reach from this
location.
stuff (list[str]): A collection of things available at
this location.
'''
##### 3) Core Game Functions #####
# Implement the following to create your game.
def render_introduction():
'''
Create the message to be displayed at the start of your game.
Returns:
str: The introductory text of your game to be displayed.
'''
def create_world():
'''
Creates a new version of the world in its initial state.
Returns:
World: The initial state of the world
'''
def render(world):
'''
Consumes a world and produces a string that will describe the current state
of the world. Does not print.
Args:
world (World): The current world to describe.
Returns:
str: A textual description of the world.
'''
def get_options(world):
'''
Consumes a world and produces a list of strings representing the options
that are available to be chosen given this state.
Args:
world (World): The current world to get options for.
Returns:
list[str]: The list of commands that the user can choose from.
'''
def update(world, command):
'''
Consumes a world and a command and updates the world according to the
command, also producing a message about the update that occurred. This
function should modify the world given, not produce a new one.
Args:
world (World): The current world to modify.
Returns:
str: A message describing the change that occurred in the world.
'''
def render_ending(world):
'''
Create the message to be displayed at the end of your game.
Args:
world (World): The final world state to use in describing the ending.
Returns:
str: The ending text of your game to be displayed.
'''
def choose(options):
'''
Consumes a list of commands, prints them for the user, takes in user input
for the command that the user wants (prompting repeatedly until a valid
command is chosen), and then returns the command that was chosen.
Note:
Use your answer to Programming Problem #43.4
Args:
options (list[str]): The potential commands to select from.
Returns:
str: The command that was selected by the user.
'''
###### 4) Win/Lose Paths #####
# The autograder will use these to try out your game
# WIN_PATH (list[str]): A list of commands that win the game when entered
# LOSE_PATH (list[str]): A list of commands that lose the game when entered.
WIN_PATH = []
LOSE_PATH = []
###### 5) Unit Tests #####
# Write unit tests here
from cisc108 import assert_equal
###### 6) Main Function #####
# Do not modify this area
def main():
'''
Run your game using the Text Adventure console engine.
Consumes and produces nothing, but prints and indirectly takes user input.
'''
print(render_introduction())
world = create_world()
while world['status'] == 'playing':
print(render(world))
options = get_options(world)
command = choose(options)
print(update(world, command))
print(render_ending(world))
if __name__ == '__main__':
main()