Example #1
0
def test_player_interaction1():
    engine = setup()

    try_door_no_key = [
        'take scalpel',
        'go west',
        'go north',
        'go north',
        'look corpse',
        # 'take keycard', # remove this line to attempt opening the locked door without a key
        'go south',
        'go east',
        'go south',
        'take parka',
        'go north',
        'go east'
    ]

    engine.simulate_play(try_door_no_key)

    # this tests to make sure that the player could not open the door ...
    # ... without the key
    assert_equal(engine.player.location.label, 'central_hallway_east')
    assert_equal(engine.player.victory, False)

    # give the player the key and try again
    engine.player.inventory.add(engine.map.all_items['keycard'])

    try_door_with_key = ['go east']

    engine.simulate_play(try_door_with_key)

    assert_equal(engine.player.location.label, 'outside')
    assert_equal(engine.player.victory, False)
Example #2
0
def test_player_interaction5():
    engine = setup()

    obtain_scalpel = ['take scalpel']

    engine.simulate_play(obtain_scalpel)

    # test if the player was able to obtain the parka
    assert_equal(engine.player.inventory.has('scalpel'), True)
Example #3
0
def test_player_interaction2():
    engine = setup()

    obtain_parka = [
        'take scalpel', 'go west', 'go north', 'go north', 'look corpse',
        'take keycard', 'go south', 'go east', 'go south', 'take parka'
    ]

    engine.simulate_play(obtain_parka)

    # test if the player was able to obtain the parka
    assert_equal(engine.player.inventory.has('parka'), True)
Example #4
0
def test_player_interaction3():
    engine = setup()

    obtain_syringe = [
        'take scalpel', 'go west', 'go north', 'go north', 'look corpse',
        'take keycard', 'go south', 'go east', 'go south', 'take parka',
        'go north', 'go east', 'go south', 'look body', 'cut key', 'take key',
        'go north', 'go west', 'go north', 'look fridge', 'take syringe'
    ]

    engine.simulate_play(obtain_syringe)

    # test if the player was able to obtain the parka
    assert_equal(engine.player.inventory.has('syringe'), True)
Example #5
0
def test_win_case2():
    engine = setup()

    # this is a different sequence needed to win the game
    win_case = [
        'take scalpel',
        'go west',
        'go north',
        'go north',
        'look corpse',
        'take keycard',
        'go south',
        'go east',
        'go south',
        'take parka',
        'go north',
        'go east',
        'go south',
        'look body',
        'cut key',
        'take key',
        'go north',
        'go west',
        'go north',
        'look fridge',
        'take syringe',
        'inject self',
        'go south',
        'go west',
        'go west',
        'go south',
        'unlock cylinder',
        'take rod',
        'go north',
        'go east',
        'go east',
        'go west',  # a few extra, unnecessary moves
        'go east',
        'go east',
        'go south',
        'fix snowmobile'
    ]

    # simulate the play
    engine.simulate_play(win_case)

    # see if the player is in the correct room and that they have won the game
    assert_equal(engine.player.location.label, 'garage')
    assert_equal(engine.player.victory, True)
Example #6
0
def test_win_case3():
    engine = setup()

    # this is a third sequence needed to win the game
    win_case = [
        'go west',  # different start move
        'go east',
        'take scalpel',
        'go west',
        'go north',
        'go north',
        'look corpse',
        'take keycard',
        'go south',
        'go east',
        'go south',
        'take parka',
        'go north',
        'go east',
        'go south',
        'look body',
        'cut key',
        'take key',
        'go north',
        'go west',
        'go north',
        'look fridge',
        'take syringe',
        'go south',
        'go west',
        'go west',
        'inject self',  # inject self at different portion of game
        'go south',
        'unlock cylinder',
        'take rod',
        'go north',
        'go east',
        'go east',
        'go east',
        'go south',
        'fix snowmobile'
    ]

    # simulate the play
    engine.simulate_play(win_case)

    # see if the player has won the game
    assert_equal(engine.player.victory, True)
Example #7
0
def test_player_interaction4():
    engine = setup()

    obtain_rod = [
        'take scalpel', 'go west', 'go north', 'go north', 'look corpse',
        'take keycard', 'go south', 'go east', 'go south', 'take parka',
        'go north', 'go east', 'go south', 'look body', 'cut key', 'take key',
        'go north', 'go west', 'go north', 'look fridge', 'take syringe',
        'inject self', 'go south', 'go west', 'go west', 'go south',
        'unlock cylinder', 'take rod'
    ]

    engine.simulate_play(obtain_rod)

    # test if the player was able to obtain the parka
    assert_equal(engine.player.inventory.has('rod'), True)
