[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Text-Based RPG



I've been away from Python for several months. I just came back to it, to start working on a text-based RPG. To get started, I decided to move by rooms. I have separate text files for each major message, to conserve file space. What troubles me is that when I tested it, whenever I enter anything into the command line, it says 'Invalid command' which I included as an error message. Here is where I think the trouble is:

def command_line():
    command = raw_input('>>> ')
def command(command, current_room):
    if current_room == anthro_tavern:
        if command == 'north':
print '\n\nThat room does not exist yet. Please try again.\n\n'
        elif command == 'south':
print '\n\nThat room does not exist yet. Please try again.\n\n'
        elif command == 'down':
            print 'That room does not exist yet. Please try again./n/n'
        elif command == 'talk to garrick':
            speech = open('garricks_speech.txt', 'r')
            print speech.read()
            speech.close()
        elif command == 'talk to janet':
            speech = open('janets_speech.txt', 'r')
            print speech.read()
            speech.close()
        elif command == 'talk to stranger':
            print 'This feature is coming soon.'
        else:
            print 'Invalid command.'
        anthro_tavern()
    else:
print 'Error 1: Non existent room being requested/nfrom. If this error appears, something/nis very wrong.'
def anthro_tavern():
    text_file = open("swamp_tavern.txt", "r")
    print text_file.read()
    text_file.close()
    command(command_line(), anthro_tavern)
    return current_room

anthro_tavern()

I originally had different commands for each action, with variations on capitalization so you didn't have to enter the same command every time, but then all it did was the message for the first 'if' line. Does anyone see a problem with this?