Thread: Why OOP?
View Single Post
Old Oct 6th, 2007, 9:23 AM   #21
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Pretty good, but if you want to label your directions as "w", "e", "n" and "s", why not do something like:

python Syntax (Toggle Plain Text)
  1. foyer.exits["w"] = kitchen
  2. kitchen.exits["e"] = foyer
  3.  
  4. me = Player(foyer)
  5.  
  6. while True:
  7. choice = raw_input("What would you like to do? ").lower()
  8. if choice == "look":
  9. me.look()
  10. else:
  11. me.move(choice)
In other words, you assume that any command that you don't know about is a direction.

You can also have more than one direction leading to the same place:
python Syntax (Toggle Plain Text)
  1. foyer.exits["w"] = kitchen
  2. foyer.exits["west"] = kitchen
  3. foyer.exits["kitchen"] = kitchen
Arevos is offline   Reply With Quote