Question

I am working on a text adventure in Python. I'm very new to the concept of object oriented programming (and programming in general), so I'm not entirely sure what went wrong. Well, what I've done so far is made two methods; one that handles what the user types in, and one that dictates what will happen in the game, using other methods defining rooms that I will create in the future. One problem I have, though, is that I can't test the program by running it! When I run it, there is no prompt for user input - the program just ends without returning any error. There's not much code so maybe you could help me in determining the problem! I'm sure there's something really obvious in there I've forgotten...

class Main(object):


    def handle_events(self, userinput, cmd):
        self.userinput = userinput
        self.cmd = cmd
        userinput = raw_input('> ')
        cmd = {'use' : use,'quit' : quit, 'help' : help}
        if userinput[0] not in cmd:
            print "Invalid command. Check [help] for assistance."





    def main(self, handle_events):

        print '''You are in a dark room filled with
                strange and ominous objects.

                After some feeling around, you think
                you can make out a light switch.'''

        self.userinput
        if userinput[1] == 'switch':
            print "You flicked the switch!"


Main().main
Was it helpful?

Solution

You are not calling your method. Main().main is just a reference to the method. To call it you need another set of parentheses: Main().main().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top