|
re:
Thanks for the help guys. Here's where I am now. There is some erroneous code - just some things I've played around with. The things I'm trying to do now is set up a sort of commands database so that I don't have to have a billion if statements like
if choice == "examine head":
print foyer.items["head"]
That' fine for a room with only one object, but if I have a room with multiple objects, it could really start to pile up on me. I'm trying to think of the logic behind it - having all of my interact able objects in a dictionary or something, then having key words like EXAMINE, LOOK, TAKE, etc. Then the if statement could look along these lines:
if choice == "examine", object:
print <something>
I don't have my mind wrapped around how to do this yet.
Anyhow, here's the code for where I am:
[PHP]class Room(object):
def __init__(self, description):
self.description = description
self.exits = {}
self.items = {}
class Player(object):
def __init__(self, room):
self.room = room
def look(self):
print self.room.description
def examine(self):
print self.room.items
def move(self, direction):
if direction in self.room.exits:
self.room = self.room.exits[direction]
me.look()
else:
print "You cannot go in that direction."
#class Examines(object):
# def __init__(self, name, description):
# self.description = description
# self.name = name
foyer = Room("""
You are in the foyer of the house. The air is thick with death here.
Humidity has already caught the death stench and it permeates the house.
The house is dark. On the wall beside the entrance is a light switch.
Directly in front of you is a passage way leading deeper into the house.
At the far end of the passage way is a window, which allows a bit of
moonlight to shine into the darkness. On the left and right sides of the
hallway are small tables. Sitting on the right-hand table is the smiling
head of an elderly man, and he seems to be looking at you.
""")
kitchen = Room("You are in a dark kitchen...")
foyer.exits["west"] = kitchen
kitchen.exits["east"] = foyer
# head = Examines("head", "you see a head...")
foyer.items = {"head":"you see a head..."}
me = Player(foyer)
while True:
choice = raw_input("What would you like to do? ").lower()
if choice == "look":
me.look()
elif choice == "examine head":
print foyer.items["head"]
else:
me.move(choice)
[/PHP]
I know for those of you who are experienced in OOP it seems like I only added one thing. However, that one thing took me most of the day testing and playing around with different options to finally get an object to properly react to examination. I'll pick up steam as we go.
Last edited by nisim777; Oct 6th, 2007 at 7:40 PM.
|