Main      Site Guide    
Message Forum
Re: Python Question
Posted By: Don the Monkeyman, on host 24.79.11.42
Date: Saturday, June 29, 2002, at 16:02:41
In Reply To: Re: Python Question posted by Sam on Wednesday, June 19, 2002, at 17:09:41:

> # Program starts here, with a new game.
> location = 'start'
> inventory = ['sack']
> won_the_game = 0
>
> while (not won_the_game):
> ____ print_location_description(location)
> ____ do_menu(location)
>
> print "You won the game! Congratulations!"
>
> def print_location_description(location):
> ____ if location == 'start':
> ________ print "You are at the start."
> ________ if not 'gold' in inventory:
> ____________ print "There is gold here!"
> ____ elif location == 'carnival':
> ________ print "You are at the carnival!"
> ________ print "What next?"
> ____ elif location == 'store':
> ________ print "You are at the store!"
> ____ else:
> ________ print "Uh oh! You found a bug, because"
> ________ print "you're somewhere I don't know."
>
> def do_menu(location):
> ____ if location == 'start':
> ________ do_start_menu()
> ____ elif location == 'carnival':
> ________ do_carnival_menu()
> ____ elif location == 'store':
> ________ do_store_menu()
> ____ else:
> ________ print "Whoopsie."
>
> def do_start_menu():
> ____ print "1. Go north."
> ____ print "2. Go south."
> ____ print "3. Look at your inventory."
> ____ if not 'gold' in inventory:
> ________ print "4. Take the gold!"
> ____ choice = raw_input("Enter your choice: ")
> ____ if choice == '1':
> ________ print "You go north."
> ________ location = 'carnival'
> ____ elif choice == '2':
> ________ print "You go south."
> ________ location = 'store'
> ____ elif choice == '3':
> ________ print "Your inventory: " + `inventory`
> ____ elif choice == '4' and not 'gold' in inventory:
> ________ print "You take the gold."
> ________ inventory.append('gold')
> ____ else:
> ________ print "You picked an incorrect option!"
> ________ print "Try again!"
>
> .
> .
> .
>

After reading this entire thread, I feel pretty comfortable with Python. I understand namespaces, thanks to perl, and I'm getting pretty good at the idea of Object-Oriented design (although I need some practical work on that.) I understand the idea of identifying the variables as global in each function, and I can see why using "GOTO"-type statements is a bad idea. Still, I am left with one burning question. How on earth are you supposed to win this game? I see that the code is intentionally incomplete, but I need closure here!

Replies To This Message

Post a Reply

RinkChat Username:
Password:
Email: (optional)
Subject:
Message:
Link URL: (optional)
Link Title: (optional)

Make sure you read our message forum policy before posting.