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) |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor