-
Notifications
You must be signed in to change notification settings - Fork 0
/
homestar_walkabout.py
234 lines (207 loc) · 7.4 KB
/
homestar_walkabout.py
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
from sys import exit
from pprint import pprint
#setup context
inv = ['quesos']
objectives = []
context = 'inside'
#setup vocabulary
move = ['go','enter','move','exit','walk','open','hover']
take = ['pickup','take','grab']
inventory = ['inv','inventory']
look = ['look','see']
use = ['use']
objectives = ['objectives']
actions = {'move': move, 'take': take, 'look': look, 'inventory': inventory, 'use': use, 'objectives': objectives}
directions = {'in': ['in','inside','enter'], 'out': ['out','outside','exit'], 'left': ['left','west'], 'right': ['right','east'], 'up': ['up','north'], 'down': ['down','south']}
# function to normalize input
def parse_input(input):
global actions
global context
input = input.lower().strip()
if('lure' in input or 'jig' in input):
print 'You tantalizingly start to say "Come on and get in the boat, fish! Come on and get in the boat, fish fish! Come on and get in the boat, fish!" while doing a pretty sweet jig'
print 'There are now many fish on the ground. Where they came from no one knows'
return '',''
if('fly' in input and 'hover' in move):
print 'Well, you can\'t really fly ever since you put all that weight on. You can pretty much only hover an inch or two above the ground'
return '',''
if('sbu' in input and 'hover' in move):
print 'Why did you just say sbu? Are you some kind of idiot? Now you can\'t hover anymore!'
actions['move'].remove('hover')
return '',''
if(input.find(' ') == -1 and input in inv):
return 'use',input
norm, match = match_vocab(actions, input)
if(norm != ''):
if(norm == 'move'):
dir_norm, dir_match = match_vocab(directions, input)
if(dir_norm != ''):
return norm,dir_norm
if(norm == 'inventory'):
check_inv()
remainder = input.replace(match,'').strip()
return norm,remainder
return 'error',''
def match_vocab(vocab, input):
"""Takes a dictionary of lists as a vocabulary element and an input string and returns the normalized word and matched word"""
for dict_key in vocab:
for list_item in vocab[dict_key]:
if(list_item in input):
return dict_key,list_item
return '',''
def check_inv():
global inv
if(len(inv) > 0):
print "Here is a list of all the things your have in your inventory:"
for i in inv:
print i
else:
print "You have nothing in your inventory! This is terrible!"
return 0
def get_input():
input = raw_input('> ')
return parse_input(input.strip())
def bubs_inside():
global context
while(1):
context = 'inside'
description = 'You are inside a brick building. There are letters one might use on a movie theater sign strewn about the ground, many food items, and what appears to have been a cold one in a former life.'
print description
action,remainder = get_input()
pprint(action)
pprint(remainder)
if(action == 'move'):
if('out' in remainder):
bubs_outside()
else:
print 'You cannot go there!'
def bubs_outside():
global context
while(1):
context = 'outside'
print 'You are outside of a small brick building, which, wait you know this place well! This is your concession stand. And even if you don\'t remember it, the sign at the top reading "Bubs\' Concession Stand" is helping out'
action,remainder = get_input()
if(action == 'move'):
if('in' in remainder):
bubs_inside()
elif('down' in remainder):
field_2()
elif('up' in remainder):
field_2()
elif('left' in remainder):
sports_field()
elif('right' in remainder):
field()
else:
print 'You cannot go there!'
def field_2():
global context
while(1):
context = 'outside'
print 'This is a field'
action,remainder = get_input()
if(action == 'move'):
if('down' in remainder):
field_2()
elif('up' in remainder):
field_2()
elif('left' in remainder):
sports_field()
elif('right' in remainder):
field()
else:
print 'You cannot go there!'
def lockers():
global context
while(1):
context = 'outside'
print 'Lockers'
action,remainder = get_input()
if(action == 'move'):
if('in' in remainder):
bubs_inside()
elif('down' in remainder):
field_2()
elif('up' in remainder):
field_2()
elif('left' in remainder):
sports_field()
elif('right' in remainder):
field()
else:
print 'You cannot go there!'
def sports_field():
global context
while(1):
context = 'outside'
print 'Sports Field'
action,remainder = get_input()
def strong_badia():
global context
while(1):
context = 'outside'
print 'Strong Badia'
action,remainder = get_input()
def grill():
global context
while(1):
context = 'outside'
print 'Grill'
action,remainder = get_input()
def kot_castle():
global context
while(1):
context = 'outside'
print 'KOT Castle'
action,remainder = get_input()
def homestar():
global context
while(1):
context = 'outside'
print 'Homestar House'
action,remainder = get_input()
def stick():
global context
while(1):
context = 'outside'
print 'Stick'
action,remainder = get_input()
def strongbad():
global context
while(1):
context = 'outside'
print 'Strongbad House'
action,remainder = get_input()
def field():
global context
while(1):
context = 'outside'
print 'Field'
action,remainder = get_input()
def marzipan():
global context
while(1):
context = 'outside'
print 'Marzipan House'
action,remainder = get_input()
print """
_____ _____
| | | |
| |_| |
| | _______ _____ _____ ______ ______ _______ _______ _______
| ___ | | ___ | | | \ / | | | ___| | __| |__ __| | ___ | | ___ |
| | | | | |_| | | |\ v /| | | __| |__ | | | | |_| | | |_| |
|___| |___| |_____| |_| \_/ |_| |____| |____| |_| |_| |_| |_| \_\\
____ ____
| | | |
| | | |
| |_| | _______ ___ ___ __ _______ ______ _______ ___ ___ _______
| _ | | ___ | | | | |/ / | ___ | | |_| | | ___ | | | | | |__ __|
| / \ | | |_| | | |_ | | | |_| | | ___< | |_| | | |_| | | |
\/ \/ |_| |_| |___| |_|\_\ |_| |_| |_|_|_| |_____| \___/ |_|
"""
print 'Welcome to Free Country, USA, home of Strongbadia-"The place where tropical breezes blow."'
print 'You are bubs, a man about town and you need to complete an adventure.'
print 'As with any good text-based adventure you will have to navigate this strange world by typing commands at the prompt.'
print 'Game experience will not change during on-line game play.'
bubs_inside()