Exemple #1
0
def test_creatures_5():
    '''
    Online is on the north of USYD, so that there exits a path between them. 
    The student is originally at the USYD, but he moves north to online.
    Make sure the current location of the student is online 
    '''
    online = Location("online")
    USYD = Location("USYD")
    USYD.add_path("north", online)
    me = Creature("Me", 5, USYD, "INFO1110 student")
    USYD.add_creature(me)
    me.get_location().remove_creature(me)
    paths = me.get_location().get_paths()
    me.set_location(paths.get("north"))
    me.get_location().add_creature(me)
    assert me.get_location() == online, "Test 5 failed."
    print("Test 5 passed!")
Exemple #2
0
def process_locations(source):
    locs = []
    try:
        with open(source) as file:
            lines = file.readlines()
            if len(lines) == 0:
                print("The game cannot run without any rooms :(")
                exit()

            for line in lines:
                # Each parameter is seperate by >
                info = line.split(" > ")
                # Make sure the info has three elements, otherwise, pass to exception
                if len(info) == 3:
                    start_name = info[0]
                    dire = info[1]
                    dest_name = info[2].strip()

                    # Look for the location in the list, return false if not
                    start_location = look_for_loc(start_name, locs)
                    dest_location = look_for_loc(dest_name, locs)

                    # Add location into the list if it not already in it
                    if not start_location:
                        start_location = Location(start_name)
                        locs.append(start_location)
                    if not dest_location:
                        dest_location = Location(dest_name)
                        locs.append(dest_location)

                    # Add path to a list of paths
                    start_location.add_path(dire, dest_location)

    except FileNotFoundError:
        print("You have specified an invalid configuration file.")
        exit()
    return locs