MU* style movement with recursion

 avatar
c0dezer019
python
2 months ago
670 B
2
Indexable
Never
rooms = {
    "Bridge": {
        "aft": "Turbolift",
        "port": "Ready Room"
        },
    "Ready Room": {
        "starboard": "Bridge"
    },
    "Turbolift": {
        "forward": "Bridge"
    }
}

current_loc = rooms['Bridge']


def movement(direction):
    global current_loc

    while direction != '.exit':
        if direction in current_loc.keys():
            new_loc = current_loc[direction]
            current_loc = rooms[new_loc]

            print(f'you are now in the {new_loc}')
        else:
            print("You are unable to go there.")

        direction = input('Move: ')
        movement(direction)


move = input('Move: ')
movement(move)
Leave a Comment