TextWorldAdventure.py
def load(fname):
    '''
    returns a complete new World after reading information from the textfile fname
    (Str).
    load: Str -> World
    
    '''
    ww = open(fname, "r")
    next_line_str = ww.readline()
    ret = {}
    rooms_list = []
    player = Player(id)
    while next_line_str != '':
        split_list = next_line_str.split()
        if "thing" in split_list[0]:
            method = Thing(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            ret[method.id] = method 
        elif 'room' in split_list[0]:
            method = Room(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            next_line_str = ww.readline()
            content_list = next_line_str.split()
            if len(content_list) >= 2:
                i = 1 
                while i < len(content_list):
                    intnum = int(content_list[i][1:])
                    for item in ret:
                        if item == intnum:
                            method.contents.append(ret[item])
                    i += 1
            ret[method.id] = method 
            rooms_list.append(method)
        elif 'player' in split_list[0]:
            method = Player(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            next_line_str = ww.readline()
            inventory_list = next_line_str.split()
            if len(inventory_list) >= 2:
                i = 1 
                while i < len(inventory_list):
                    intnum = int(inventory_list[i][1:])
                    for item in ret:
                        if item == intnum:
                            method.inventory.append(ret[item])
                    i += 1
            next_line_str = ww.readline()
            location_list = next_line_str.split()
            for item in ret:
                if int(location_list[1][1:]) == item:
                    method.location = (ret[item])
            ret[method.id] = method 
            player = method
        elif 'keyexit' == split_list[0]:
                    exit_list = next_line_str.split()
                    next_line_str = ww.readline()
                    exit_list2 = next_line_str.split()
                    method = Exit(' '.join(exit_list[3:]),ret[int(exit_list[2][1:])]) 
                    method.key = ret[int(exit_list2[0][1:])]
                    method.message = " ".join(exit_list2[1:])
                    for item in list(ret.keys()):
                        if int(exit_list[1][1:]) == item:
                            ret[item].exits.append(method)          
        elif 'exit' in split_list[0]:
            exit_list = next_line_str.split()
            method = Exit(' '.join(exit_list[3:]),ret[int(exit_list[2][1:])])
            for item in list(ret.keys()):
                if int(exit_list[1][1:]) == item:
                    ret[item].exits.append(method)
        next_line_str = ww.readline()
    new_World = World(rooms_list,player)
    return new_World

    returns a complete new World after reading information from the textfile fname
    (Str).
    load: Str -> World
    
    
returns a complete new World after reading information from the textfile fname
(Str).
load: Str -> World
returns a complete new World after reading information from the textfile fname ( Str ) . load : Str - > World
def load(fname):
    ww = open(fname, "r")
    next_line_str = ww.readline()
    ret = {}
    rooms_list = []
    player = Player(id)
    while next_line_str != '':
        split_list = next_line_str.split()
        if "thing" in split_list[0]:
            method = Thing(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            ret[method.id] = method 
        elif 'room' in split_list[0]:
            method = Room(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            next_line_str = ww.readline()
            content_list = next_line_str.split()
            if len(content_list) >= 2:
                i = 1 
                while i < len(content_list):
                    intnum = int(content_list[i][1:])
                    for item in ret:
                        if item == intnum:
                            method.contents.append(ret[item])
                    i += 1
            ret[method.id] = method 
            rooms_list.append(method)
        elif 'player' in split_list[0]:
            method = Player(int(split_list[1][1:]))
            method.name = " ".join(split_list[2:])
            method.description = ww.readline().strip()
            next_line_str = ww.readline()
            inventory_list = next_line_str.split()
            if len(inventory_list) >= 2:
                i = 1 
                while i < len(inventory_list):
                    intnum = int(inventory_list[i][1:])
                    for item in ret:
                        if item == intnum:
                            method.inventory.append(ret[item])
                    i += 1
            next_line_str = ww.readline()
            location_list = next_line_str.split()
            for item in ret:
                if int(location_list[1][1:]) == item:
                    method.location = (ret[item])
            ret[method.id] = method 
            player = method
        elif 'keyexit' == split_list[0]:
                    exit_list = next_line_str.split()
                    next_line_str = ww.readline()
                    exit_list2 = next_line_str.split()
                    method = Exit(' '.join(exit_list[3:]),ret[int(exit_list[2][1:])]) 
                    method.key = ret[int(exit_list2[0][1:])]
                    method.message = " ".join(exit_list2[1:])
                    for item in list(ret.keys()):
                        if int(exit_list[1][1:]) == item:
                            ret[item].exits.append(method)          
        elif 'exit' in split_list[0]:
            exit_list = next_line_str.split()
            method = Exit(' '.join(exit_list[3:]),ret[int(exit_list[2][1:])])
            for item in list(ret.keys()):
                if int(exit_list[1][1:]) == item:
                    ret[item].exits.append(method)
        next_line_str = ww.readline()
    new_World = World(rooms_list,player)
    return new_World
def load ( fname ) : ww = open ( fname , "r" ) next_line_str = ww . readline ( ) ret = { } rooms_list = [ ] player = Player ( id ) while next_line_str != '' : split_list = next_line_str . split ( ) if "thing" in split_list [ 0 ] : method = Thing ( int ( split_list [ 1 ] [ 1 : ] ) ) method . name = " " . join ( split_list [ 2 : ] ) method . description = ww . readline ( ) . strip ( ) ret [ method . id ] = method elif 'room' in split_list [ 0 ] : method = Room ( int ( split_list [ 1 ] [ 1 : ] ) ) method . name = " " . join ( split_list [ 2 : ] ) method . description = ww . readline ( ) . strip ( ) next_line_str = ww . readline ( ) content_list = next_line_str . split ( ) if len ( content_list ) >= 2 : i = 1 while i < len ( content_list ) : intnum = int ( content_list [ i ] [ 1 : ] ) for item in ret : if item == intnum : method . contents . append ( ret [ item ] ) i += 1 ret [ method . id ] = method rooms_list . append ( method ) elif 'player' in split_list [ 0 ] : method = Player ( int ( split_list [ 1 ] [ 1 : ] ) ) method . name = " " . join ( split_list [ 2 : ] ) method . description = ww . readline ( ) . strip ( ) next_line_str = ww . readline ( ) inventory_list = next_line_str . split ( ) if len ( inventory_list ) >= 2 : i = 1 while i < len ( inventory_list ) : intnum = int ( inventory_list [ i ] [ 1 : ] ) for item in ret : if item == intnum : method . inventory . append ( ret [ item ] ) i += 1 next_line_str = ww . readline ( ) location_list = next_line_str . split ( ) for item in ret : if int ( location_list [ 1 ] [ 1 : ] ) == item : method . location = ( ret [ item ] ) ret [ method . id ] = method player = method elif 'keyexit' == split_list [ 0 ] : exit_list = next_line_str . split ( ) next_line_str = ww . readline ( ) exit_list2 = next_line_str . split ( ) method = Exit ( ' ' . join ( exit_list [ 3 : ] ) , ret [ int ( exit_list [ 2 ] [ 1 : ] ) ] ) method . key = ret [ int ( exit_list2 [ 0 ] [ 1 : ] ) ] method . message = " " . join ( exit_list2 [ 1 : ] ) for item in list ( ret . keys ( ) ) : if int ( exit_list [ 1 ] [ 1 : ] ) == item : ret [ item ] . exits . append ( method ) elif 'exit' in split_list [ 0 ] : exit_list = next_line_str . split ( ) method = Exit ( ' ' . join ( exit_list [ 3 : ] ) , ret [ int ( exit_list [ 2 ] [ 1 : ] ) ] ) for item in list ( ret . keys ( ) ) : if int ( exit_list [ 1 ] [ 1 : ] ) == item : ret [ item ] . exits . append ( method ) next_line_str = ww . readline ( ) new_World = World ( rooms_list , player ) return new_World
returns a complete new World after reading information from the textfile fname
(Str).
returns a complete new World after reading information from the textfile fname ( Str ) .
'''
    returns a complete new World after reading information from the textfile fname
    (Str).
    load: Str -> World
    
    '''
fname