Ejemplo n.º 1
0
def test_already_exit_already_linked():
    M = GameMaker()
    R1 = M.new_room()
    R2 = M.new_room()
    R3 = M.new_room()

    M.connect(R1.east, R2.west)
    npt.assert_raises(ExitAlreadyUsedError, M.connect, R1.east, R3.west)
Ejemplo n.º 2
0
def build_test_game():
    M = GameMaker()

    # Create a 'bedroom' room.
    R1 = M.new_room("bedroom")
    R2 = M.new_room("kitchen")
    M.set_player(R1)

    path = M.connect(R1.east, R2.west)
    path.door = M.new(type='d', name='wooden door')
    path.door.add_property("open")

    carrot = M.new(type='f', name='carrot')
    M.inventory.add(carrot)

    # Add a closed chest in R2.
    chest = M.new(type='c', name='chest')
    chest.add_property("open")
    R2.add(chest)

    commands = ["go east", "insert carrot into chest"]
    quest1 = M.new_quest_using_commands(commands)
    quest1.reward = 2
    commands = ["go east", "insert carrot into chest", "close chest"]
    event = M.new_event_using_commands(commands)
    quest2 = Quest(win_events=[event])
    M.quests = [quest1, quest2]
    game = M.build()
    return game
Ejemplo n.º 3
0
def test_expecting_door_entity_in_path():
    M = GameMaker()
    R1 = M.new_room()
    R2 = M.new_room()

    path = M.connect(R1.east, R2.west)
    npt.assert_raises(TypeError, setattr, path.door, 'dummy')
Ejemplo n.º 4
0
def test_record_quest_from_commands(play_the_game=False):
    M = GameMaker()

    # The goal
    commands = ["go east", "insert ball into chest"]

    # Create a 'bedroom' room.
    R1 = M.new_room("bedroom")
    R2 = M.new_room("kitchen")
    M.set_player(R1)

    path = M.connect(R1.east, R2.west)
    path.door = M.new(type='d', name='wooden door')
    path.door.add_property("open")

    ball = M.new(type='o', name='ball')
    M.inventory.add(ball)

    # Add a closed chest in R2.
    chest = M.new(type='c', name='chest')
    chest.add_property("open")
    R2.add(chest)

    M.set_quest_from_commands(commands)
    game = M.build()

    with make_temp_directory(
            prefix="test_record_quest_from_commands") as tmpdir:
        game_file = _compile_game(game, folder=tmpdir)

        if play_the_game:
            textworld.play(game_file)
        else:
            agent = textworld.agents.WalkthroughAgent(commands)
            textworld.play(game_file, agent=agent, silent=True)
Ejemplo n.º 5
0
def build_test_game():
    M = GameMaker()

    # The goal
    commands = ["go east", "insert carrot into chest"]

    # Create a 'bedroom' room.
    R1 = M.new_room("bedroom")
    R2 = M.new_room("kitchen")
    M.set_player(R1)

    path = M.connect(R1.east, R2.west)
    path.door = M.new(type='d', name='wooden door')
    path.door.add_property("open")

    carrot = M.new(type='f', name='carrot')
    M.inventory.add(carrot)

    # Add a closed chest in R2.
    chest = M.new(type='c', name='chest')
    chest.add_property("open")
    R2.add(chest)

    quest1 = M.new_quest_using_commands(commands)
    quest1.reward = 2
    quest2 = M.new_quest_using_commands(commands + ["close chest"])
    quest2.set_winning_conditions(
        [M.new_fact("in", carrot, chest),
         M.new_fact("closed", chest)])
    M._quests = [quest1, quest2]
    game = M.build()
    return game
Ejemplo n.º 6
0
def build_test_game():
    M = GameMaker()

    # The goal
    commands = ["go east", "insert carrot into chest"]

    # Create a 'bedroom' room.
    R1 = M.new_room("bedroom")
    R2 = M.new_room("kitchen")
    M.set_player(R1)

    path = M.connect(R1.east, R2.west)
    path.door = M.new(type='d', name='wooden door')
    path.door.add_property("open")

    carrot = M.new(type='f', name='carrot')
    M.inventory.add(carrot)

    # Add a closed chest in R2.
    chest = M.new(type='c', name='chest')
    chest.add_property("open")
    R2.add(chest)

    M.set_quest_from_commands(commands)
    game = M.build()
    return game
Ejemplo n.º 7
0
def test_making_a_small_game(play_the_game=False):
    M = GameMaker()
    # Create a 'bedroom' room.
    R1 = M.new_room("bedroom")
    M.set_player(R1)

    # Add a second room to the east of R1.
    R2 = M.new_room()            # Generated name
    path = M.connect(R1.east, R2.west)  # Undirected path

    # Add a closed door between R1 and R2.
    door = M.new_door(path, name='glass door')
    door.add_property("locked")

    # Put a matching key for the door on R1's floor.
    key = M.new(type='k', name='rusty key')
    M.add_fact("match", key, door)
    R1.add(key)

    # Add a closed chest in R2.
    chest = M.new(type='c', name='chest')
    chest.add_property("closed")
    R2.add(chest)

    # Add a 3 random portable objects in the chest.
    objs = [M.new(type='o') for _ in range(3)]
    chest.add(*objs)

    # Add 3 food objects in the player's inventory.
    foods = [M.new(type='f') for _ in range(3)]
    M.inventory.add(*foods)

    ## Add 10 random objects scattered in the world.
    #M.populate(nb_objects=10)

    game = M.build()
    assert "GameMaker" in game.metadata["desc"]

    with make_temp_directory(prefix="test_making_a_small_game") as tmpdir:
        game_file = _compile_game(game, folder=tmpdir)

        if play_the_game:
            textworld.play(game_file)