def getCommand(sentence): ''' Read a command from the user and parse it. This parser understands some simple sentences: * just a verb: 'quit' * verb followed by a noun: 'eat sandwich' * verb noun 'with' noun: 'kill monster with sword' Return a dictionary of the parsed words, or None if the command couldn't be parsed. ''' cmnd = {} if sentence == None: return None words = sentence.lower().split() if len(words) == 0: return None cmnd['verb'] = words[0].lower() if len(words) > 1: cmnd['noun'] = words[1].lower() if len(words) > 2: if words[2] == output('with', r=1) or words[2] == output('using', r=1): if len(words) > 3: cmnd['using'] = words[3] else: output('usingerror', addon=[verb, noun]) return None else: cmnd['extra'] = words[2:] return cmnd
def describe(self, r=False): if r: x = self.name + '\n' else: output(self.name, dict=False) for i in self.items: if r: x += output('itemhere', addon=i, r=1) else: output('itemhere', addon=i) if not config.instmsg: time.sleep(0.1) for d in self.doors: if r: x += output('doorhere', addon=d.direction, r=1) else: output('doorhere', addon=d.direction) if not config.instmsg: time.sleep(0.1) if r == 1: return x
def use(self, attacker, attacked): temp = 1.5 if self.type == attacked.type else 1 dice = random.randint(0,10) if dice <= 1: crit = 0.5 elif dice >= 10: crit = 1.5 else: crit = 1 damage = ((((((self.pwr + attacker.attk)*2)*temp)-(attacked.dfns/1.1))/3)*crit)+(random.randint(0,20)-10) damage = int(damage) attacked.take_damage(damage) output('entityhurt', addon=(str(attacked),str(damage))) crit += 5 if crit == 0.5: output('ineffective') elif crit == 1.5: output('critical')
def sync(vers, officialvers, langversneed, title, auth, modules=[], args=[]): global version, officialversion, langversneeded, gametitle, author, peltvers, size, width, height, screen, myfont version = config.version = vers officialversion = config.officialversion = officialvers langversneeded = langversneed gametitle = config.gametitle = title author = config.author = auth config.args = args #from localio import output, newline, getInput, color #Print the title, author, and version makeColor('reset') output('author', addon=author) output('version', addon=(officialversion, peltvers), s=2) newline() output('title', addon=gametitle, s=3)
def textplay(level): playing = True makeColor('blue') output(level.name, dict=False, s=2) makeColor('reset') output('gamestart') playing=True location = level.rooms[0] location.describe() while playing: output("") cmnd = getCommand(getInput.text('\n'+m('gameaction'))) # single-word commands if not cmnd or cmnd['verb'] == m('quitcmd'): quit(m('quitmsg')) elif cmnd['verb'] == m('savecmd'): save() continue elif cmnd['verb'] == m('loadcmd'): load() continue elif cmnd['verb'] == m('helpcmd'): output('helpquit') output('helpsave') output('helpload') output('helpdescribe') output('helphelp') output('helpexamine') output('helpeat') output('helpdrink') output('helptake') output('helpgo') continue elif cmnd['verb'] == m('describecmd'): location.describe() continue # two-word commands noun = cmnd.get('noun') if not noun: continue if cmnd['verb'] == m('gocmd'): roomname = location.go(noun) if not roomname: output('doormissing') elif roomname == "locked": output('doorlocked') elif roomname == "invalid": output('directionerror') elif roomname == "Finish": quit('broken4') else: i = 0 for r in level.rooms: if r.name == roomname: break else: i += 1 location = level.rooms[i] else: # commands that require an item item = location.findItem(noun) if not item: output('itemerror', addon=noun) elif cmnd['verb'] == m('examinecmd') and hasattr(item, 'examine'): item.examine() elif cmnd['verb'] == m('eatcmd') and hasattr(item, 'eat'): item.eat() elif cmnd['verb'] == m('drinkcmd') and hasattr(item, 'drink'): item.drink() elif cmnd['verb'] == m('takecmd') and hasattr(player, 'take'): player.take(item) elif cmnd['verb'] == m('opencmd') and hasattr(item, 'open'): item.open(player.inventory) else: output('cmderror')
def action(msg, addon=None, s=0): output('[red]'+m(msg, color=True), dict=False, addon=None, s=s)
def speak(self, msg, dict=True, addon=None, s=0, newline=True): if dict: msg = m(msg, color=True) output(self.name+': '+'['+self.color+']'+msg, dict=False, addon=addon, newline=newline, s=s)
def add_attack(self, attack): if type(attack) == Attack: pass else: output('attackerror')
def saveload(save, overwarning=False, overaddon=False): waiting = True while waiting: saves = range(10) saveslist = list(saves) #path = os.path #os.listdir(path) for s in saves: s+=1 try: if pc == 'computer': temp = 'saves/save' else: temp='save' with open(temp+str(s), 'rb') as handle: file = list(pickle.load(handle)) output('save2', addon=[str(s), file[2]], noscroll=True) saveslist[s-1] = output('save2', addon=[str(s), file[2]], r=1) except: if save: output('save1', addon=str(s), noscroll=True) saveslist[s-1] = output('save1', addon=str(s), r=1) output('') if save: choice = getInput.choice(output('save3', r=1),saveslist) else: choice = getInput.choice(output('save4', r=1),saveslist) if choice == 'c': return False choice = str_to_int(choice[4:]) if choice > 0 and choice <= len(saves): if pc == 'computer': response = 'saves/save'+str(choice)+".save" else: response = 'save'+str(choice)+".save" try: with open(response, 'rb') as handle: if handle: overwait = True handle = pickle.load(handle) if save: while overwait: addon = [file[0], file[1], file[2]] overwrite = getInput.choice(output('savewarning', addon=addon, r=1),[output('yes', r=1),output('no', r=1)]) if overwrite == 1: return response elif overwrite == 2: overwait = False else: output('inputerror') else: return response except: return response else: output('saveerror') output('')
def __str__(self): return output('doordesc', r=1, addon=[self.direction,self.room])