Example #8
0
def test_non_win_case2():
    engine = setup()

    # this is a third sequence needed to win the game
    win_case = [
        'take scalpel',
        'go west',
        'go north',
        'go north',
        'look corpse',
        'take keycard',
        'go south',
        'go east',
        'go south',
        'take parka',
        'go north',
        'go east',
        'go south',
        'look body',
        'cut key',
        'take key',
        'go north',
        'go west',
        'go north',
        # 'look fridge',        # try to complete the game without getting the syringe
        # 'take syringe',
        'go south',
        'go west',
        'go west',
        'go south',
        'unlock cylinder',
        'take rod',
        'go north',
        'go east',
        'go east',
        'go east',
        'go south',
        'fix snowmobile'
    ]

    # simulate the play
    engine.simulate_play(win_case)

    # see if the player has won the game
    assert_equal(engine.player.victory, True)
Example #9
0
def test_engine():
    engine = setup()
    
    pickup_sequence = [
        'dance', # nonsense command
        'look shoe', #look for non existent item
        'look scalpel', #look for real item
        'take shoe', #take non existent item
        'take scalpel', #take real item
        'inv' #list inventory
        ]
    
    engine.simulate_play(pickup_sequence)
        
    assert_equal(engine.player.inventory.has('scalpel'), True)
    assert_equal(len(engine.player.location.items), 0)
    assert_equal(engine.player.location.label, 'tube_room')
    # scalpel is picked up and no longer present in room
    
    move_and_drop = [
        'n', #move to west hall using short command
        'drop scalpel',
        'go south', # move back to tube room using full command
        'go north' # back to hall
        ]

    engine.simulate_play(move_and_drop)
    
    assert_equal(engine.player.location.label, 'central_hallway_west')
    assert_equal('scalpel' in engine.player.location.items.keys(), True)
    assert_equal(len(engine.player.inventory.inv_list), 0)
    
    #player is in west hall and has dropped scalpel
    
    dead_end = [
        'take scalpel', #pick scalpel back up for cut test
        'e', #move to east hall
        'e', #try main portal
        'go east' #try main portal again
        ]
    
    engine.simulate_play(dead_end)
    
    assert_equal(engine.player.location.label, 'central_hallway_east')
    #player is still in east hall despite three east commands
    
    find_keycard = [
        'w', #move to west hall
        'go north', #move to kitchen
        'look corpse', #unhide keycard
        'take keycard'
        ]
    
    engine.simulate_play(find_keycard)
    
    assert_equal(engine.player.location.label, 'kitchen')
    assert_equal(engine.player.inventory.has('keycard'), True)
    #player is in kitchen holding keycard
    
    find_parka = [
        's', #move to west hall
        'e', #move to east hall
        's', #move to closet
        'take parka' #pick up parka
        ]
    engine.simulate_play(find_parka)
    assert_equal(engine.player.location.label, 'closet')
    assert_equal(engine.player.inventory.has('parka'), True)
    
    open_main = [
        'n', #move to east hall
        'e' #go out main portal
        ]
        
    engine.simulate_play(open_main)
    assert_equal(engine.player.location.label, 'outside')
    
    find_key = [
        's', #go to garage
        'look body', #reveal keycard
        "take key" #fails
        ]
    engine.simulate_play(find_key)
    
    assert_equal(engine.player.location.label, 'garage')
    assert_equal('key' in engine.player.location.items.keys(), True)
    assert_equal(engine.player.location.items['key'].type, 'scenery')
    #player is in garage, key is visible but can't be taken
    
    cut_key = [
        'cut key', #cuts the key out
        'take key' #takes key
        ]
        
    engine.simulate_play(cut_key)
    
    assert_equal(engine.player.inventory.has('key'), True)
    
    inject = [
        'n', #leave garage
        'w', #back to east hall
        'n', #into lab
        'look fridge', #reveal syringe
        'take syringe',
        'inject self'
        ]
        
    engine.simulate_play(inject)
    
    assert_equal(engine.player.location.label, 'lab')
    assert_equal(engine.player.inventory.has('syringe'), True)
    assert_equal(engine.player.injected, True)
    
    get_core = [
        's', #to east hall
        'w', #to west hall
        'w', # down stairs
        's', # into reactor
        'unlock cylinder', #open core
        'take rod'
        ]
        
    engine.simulate_play(get_core)
    
    assert_equal(engine.player.location.label, 'reactor')
    assert_equal(engine.player.inventory.has('rod'), True)
    
    fix = [
        'n', #to reactor foyer
        'e', #to west hall
        'e', #to east hall
        'e', #outside
        's', #to garage
        'fix snowmobile' #fix snowmobile
        ]
        
    engine.simulate_play(fix)
    
    assert_equal(engine.player.location.label, 'garage')
    assert_equal(engine.player.victory, True)