@tech4teachers/

3.1 Textadventure with some mods

Python

Fix misspelled words, swap "up" for "north" get output text to look "nicer", add an inventory system get solved location truth table workin

fork
loading
Files
  • main.py
main.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# a text rpg in python
# made by ......Mr. Boyd
#based on Brian Tong's Youtube video
#https://www.youtube.com/watch?v=_n0_vndSuYM&t=597s
#
##Status as of Friday July10 2019::::  got the truth table near line 123 working solved_places, created a line in the movement reporter that is now re-remarked out that was verifying the truth tabe IS updating after you leave a room....next I need to get it updating as soon as you ENTER the room!!##
#import cmd
#import textwrap
import sys
import os
#import time
#import random


screen_width=100


"""player setup"""
class player:
	def __init__(self): ##__init__ MUST have double _ _ underscores __  
    ## next to each other ..in front and in back or  the init built-in will NOT be called 
		self.name= "Kris"
		self.game_over=False
		self.status_effects=[]
		self.current_location='b2'
		self.old_location='b2'
		self.location_up='a2'
		self.location_down='c2'
		self.location_east='b3'
		self.location_west='b1'
		self.destination=''

my_player=player()





def title_screen_selections():
	option=input("Type play to begin or help to see a list of options, or quit:  ")
	if option.lower()==("play"):
		print("You awaken to find yourself in ....")
		print(zonemap[my_player.current_location]['DESCRIPTION'])
		prompt()
	elif option.lower()==("help"):
		help_menu()
	elif option.lower()==("quit"):
		sys.exit()

	while option.lower() not in ['play','help','quit']:
		print("Please enter a valid option.")
		option=input(">>>>") 
		if option.lower()==("play"):
			print("You awaken to find yourself in ....")
			print(zonemap[my_player.current_location]['DESCRIPTION'])
			prompt()
		elif option.lower()==("help"):
			help_menu()
		elif option.lower()==("quit"):
			sys.exit()



def title_screen():
	os.system('clear')
	print('#######################################')
	print('# Welcome to the Iron Rain text game  #')
	print('############# -  Play -  ##############')
	print('############# -  Help -  ##############')
	print('############# -  Quit -  ##############')
	print('#  copyright 2018 Mr.Boyd DC CS class #')
	print('#######################################')
	print(sys.version) #not required 
	title_screen_selections()

def help_menu():
	print('#######################################')
	print('#   Helpful tips to play the game     #')
	print('#      Typical commands are .....     #')
	print('# north, south, east, west...and look #')
	print('#   You MUST spell corectly and type  #')
	print('#  commands into the console/terminal #')
	print('#      Good LUCK and have FUN!!       #')
	print('#######################################')
	title_screen_selections()


### This next help is for in-game help
### if you tried to use the help_menu above...
### it would send you back to the beginning
### and you would ****LOSE ALL YOUR PROGRESS!!!!!****
### because it ends with a return to the title screen
### this in-game help finishes with the prompt
def help_me():
	print('#######################################')
	print('#   Helpful tips to play the game     #')
	print('#      Typical commands are .....     #')
	print('# north, south, east, west...and look #')
	print('#   You MUST spell corectly and type  #')
	print('#  commands into the console/terminal #')
	print('#      You can do this Keep Trying!   #')
	print('#######################################')
	prompt()

#### map key/legend

"""
player start is b2

 a1 a2 a3
|__|__|__
 b1 b2 b3
|__|__|__
 c1 c2 c3
|__|__|__
"""


## This is a "dictionary" container, like an array in JS
## these are places the player has been...which may determine
## if items are still available there, or enemies are still present
## or if one-time events have already happend
## imagine a king sends you ona quest, he waits in a room in his castle
## so when you return and the room count goes up to >1 AND you have the 
## quested item WITH you in your inventory....THEN he says something new

solved_places=	{"a1":False,"a2":False,"a3":False,
				 "b1":False,"b2":True,"b3":False,
				 "c1":False,"c2":False,"c3":False
			  	}



