Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: New to Python...feedback? (http://www.velocityreviews.com/forums/t318759-re-new-to-python-feedback.html)

Andy Jewell 06-23-2003 08:40 PM

Re: New to Python...feedback?
 
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..."





All times are GMT. The time now is 12:54 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


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