Esempio n. 1
0
 def choice(self, msg, choices, window=False):
     choicerange = range(len(choices))
     for i in choicerange:
         output("[yellow]%d: [reset]%s" % (i + 1, choices[i]), dict=False)
     while True:
         output(msg + "  ", dict=False)
         choic = pelt.str_to_int(inputfd.read(), default=0)
         if choic - 1 not in choicerange:
             continue
         if choices[choic - 1] == m("quit") or choices[choic - 1] == m("back") or choices[choic - 1] == m("cancel"):
             return 0
         return choices[choic - 1]
Esempio n. 2
0
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')
Esempio n. 3
0
def action(msg, addon=None, s=0):
	output('[red]'+m(msg, color=True), dict=False, addon=None, s=s)
Esempio n. 4
0
	def get_var(var):
		if var == 'all': return m('playerdesc') %(self.name, self.last, self.gender, self.species, self.inventory, self.location, self.level, self.attacks)
		else:
			try: return self.__getattribute__(var)
			except AttributeError: return None
Esempio n. 5
0
	def __init__(self, name, level, life, attk=25, dfns=25, type='Normal', attacks=[], color='yellow'):
		self.type = type
		self.attacks = [Attack(m('attack1'), m('attack1desc'), 20, 0, m('type1'))]
		for attack in attacks: self.attacks.append(attack)
		Entity.__init__(self, name, level, life, attk, dfns, color=color)
Esempio n. 6
0
	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)
Esempio n. 7
0
 def choice(self, msg, choices, window=False):
     strings = [str(c) for c in choices]
     if config.ios:
         temp = strings[-1]
         if temp == m("quit") or temp == m("back") or temp == m("cancel"):
             strings.remove(temp)
         try:
             if len(strings) == 1:
                 choice = console.alert(msg, "", strings[0])
             elif len(strings) == 2:
                 choice = console.alert(msg, "", strings[0], strings[1])
             elif len(strings) == 3:
                 choice = console.alert(msg, "", strings[0], strings[1], strings[2])
             else:
                 waiting = True
                 page = 1
                 while waiting:
                     try:
                         b = 2
                         choice = console.alert(
                             msg, "", strings[0 + (page - 1) * 2], strings[1 + (page - 1) * 2], "Next Page"
                         )
                     except IndexError:
                         b = 1
                         try:
                             choice = console.alert(msg, "", strings[0 + (page - 1) * 2], output("next", r=1))
                         except IndexError:
                             page = 0
                             choice = 1 + b
                         except KeyboardInterrupt:
                             return 0
                     except KeyboardInterrupt:
                         return 0
                     if choice == 1 + b:
                         if page <= len(strings) // 2:
                             page += 1
                         else:
                             page = 1
                     else:
                         number = choice + (page - 1) * 2
                         waiting = False
             number = choice
         except KeyboardInterrupt:
             return 0
     else:
         if not window:
             choice = easygui.buttonbox(
                 msg=msg, title="PELT Engine - " + pelt.gametitle + " v" + str(pelt.version), choices=strings
             )
             i = 1
             for c in strings:
                 if choice == c:
                     number = i
                 else:
                     i += 1
         else:
             choice = dm(pelt.screen, strings, pelt.width // 2, pelt.height // 2, None, 32, 1.4, GREEN, PURPLE) + 1
     temp = str(choice)
     if temp == m("quit") or temp == m("back") or temp == m("cancel"):
         return 0
     return choices[number - 1]
Esempio n. 8
0
def normOutput(
    msg,
    dict=True,
    newline=True,
    noscroll=False,
    addon=None,
    addonfromdict=False,
    modifier="normal",
    ignorecolor=False,
    noreset=False,
    r=0,
    s=0,
):
    if not noreset:
        makeColor("reset")
    # modifier = caps, title, lower, normal (when modifier isn't present)
    try:
        if dict:
            msg = m(msg, color=not ignorecolor)
    except KeyError:
        if msg == "":
            pass
        else:
            msg = "WARNING: " + msg + " is not a valid keyword."
    if addon:
        try:
            msg = msg % addon
        except TypeError:
            msg = 'Hey, this message is broken.  Tried to print "%s" and add "%s".' % (msg, addon)
    if modifier == "caps":
        msg = msg.upper()
    elif modifier == "title":
        msg = msg.title()
    elif modifier == "lower":
        msg = msg.lower()
    if r == 0:
        style = False
        colour = ""
        for c in msg:
            if not ignorecolor:
                if c == "[":
                    style = True
                elif c == "]":
                    style = False
                    if config.color:
                        makeColor(colour)
                    colour = ""
                elif style:
                    colour += c

                else:  # if not style and c != "]":
                    outputfd.write(c)
                    if not noscroll:
                        outputfd.flush()
                        time.sleep(config.scroll)

            else:
                outputfd.write(c)
                if not noscroll:
                    outputfd.flush()
                    time.sleep(config.scroll)

        if newline:
            outputfd.write("\n")
        if not noreset:
            makeColor("reset")
        outputfd.flush()
        time.sleep(s)
    elif r == 1:
        raise OutputReturnError(
            "ERROR: You are still using output(..., r=1) in your code.  Please use m(<type 'str'>) in its place."
        )