## we can add new rooms to this with a function rather than
## having to type EVERY one into here later, using methods to 
## add to dictionaries, some games "generate" maps on the fly
## but if we ever encounter bugs or errors the tried-and-true 
## approach is to have all the locations in a big list....typed out 


zonemap={
	'a1':{
		'ZONENAME':'the western edge of your neighborhood',
		'DESCRIPTION':'Bordered by the highway and the core of your once peaceful neighborhood this area was hit especially hard there seems to be virtually nothing left standing above the craters',
		'EXAMINATION':'look',
		'SOLVED':False,
		'UP':'a1',    #location that can be reached by heading "north"
		'DOWN':'b1', #location that can be reached by heading "south"
		'LEFT':'a1',#location that can be reached by heading "west"
		'RIGHT':'a2',#location that can be reached by heading "east"
		'SURPRISES':' a crowbar and a rather alien looking egg pulsing and glowing.'   # for now I will put items and other characters in here
	},

	'a2':{
		'ZONENAME':'the Neighborhood Center',
		'DESCRIPTION':' In the core of the neighborhood is a park that while pockmarked by meteor craters seems to be where people are gathering and a triage station has informally started to treat the wounded',
		'EXAMINATION':'look',
		'SOLVED ':False,
		'UP':'a2',
		'DOWN':'b2',
		'LEFT':'a1',
		'RIGHT':'a3',
		'SURPRISES':'an emergency responder, who offers you a bottle of water and a granola bar.',
	},

	'a3':{
		'ZONENAME':'the eastern edge of your neighborhood',
		'DESCRIPTION':'Bordered by the endless sprawling suburbs to the East and the core of your once peaceful neighborhood this area was hit especially hard there seems to be virtually nothing left standing above the craters',
		'EXAMINATION':'look',
		'SOLVED':False,
		'UP':'a3',
		'DOWN':'b3',
		'LEFT':'a2',
		'RIGHT':'a3',
		'SURPRISES':'nothing else that catches your eye'
	},

	'b1':{
		'ZONENAME':'The road into town',
		'DESCRIPTION':'Littered with personal belongings and cars tipped into meteor craters, the smell of burnt flesh and gasoline are pungent in the air, it will be slow going but there is only one bridge to cross, with luck it will be intact.',
		'EXAMINATION':'look',
		'SOLVED':False,
		'UP':'a1',
		'DOWN':'c1',
		'LEFT':'b1',
		'RIGHT':'b2',
		'SURPRISES':'nothing else that catches your eye'
	},

	'b2':{
		'ZONENAME':'Your home',
		'DESCRIPTION':'The smoldering rubble that was once your house.',
		'EXAMINATION':'look',
		'SOLVED':True,
		'UP':'a2',
		'DOWN':'c2',
		'LEFT':'b1',
		'RIGHT':'b3',
		'SURPRISES':'nothing else that catches your eye'
	},

	'b3':{
		'ZONENAME':'Hardendorf Elementary School',
		'DESCRIPTION':' As you kick chunks of concrete aside and ascend the steps of your elementary school you feel releived, fortunately the meteor shower seems to have hit early in the morning before classes, it is eerily silent, but you see the crumpled body of a janitor near some doors as you approach, the school is on fire in a few places but is largely intact',
		'EXAMINATION':'look',
		'SOLVED':False,'UP':'a3','DOWN':'c3','LEFT':'b2','RIGHT':'b3',
		'SURPRISES':'The janitor Mr. Wemerling slumped next to a pair of outer double doors, with a school master key clutched tightly in his hand, he was always friendly to you and your friends but sadly seems to have passed away'
	},
	'c1':{
		'ZONENAME':'the edge of a massive crater',
		'DESCRIPTION':'The size of a football field and nearly half as deep, the steeply sloping sides and mounded up ring of impact ejecta are impossible to get through, natural gas lines seen to have been severed and at any moment lingering gasses might ignite, you should find another route',
		'EXAMINATION':'look',
		'SOLVED':False,
		'UP':'b1',
		'DOWN':'c1',
		'LEFT':'c1',
		'RIGHT':'c2',
		'SURPRISES':'nothing else that catches your eye'
	},
	'c2':{
		'ZONENAME':'your back-yard',
		'DESCRIPTION':'A little worse for the wear but even though there seems to be no way back inside your home, at least your trusty treehouse is still intact, now peering out over the dust and smoke you are glad you built it so high in that old maple tree.',
		'EXAMINATION':'look',
		'SOLVED':False,
		'UP':'b2',
		'DOWN':'c2',
		'LEFT':'c2',
		'RIGHT':'c3',
		'SURPRISES':'nothing else that catches your eye'
	},
	'c3':{
		'ZONENAME':'the edge of a massive crater',
		'DESCRIPTION':'The size of a football field and nearly half as deep, the steeply sloping sides and mounded up ring of impact ejecta are impossible to get through, natural gas lines seen to have been severed and at any moment lingering gasses might ignite, you should find another route',
		'EXAMINATION':'look',
		'SOLVED ':False,
		'UP':'b1',
		'DOWN':'c3',
		'LEFT':'c2',
		'RIGHT':'c3',
		'SURPRISES':'nothing else that catches your eye'
	},
}

