Пример #1
0
    def ask(self, question, answers, prompt='> '):
        """Function to ask and process a question, 'answers' should be in a
        list object"""
        printme = question + '\n'

        # displays answers
        for i in xrange(0, len(answers)):
            printme += '[%(i)i] %(answer)s' % \
                {'i': i+1, 'answer': answers[i]} + '\n'

        printer.display(printme)

        # interprets the user's response, a valid response can be the integer
        # of the answer's position, OR the full answer typed out.
        while True:
            response = raw_input(prompt)

            try:
                if int(response)-1 < len(answers) and int(response) >= 0:
                    tools.clear(1)
                    return int(response)-1
            except ValueError:
                pass

            for i in xrange(0, len(answers)):
                if answers[i].lower().strip() == response.lower().strip():
                    tools.clear(1)
                    return i

            print self.invalid
Пример #2
0
    def scenario(self):
        printer.display("OH NOES! SNAKES ARRIVED ON YOUR BOAT!")

        response = self.ask('How to unsnake the boat?',
                            ['Yell at them', 'Eat them'])

        if response == 0:
            print "You yell as loud as you can, the snakes don't understand \
                   fleshbag. [-10 health]"
            carmine.change(hp=-10)
        elif response == 1:
            print "You ate ALL the snakes, looks like you wiggled your way \
                   out of this one. [+2 food]"
            carmine.change(food=2)
        else:
            self.error()