1

I am working on a text-based adventure game in python. Right now I have it so that the main game loop always prints "What do you want to do?" and splits the input into individual words.

I have an action called check (also examine, observe, look, etc.) which, if that word is in the input will check all of the items I have described in the dictionary and print the item's description if it finds one.

How can I make it so that if none of the words the user inputs are in the dictionary it prints a specific message?

#The dictionary of objects
objects = { #BUNCH OF DICTIONARY ENTRIES }
#The dictionary of checkable things other than the object list
check_dic = [{ #DICTIONARY },
             { #ANOTHER DICTIONARY },
             { #AND SO ON },
             { #AND SO FORTH}]

direct_dic = [{ #ANTOTHER LIST OF DICTIONARIES}]

#The beginning of the game.
print("Awaken adventurer, your journey begins here. What is your name?")
name = input('Enter your name:') #Sets the player's name.
print("Greetings, ", name, ". \nYou awaken in an unknown location equipped with only your trusty dagger, a strange vial, and a small pouch of gold coins.", sep= '')

player = "alive"
playerlocation = "room_1"
door1_state = "locked"
drawer_state = "locked"
trunk_state = "locked"
doorway_state = "locked"
plaque_state = "concealed"
bottle = "empty"
void_puzzle = 0
actions = ["check", "get", "drop", "use", "open", "orient", "go", "record", "read", "debugwarp"]
synonyms = ["look", "take", "examine", "observe", "pickup", "discard", "move"]

#The stone pile
s = 0

while player == "alive" and void_puzzle != "solved":
    #print(playerlocation) #this is for checking what room the player is in at any time
    if playerlocation == "room_1": #starting room
        dictionary = check_dic[0]
        items = items_in_room[0]
        hidden = hidden_items[0]
        directs = direct_dic[0]
        orientation = orientations[0]
    elif playerlocation == "room_2": #the rift room
        dictionary = check_dic[1]
        items = items_in_room[1]
        hidden = hidden_items[1]
        directs = direct_dic[1]
        orientation = orientations[1]
    #THERE'S A BUNCH OF LINES OMITTED THAT DO THE SAME THING FOR ALL OF THE OTHER ROOMS.
    print("What do you want to do?")
    userinput = input()
    userinput = userinput.lower()
    words = userinput.split()
    if actions[0] in words or synonyms[0] in words or synonyms[2] in words or synonyms[3] in words:
        for a in dictionary:
            if a in words:
                if a in dictionary:
                    if a == "drawer":
                        #A BUNCH OF STUFF RELATED SPECIFICALLY TO THE DRAWER
                    elif a == "desk":
                        #LIKEWISE
                    elif a == "trunk":
                        #ETC ETC THERE'S A BUNCH OF SPECIAL CASES HERE
                    else:
                        print(dictionary[a])
        for b in objects:
            if b in words:
                if b in inventory:
                    print(objects[b])
                else:
                    print("You can't check something you don't have.")

To put it simply: I want it so that if the words are checked and the input contains nothing that's either in the dictionary or in objects that it prints a line like "What exactly are you trying to check?"

Is there any way to do that?

  • If you get each action to `continue`, you should be able to simply place that after the for loops... – Shadow Mar 10 '17 at 06:01
  • @shadow I tried doing that before but what happens is that it always prints "What exactly are you trying to check?" no matter what I enter. – John Hedlund-Fay Mar 12 '17 at 06:55

0 Answers0