def location_update():
	my_player.location_up=(zonemap[my_player.current_location]['UP'])
	## goes to the player's current location in the zonemap and looks at what is "up"
	## then updates the location_up with that information ( when "look") is called
	## should have been able to USE the "up" description directly from zonemap
	## without storing it in another/additional data container in the player class but 
	## for some reason retreiving it directly on-the-fly wasn't working
	## so this is my work around
	my_player.location_down=(zonemap[my_player.current_location]['DOWN'])
	my_player.location_east=(zonemap[my_player.current_location]['RIGHT'])
	my_player.location_west=(zonemap[my_player.current_location]['LEFT'])




"""UPDATED 2018"""
###### Game interactivity
def print_location():
	print('\n'+('#'*(6+len(zonemap[my_player.current_location]['ZONENAME'])))) 
## 6+len creates a border the same length as the location name we are about to print
	print('\n'+'#  '+zonemap[my_player.current_location]['ZONENAME'] +'  #')
	print('\n'+('#'*(6+len(zonemap[my_player.current_location]['ZONENAME'])))) 
## and again we make it look nice with a boarder of hashtags# the same length


def prompt():
	while my_player.game_over is False: 
		"""UPDATED 2018 ...aded the remarked out print(solve_places) line below to verify truth table updates were taking effect...you can always unremark this for testing purposes again later """
		##print(solved_places)   
		print("\n"+"=====================")
		print("What would you like to do?")
		action = input(">")
		myaction=action.lower() 
		if 	myaction not in['north','up','south','down','east','west','look','inventory','quit', 'help']:
 				print("You can't do that, try something else. \n")
 				prompt()
		elif myaction in ['up','north','south','down','east','west']:
				player_move(myaction)   # don't panic ....I know player_move hasn't been 
				#created yet......we are about to make it in the very next section/function 
		elif myaction == 'look':
				player_examine()
		elif myaction == 'help':
				help_me()
		elif myaction == 'quit':
				sys.exit()



def player_move(myaction):
	dest = str(myaction)  #str....forces this to a string ....just in case
	if dest in ['up','north']:  #here I allow two options 
		my_player.old_location = my_player.current_location
		my_player.current_location = zonemap[my_player.current_location]['UP']
		# so BEFORE we move, we set the old place we used to be to where we 
		# are now,then move, THEN update where we are now in the sotred values.
		#zonemap[my_player.current_location]['SOLVED']=True
		movement_reporter()

	elif dest=='south':  #I should really add 'down' as an option???
		my_player.old_location = my_player.current_location
		my_player.current_location = zonemap[my_player.current_location]['DOWN']
		#(zonemap[my_player.location]['SOLVED'])=True
		movement_reporter()
	elif dest=='east':  #what about adding 'left' as a choice??
		my_player.old_location = my_player.current_location
		my_player.current_location = zonemap[my_player.current_location]['RIGHT']
		#(zonemap[my_player.location]['SOLVED'])=True
		movement_reporter()

	elif dest=='west':
		my_player.old_location = my_player.current_location
		my_player.current_location = zonemap[my_player.current_location]['LEFT']
		#(zonemap[my_player.location]['SOLVED'])=True
		movement_reporter()


