Re: New to Python...feedback?

Discussion in 'Python' started by Andy Jewell, Jun 23, 2003.

  1. Andy Jewell

    Andy Jewell Guest

    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..."
    Andy Jewell, Jun 23, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Attenborough
    Replies:
    22
    Views:
    2,252
    Mike Treseler
    Mar 13, 2006
  2. Snuffy
    Replies:
    1
    Views:
    330
    Andrew Thompson
    Apr 9, 2004
  3. Ross Bamford

    New Java CMF wants your feedback!

    Ross Bamford, Apr 24, 2005, in forum: Java
    Replies:
    0
    Views:
    362
    Ross Bamford
    Apr 24, 2005
  4. Richard Thoms
    Replies:
    59
    Views:
    1,374
    Neredbojias
    May 15, 2006
  5. Bruno Desthuilliers
    Replies:
    24
    Views:
    4,020
    Bruno Desthuilliers
    Oct 20, 2008
Loading...

Share This Page