Permalink
Browse files

Comitted main.py which I totally forgot last commit. Whatever I said …

…in my last commit is now true.
  • Loading branch information...
1 parent e41cd43 commit 65fef6b6439e1b07263989b704e20bdf61dd432d @kallepersson kallepersson committed May 5, 2009
Showing with 43 additions and 8 deletions.
  1. +43 −8 main.py
View
51 main.py
@@ -2,18 +2,21 @@
import cmd
import string, sys
-class Person():
- def __init__(self,name,topics={}):
- self.name = name
- self.topics = topics
- #etc
-
class Topic():
def __init__(self,name,reply):
self.name = name
self.reply = reply
self.status = ""
- #etc
+
+class Person():
+ def __init__(self,name,topics={}):
+ self.name = name
+ self.topics = {}
+ for topic in topics:
+ self.addTopic(topic)
+
+ def addTopic(self,topicObject):
+ self.topics[topicObject.name.lower()] = topicObject
class Action():
def __init__(self,type,response=None):
@@ -90,6 +93,7 @@ def __init__(self,name):
self.triggers["activate"] = {}
self.triggers["set"] = {}
self.objects = {}
+ self.people = {}
def __get__(self,var):
if var in self.objects:
@@ -105,6 +109,11 @@ def addObject(self,objectObject):
objectObject.room = self
self.objects[objectObject.name] = objectObject
+ def addPerson(self,personObject):
+ personObject.room = self
+ self.people[personObject.name] = personObject
+ print "Added",personObject.name,"to",self.name
+
def setObjectVisibility(self,objectName,visible=True):
if objectName in self.objects:
self.objects[objectName].visible = visible
@@ -252,6 +261,30 @@ def do_use(self,useString):
else:
print "You can't use what you don't have"
+ def do_ask(self,askString):
+ askString = askString.lower()
+ askPerson = None
+ askTopic = None
+
+ if "about" in askString:
+ for person in self.currentRoom.people:
+ if askString.startswith(person.lower()):
+ askPerson = self.currentRoom.people[person]
+
+ if askPerson != None:
+
+ for topic in askPerson.topics:
+ if askString.endswith(topic.lower()):
+ askTopic = askPerson.topics[topic]
+ else:
+ print "Hm, what?"
+ return
+
+ if askPerson != None and askTopic != None:
+ print askTopic.reply
+ else:
+ "Nope."
+
def do_quit(self, arg):
exit("Bye!")
@@ -291,6 +324,8 @@ def do_dump(self, arg):
Restroom.addObject(restroomToothpaste)
Restroom.exits["west"] = "Cellar"
+Jeff = Person("Jeff",[Topic("foo","bar!")])
+Cellar.addPerson(Jeff)
Game = Game()
Game.inventory = Inventory()
@@ -300,4 +335,4 @@ def do_dump(self, arg):
Game.addRoom(Restroom,"Restroom");
Game.start("Cellar")
-
+a

0 comments on commit 65fef6b

Please sign in to comment.