New to Python...feedback?

Andy Jewell andy at wild-flower.co.uk
Mon Jun 23 16:40:28 EDT 2003


danka,

Been busy, I see... you asked for comments, so here they are:

	1) You've put all your data right inside the program - this is a "BAD THING" 
(tm).  You ought to either a) put it into a list or similar structure at the 
beginning, or b) even better, into a file of some sort - even just a simple 
text file, then read it into your program.  What if, for example, you wanted 
to do a French or German version ?  Even M$ don't rewrite their apps for each 
different language.

	2) Your program is just one long list of ifs and elses.  Maybe you should 
think about putting more of the logic into your data-structure (after 
covering point 1).  Draw your little adventure out as a diagram, eg. a tree, 
or network, showing how each part inter-relates.

	3) Think about storing the player's 'state', such as current location, what 
they're carrying, how healthy or otherwise they are and using that to affect 
the outcome of the game.


example (not thouroughly thought through, just enough to give you a start).  
You will still need to think about your data structures tho', but later on...

regards, 
-andyj

def getchoice(prompt,choices):
	global quit # global so we can change it from here
	n=1
	valid_choices=[]
	for choice in choices:
		print n,choice
		valid_choices.append(n)
		n=n+1
	valid_choices.append("q")
	resp="*"
	while resp not in valid_choices:
		resp=raw_input(prompt)
	if resp == "q":
		quit=1
	return resp

def bedroom():
	print "you hear the alarm go off at roughly 6am..."
	sleep(4)

	print "you feel groggy and tired still. for some reason..."
	sleep(4)

	print "YOU CAN'T REMEMBER WHO YOU ARE, WHERE YOU",
	print "ARE OR WHAT YOU'RE DONIG THERE!!!"
	sleep(4)
	print "[que cheesy mystery music] Dun dun DUN!"
	sleep(3)

	choice=getchoice(
		"what shall it be, O ye of no name?",
		 ["get up, in spite of the fact that you feel dead",
		  "just hit the snooze alarm...c'mon, just five more minutes...",
		  """ ignore it. sleep through it. it's not so bad. it's quite soothing,
			really."""]

	if choice == "1": return fryingpan
	elif choice == "2": return snooze
	elif choice == "3": return sleepthru

def fryingpan():
	# add your stuff about frying pan here...

def snooze():
	# stuff about snooze
		

def sleepthru():
	# stuff about sleepthru...


currentroom=bedroom # note the lack of brackets
					 #this means copy bedroom into currentroom
quit=0
state=["groggy"]
def mainloop():
	while not quit: # the next indented bit will be done until quit == 1
		move=currentroom() # do the thing for this room.  the brackets mean "do it"
		currentroom=move
		if quit:
			really=raw_input("Are you really sure yu want to quit? [Y/n]")
			if really.upper() != "Y":
				quit=0
			else:
				print "Oh, well - if you must.  You'll pay.  You know you will..."

		





More information about the Python-list mailing list