[Tutor] (no subject)
david
din22 at earthlink.net
Mon Dec 5 14:42:34 CET 2005
hello everyone, and thanks for your help and guidance so far.
amazingly enough, something i thought would be simple has turned out to be not simple.
i have a sword that i want to wield. as i have it here, i think i am wielding whatever string i type
as argument to wield. so i guess i need to pass wield an object somehow instead of a string.
can anyone point in the right direction?
class Player:
def __init__(self,name):
self.name = name
self.location = None
self.inventory = []
self.wielded = None
self.headwear = None
def wield(self,what):
print type(what)
print 'you wield',what
self.wielded = what
def do(self):
cmd = string.split(raw_input('>'))
verb = cmd[0]
if len(cmd) > 1:
target = cmd[1]
if verb == 'l':
self.look()
elif verb in ['n','s','e','w']:
self.move(verb)
elif verb == 'quit':
sys.exit()
elif verb == 'i':
print 'wielded',self.wielded
print 'on head', self.headwear
for a in self.inventory:
print a.name
elif verb == 'wield':
self.wield(target)
else:
print 'what?'
class Thing:
def __init__(self,name):
self.name = name
self.uponwield = ''
p = Player('david')
sord = Thing('sword')
sord.uponwield = 'the sword glows '
hat = Thing('hat')
p.inventory.append(sword)
p.inventory.append(hat)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051205/517ef96e/attachment.html
More information about the Tutor
mailing list