#Creatures_Class############################################################################################# class creature: def __init__ (self, name, adj = []): #create a creature with NAME and TAG LIST(empty) self.name = name self.adj = adj def tag(self, adj): #adds TAG to TAG LIST self.adj.append(adj) def detag(self, adj): #removes TAG from TAG LIST self.adj.remove(adj) #Actions##################################################################################################### def stab(target): #runs when something is stabbed print 'stab' for i in target.adj: #pulls the TAGs on the target if i != 'tough': #looks for specific TAGs that allow it to be killed print str(target.name) + ' is killed.' #needs to actually kill goblin still target.tag('dead') def talk(target): #run when something is talked to alive = true #assume target is alive for i in target.adj: #check to see if target is dead if i == 'dead': alive = false if alive == true: print 'talk' #talk if target is, in fact, alive (or not dead) #Creature_List############################################################################################### adjs = [] PC = creature('PC', adjs) #create PC adjs = ['happy'] goblin = creature('goblin', adjs) #create goblin(creature) #Dictionarys################################################################################################# defs = { #super freaking important. All VERBs must be in here to work. 'stab' : stab, 'talk' : talk } nouns = { #nouns 'goblin' : goblin, 'PC' : PC } #Action_and_Target_Lists##################################################################################### actions = ['talk', 'stab'] #available ACTIONS (needs to be turned into real code) targets = ['goblin', 'PC'] #available TARGETS (needs to be turned into real code) print actions print targets #Player_Input################################################################################################ verb = raw_input() #player input noun = raw_input('Enter an action and target: ') print verb + ' ' + noun for i in actions: #checks input against available actions list if verb == i: defs[verb](nouns[noun]) #calls def based on verb, but it must be in defs(dictionary)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question