def movement_reporter():
#	destination=genericvalue  ## tried this and it didn't work
	location_update()
#	my_player.destination=str(destination) ## tried this and it didn't work
#	my_player.destination=genericvalue  ## tried this and it didn't work
	print("\n"+"You have made your way to the "+(zonemap[my_player.current_location]['ZONENAME'])+".")
	print("...")
	print(zonemap[my_player.current_location]['DESCRIPTION'])
	print_location()
	"""UPDATED 2018 need to try out the truth table HERE """
	## this next line is the line I think that will SET the truth table working see also the printing of the truth table 
	## THIS ONLY SETS TO TRUE AFTER LEAVING ....NOT ON ARRIVAL..
	## which may impact the event sequence of geting itms or fighting/talking to characters.....next see if it can be done on arrival!!
	solved_places[my_player.current_location]=True
	print('this is just debugging help leave it here for now')
	print(solved_places)

  ##this is just for debugging
	prompt()

"""UPDATED 2018/19 to include if/elif combinations that check for navigability in a direction...if there is none you are told 'nothing immediately reachable to the _____ of you' """
def player_examine():
	location_update()
	if zonemap[my_player.location_up]['ZONENAME']== zonemap[my_player.current_location]['ZONENAME']:
		print(" It appears there is nothing immediately reachable to the north of you. \n")
	elif zonemap[my_player.location_up]['ZONENAME']!= zonemap[my_player.current_location]['ZONENAME']:
		print("You see "+ zonemap[my_player.location_up]['ZONENAME']+" to the north of you. \n")

	if zonemap[my_player.location_down]['ZONENAME']== zonemap[my_player.current_location]['ZONENAME']:
		print(" It appears there is nothing immediately reachable to the south of you. \n")
	elif zonemap[my_player.location_down]['ZONENAME']!= zonemap[my_player.current_location]['ZONENAME']:
		print("You see "+ zonemap[my_player.location_down]['ZONENAME']+" to the south of you. \n")

	if zonemap[my_player.location_east]['ZONENAME']== zonemap[my_player.current_location]['ZONENAME']:
		print(" It appears there is nothing immediately reachable to the east of you. \n")
	elif zonemap[my_player.location_east]['ZONENAME']!= zonemap[my_player.current_location]['ZONENAME']:
		print("You see "+ zonemap[my_player.location_east]['ZONENAME']+" to the east of you. \n")

	if zonemap[my_player.location_west]['ZONENAME']== zonemap[my_player.current_location]['ZONENAME']:
		print(" It appears there is nothing immediately reachable to the west of you. \n")
	elif zonemap[my_player.location_west]['ZONENAME']!= zonemap[my_player.current_location]['ZONENAME']:
		print("You see "+ zonemap[my_player.location_west]['ZONENAME']+" to the west of you. \n")		
	# consider adding a way to if check that the direction is the SAME as the current name ...indicating you can't go there
	prompt()
	## other ideas for other ITEMS you might see and/or get/acquire 
	#	print("...and upon further investigation, you see "+ zonemap[my_player.location]['SURPRISES']+"\n")
	#	(zonemap[my_player.location]['SOLVED'])=True
	#	prompt()




"""main game function and loop
 Game Functionality
def start_game():
	while player.game_over == False
	.......how do we 'else' reset the game if player.alive=False????
	return"""

#def main_game_loop():
	#os.system('clear')
#	while my_player.game_over == False:
#		prompt()

title_screen()
# starting at the title screen starts the program