[Tutor] Help with classes
Kevin
python.programming at gmail.com
Thu Apr 7 19:23:04 CEST 2005
I am fooling around with classes and I was trying to create a very
small one player text adventure. I made a class called commands here
it is:
class Commands:
def __init__(self):
pass
def quiting(self):
sys.exit()
def look(self):
print "\nNot working yet!\n"
def get(self):
print "\nNot working yet!\n"
def take(self):
print "\nNot working yet!\n"
def kill(self):
print "\nNot working yet!\n"
def drink(self):
print "\nNot working yet!\n"
def eat(self):
print "\nNot working yet!\n"
def eq(self):
print "\nNot working yet!\n"
def helpsys(self,response):
answer = None
i = ['look','get','take','kill','drink','eat','eq','help']
while not answer in i:
answer = raw_input(response)
#Help files will go here
return answer
there is nothing special about it yet. But in the main code wich is:
while 1:
com = Commands()
a = ['look',
'get',
'take',
'kill',
'drink',
'eat',
'eq',
'help',
'quit']
commandl = raw_input(">>>: ")
if commandl not in a:
print "\nI don't understand that command?\n"
I want to beable to type in a command from the list at the prompt and
have it call one of the functions from the class. I was looking for a
shorter way to write it but the only way I can think of is with an if
statment for each command. Is there a better way or shorter way to do
this?
Thanks
Kevin
More information about the Tutor
mailing list