I've been trying to make an open-ended text adventure. I tried to set up nine rooms that you can move around in, but I think the way I did it is not possible in python. Is there any similar way I could do it? A workaround? Here's the code: (By the way I know there is no way for the user to interact yet)
class Room:
def __init__(self, north, east, south, west, desc):
self.north = north
self.east = east
self.south = south
self.west = west
self.desc = desc
loc1 = Room(False, loc2, loc4, False, "You can go east and south")
loc2 = Room(False, loc3, loc5, loc1, "You can go east, south, and west")
loc3 = Room(False, False, loc6, loc2, "You can go west and south")
loc4 = Room(loc1, loc5, loc7, False, "You can go north, east, and south")
loc5 = Room(loc2, loc6, loc8, loc4, "You are in the center room, with paths in all directions")
loc6 = Room(loc3, False, loc9, loc5, "You can go north, west, and south")
loc7 = Room(loc4, loc8, False, False, "You can go north and east")
loc8 = Room(loc5, loc9, False, loc7, "You can go north, east, and west")
loc9 = Room(loc6, False, False, loc8, "You can go north and west")
location = loc5
def Interpret(b):
global location
if b == 'help':
print('To move around, type north, south, east and west. Make sure it\'s all in lowercase, so that the game can understand.')
elif b == 'north':
if location.north == False:
print("You can't go that way.")
else:
location = location.north
elif b == 'east':
if location.east == False:
print("You can't go that way.")
else:
location = location.eastth
elif b == 'south':
if location.south == False:
print("You can't go that way")
else:
location = location.south
elif b == 'west':
if location.west == False:
print("You can't go that way")
else:
location = location.west