コード例 #1
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def map_update_clues_test():
    # Test Map.update_clues method

    # create map and characters
    a_map = map_.Map('story')
    player = char.Player()
    boar = char.Boar()
    a_map.characters['player'] = player
    a_map.characters['boar'] = boar
    # add two adjacent scenes
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    # scene2 is east of scene1
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    map_gen.create_link(s1, s2)
    # put some clues in the scenes
    s1.clues.append(map_.FootprintClue('e')) 
    s2.clues.append(map_.BrokenTreeClue())
    ok_(s1.clues[0].fresh == 2)
    ok_(s2.clues[0].fresh == 2)
    # update clues one clock tick
    a_map.update_clues()
    ok_(s1.clues[0].fresh == 1)
    ok_(s2.clues[0].fresh == 1)
    # update clues one more time
    a_map.update_clues()
    ok_(s1.clues[0].fresh == 0)
    ok_(s2.clues[0].fresh == 0)
コード例 #2
0
ファイル: combat_tests.py プロジェクト: R5D4/dark_forest
def run_away_test():
    # Test player running away!

    # create map and characters
    a_map = map_.Map('story')
    player = char.Player()
    boar = char.Boar()
    a_map.characters['player'] = player
    a_map.characters['boar'] = boar
    # add two adjacent scenes
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    map_gen.create_link(s1, s2)
    # spawn the boss in one of the scenes
    map_gen.add_lair(a_map)
    map_gen.spawn_boss(a_map)
    # run away from one of the scenes
    name = combat.run_away(s1)
    ok_(name == s2.name)
    name = combat.run_away(s2)
    ok_(name == s1.name)
コード例 #3
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def create_link_test():
    a_map = map_.Map('story')
    # east-west
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    map_gen.create_link(s1, s2)
    ok_(s1.exits['e'] == 'scene2')
    ok_(s2.exits['w'] == 'scene1')
    # north-south
    s3 = map_gen.new_scene(a_map, None, (5, 6))
    s3.name = 'scene3'
    map_gen.create_link(s1, s3)
    ok_(s1.exits['s'] == 'scene3')
    ok_(s3.exits['n'] == 'scene1')
    # nw-se
    s4 = map_gen.new_scene(a_map, None, (4, 6))
    s4.name = 'scene4'
    map_gen.create_link(s1, s4)
    ok_(s1.exits['sw'] == 'scene4')
    ok_(s4.exits['ne'] == 'scene1')
    # ne-sw
    s5 = map_gen.new_scene(a_map, None, (6, 6))
    s5.name = 'scene5'
    map_gen.create_link(s1, s5)
    ok_(s1.exits['se'] == 'scene5')
    ok_(s5.exits['nw'] == 'scene1')
コード例 #4
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def adjacent_scenes_test():
    a_map = map_.Map('story')
    location = (5, 5)

    # one adjacent scene
    scene_dict = {
                 (5, 5): map_gen.new_scene(a_map, 'entrance', (5, 5)),
                 (4, 6): map_gen.new_scene(a_map, 'scene1', (4, 6)),
                 }
    adj_scenes = map_gen.adjacent_scenes(scene_dict, location)
    print adj_scenes
    ok_(scene_dict[(4, 6)] in adj_scenes)

    # two adjacent scenes
    scene_dict[(6, 5)] = map_gen.new_scene(a_map, 'scene2', (6, 5)), 
    adj_scenes = map_gen.adjacent_scenes(scene_dict, location)
    print adj_scenes
    ok_(scene_dict[(4, 6)] in adj_scenes)
    ok_(scene_dict[(6, 5)] in adj_scenes)

    # three adjacent scenes
    scene_dict[(6, 6)] = map_gen.new_scene(a_map, 'scene3', (6, 6)), 
    adj_scenes = map_gen.adjacent_scenes(scene_dict, location)
    print adj_scenes
    ok_(scene_dict[(4, 6)] in adj_scenes)
    ok_(scene_dict[(6, 5)] in adj_scenes)
    ok_(scene_dict[(6, 6)] in adj_scenes)
コード例 #5
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def DFS_test():
    # test for the helper function DFS
    a_map = map_.Map('story')

    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    map_gen.create_link(s1, s2)
    ok_(set(DFS(s1, a_map)) == set([s1, s2]))
    ok_(set(DFS(s2, a_map)) == set([s1, s2]))
コード例 #6
0
ファイル: draw_map_tests.py プロジェクト: R5D4/dark_forest
def prepare_canvas_test():
    # Test if links are drawn properly

    ### Simple test ###
    a_map = map_.Map('story')
    # create scenes with location data
    s1 = map_gen.new_scene(a_map, None, (1, 1))
    s2 = map_gen.new_scene(a_map, None, (2, 1))
    s3 = map_gen.new_scene(a_map, None, (1, 2))
    s4 = map_gen.new_scene(a_map, None, (2, 2))
    # set scene names
    s1.name = 'scene1'
    s2.name = 'scene2'
    s3.name = 'scene3'
    s4.name = 'scene4'
    # update exits
    s1.exits.update({'se': 'scene4'})
    s4.exits.update({'nw': 'scene1'})
    s2.exits.update({'sw': 'scene3'})
    s3.exits.update({'ne': 'scene2'})
    # add scenes to map
    a_map.add_scene(s1)
    a_map.add_scene(s2)
    a_map.add_scene(s3)
    a_map.add_scene(s4)
    # prepare canvas
    canvas = draw_map.prepare_canvas(a_map, (1, 1))
    draw_map.print_canvas(canvas)
    # tests
    ok_(canvas[1][1] == 'X')

    ### Automated tests on procedurally generated maps ###
    for x in range(1, 101):
        a_map = map_gen.new_map()
        # prepare canvas
        canvas = draw_map.prepare_canvas(a_map, None)
        draw_map.print_canvas(canvas)
        # for each scene
        for sc in a_map.scenes.values():
            # for each exit
            for ex in sc.exits.keys():
                # calculate canvas position of the link
                canvas_x, canvas_y = draw_map.get_canvas_link_location(
                                                                sc.location,
                                                                ex)
                # check if link is the correct symbol
                print "{}: {}".format(sc.location, sc.exits)
                ok_(canvas[canvas_x][canvas_y] == draw_map.SYMBOL_LINK[ex] or \
                    canvas[canvas_x][canvas_y] == 'X')
コード例 #7
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def cmd_take_test():
    # Test 'take' command

    ## Setup
    # create scene
    a_map = map_.Map('story')
    a_map.add_player()
    sc = map_gen.new_scene(a_map, 'random', (0,0))
    # empty player inventory
    player = sc.characters['player']
    player.inventory = []
    # create item
    w = items.get_weapon("Hunting Knife")
    # add items to scene
    sc.items.append(w)

    ## Testing the 'take' command
    # no item ID
    msg = sc.cmd_take(None)
    ok_(msg == "Please indicate item ID.")
    # invalid item ID
    msg = sc.cmd_take('9')
    ok_(msg == "No such item.")
    # invalid item ID 
    msg = sc.cmd_take('nop')
    ok_(msg == "No such item.")
    # valid scenario
    msg = sc.cmd_take('0')
    ok_(msg == "Took Hunting Knife.")
    ok_(w not in sc.items)
コード例 #8
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def scene_find_clue_test():
    # Test Scene.find_clue

    # create a scene
    a_map = map_.Map('story')
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s1.clues = []

    # no clues
    clue = s1.find_clue(map_.FootprintClue)
    ok_(not clue)
    
    # add footprint
    s1.clues.append(map_.FootprintClue("n"))
    clue = s1.find_clue(map_.FootprintClue)
    ok_(clue)
    ok_(isinstance(clue, map_.FootprintClue))

    # add broken tree
    s1.clues.append(map_.BrokenTreeClue())
    clue = s1.find_clue(map_.BrokenTreeClue)
    ok_(clue)
    ok_(isinstance(clue, map_.BrokenTreeClue))

    # add slain animal
    s1.clues.append(map_.SlainAnimalClue())
    clue = s1.find_clue(map_.SlainAnimalClue)
    ok_(clue)
    ok_(isinstance(clue, map_.SlainAnimalClue))
コード例 #9
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def update_desc_test():
    # Test update description function

    # create map and characters
    a_map = map_.Map('story')
    player = char.Player()
    boar = char.Boar()
    a_map.characters['player'] = player
    a_map.characters['boar'] = boar
    # add a scene
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s1.features = [] # no features
    # add a lair as the only feature
    map_gen.add_lair(a_map)
    lair = s1.features[0]

    # unrevealed lair
    ok_(s1.description == "No description available.")
    # revealed lair
    lair.revealed = True
    map_.update_desc(s1)
    print s1.description
    ok_("There's a cave entrance behind the thick brush, it's the lair of the \
forest guardian!" in s1.description)
コード例 #10
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def move_boss_test():
    # Tests boss' movement on the map

    # create map: 1-2-3 
    a_map = map_.Map('story')
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s3 = map_gen.new_scene(a_map, None, (7, 5))
    s3.name = 'scene3'
    a_map.add_scene(s3)
    map_gen.create_link(s1, s2)
    map_gen.create_link(s2, s3)
    # set lair and spawn boss
    a_map.boss_scene_name = s1.name
    a_map.lair_scene_name = s1.name
    s1.flags['encounter'] = True

    # test 1: daytime, in lair scene
    for t in range(7, 20): # 0700 to 1900
        a_map.clock.time = t
        new_scene, direction = a_map.move_boss()
        ok_(not a_map.path) # no path chosen
        ok_(new_scene == s1.name and not direction) # should stay in same scene

    # test 2: daytime, not in lair scene
    for t in range(7, 20): # 0700 to 1900
        a_map.clock.time = t
        a_map.path = [] # reset path
        a_map.boss_scene_name = s3.name # spawn boss away from lair
        new_scene, direction = a_map.move_boss()
        ok_(a_map.path) # path to lair constructed

    # test 3: nighttime
    moved = False
    a_map.clock.time = 20
    for t in range(10): # 2000 to 0600
        a_map.clock.tick()
        a_map.boss_scene_name = s3.name # spawn boss away from lair
        new_scene, direction = a_map.move_boss()
        if direction: # not None
            moved = True
        ok_(not a_map.path) # no path chosen
    ok_(moved) # should have moved at least once (randomly)
コード例 #11
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def add_links_test():
    # Test if map_gen.add_links function actually adds between 0 and 1 link
    # per scene.

    # two scenes, max two new links
    a_map = map_.Map('story')

    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)

    map_gen.add_links(a_map)
    ok_(count_links(a_map) <= 2)


    # three scenes, max three new links
    a_map = map_.Map('story')

    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s3 = map_gen.new_scene(a_map, None, (4, 5))
    s3.name = 'scene3'
    a_map.add_scene(s3)

    map_gen.add_links(a_map)
    ok_(count_links(a_map) <= 3)

    # four scenes, max four new links
    a_map = map_.Map('story')

    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s3 = map_gen.new_scene(a_map, None, (7, 5))
    s3.name = 'scene3'
    a_map.add_scene(s3)
    s4 = map_gen.new_scene(a_map, None, (8, 5))
    s4.name = 'scene4'
    a_map.add_scene(s4)

    map_gen.add_links(a_map)
    ok_(count_links(a_map) <= 4)
コード例 #12
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def add_flora_test():
    # Test if flora is added for each stratum
    a_map = map_.Map('story')
    for i in xrange(100):
        scene = map_gen.new_scene(a_map, 'random', (1, 1))
        map_gen.add_flora(scene)
        map_gen.add_description(scene)
        print scene.features
        ok_('canopy' in scene.description)
        ok_('understory' in scene.description)
        ok_('shrubs' in scene.description)
        ok_('floor' in scene.description)
コード例 #13
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def print_encounter_msg_test():
    # Test if encounter messages are printed correctly

    # create map and characters
    a_map = map_.Map('story')
    player = char.Player()
    boar = char.Boar()
    a_map.characters['player'] = player
    a_map.characters['boar'] = boar
    # add a scene
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    # spawn the boss in s1 and put it in the lair
    a_map.boss_scene_name = s1.name
    s1.features = [] # no features
    map_gen.add_lair(a_map)
    lair = s1.features[0]

    # boss in lair, lair unrevealed
    lair.revealed = False
    lair.has_boss = True
    s1.flags['encounter'] = False
    ok_(s1.print_encounter_msg() is None)
    # boss in lair, lair revealed
    lair.revealed = True
    lair.has_boss= True
    s1.flags['encounter'] = True
    ok_(s1.print_encounter_msg() == "You can see movement inside the beast's \
lair!")
    # boss not in scene, lair unrevealed
    lair.revealed = False
    lair.has_boss = False
    s1.flags['encounter'] = False
    ok_(s1.print_encounter_msg() is None)
    # boss not in scene, lair revealed
    lair.revealed = True
    lair.has_boss = False
    s1.flags['encounter'] = False
    ok_(s1.print_encounter_msg() is None)
    # boss in scene (not in lair), lair unrevealed
    lair.revealed = False
    lair.has_boss= False
    s1.flags['encounter'] = True
    ok_(s1.print_encounter_msg() == "You see the boar! You don't think it \
notices you.")
    # boss in scene (not in lair), lair revealed
    lair.revealed = True
    lair.has_boss= False
    s1.flags['encounter'] = True
    ok_(s1.print_encounter_msg() == "You see the boar! You don't think it \
notices you.")
コード例 #14
0
ファイル: draw_map_tests.py プロジェクト: R5D4/dark_forest
def draw_map_test():
    ## Case 1
    a_map = map_.Map('story')

    # scene1
    s1 = map_gen.new_scene(a_map, None, (2, 1))
    s1.name = 'scene1'
    s1.exits.update({'s': 'scene2', 
                     'e': 'scene3',
                     'se': 'scene4'})
    a_map.add_scene(s1)
    # scene2
    s2 = map_gen.new_scene(a_map, None, (2, 2))
    s2.name = 'scene2'
    s2.exits.update({'n': 'scene1',
                     'ne': 'scene3'})
    a_map.add_scene(s2)
    # scene3
    s3 = map_gen.new_scene(a_map, None, (3, 1))
    s3.name = 'scene3'
    s3.exits.update({'w': 'scene1',
                     'sw': 'scene2'})
    a_map.add_scene(s3)
    # scene4
    s4 = map_gen.new_scene(a_map, None, (3, 2))
    s4.name = 'scene4'
    s4.exits.update({'nw': 'scene1'})
    a_map.add_scene(s4)

    canvas = draw_map.prepare_canvas(a_map, (2, 1))
    draw_map.print_canvas(canvas)

    ok_(canvas[2][0] == 'P') 
    ok_(canvas[2][2] == '#') 
    ok_(canvas[4][0] == '#') 
    ok_(canvas[4][2] == '#') 
    ok_(canvas[2][1] == '|') 
    ok_(canvas[3][0] == '-') 
    ok_(canvas[3][1] == 'X') 
コード例 #15
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def boss_at_lair_test():
    # Test if we can correctly determine if the boss is in the lair scene
    # create map
    a_map = map_.Map('story')
    # add a scene
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s1.features = [] # no features
    # add a lair in s1
    map_gen.add_lair(a_map)
    # add another scene
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s2.features = [] # no features

    # Test 1: boss at lair
    a_map.boss_scene_name = s1.name
    ok_(a_map.boss_at_lair())
    # Test 2: boss not at lair
    a_map.boss_scene_name = s2.name
    ok_(not a_map.boss_at_lair())
コード例 #16
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def cmd_search_test():
    # Test 'search' command

    # create scene
    a_map = map_.Map('story')
    sc = map_gen.new_scene(a_map, 'random', (0,0))
    # create items
    wps = [items.get_weapon("Hunting Knife")]
    # add items to item stash
    stash = map_.ItemStash(wps)
    # add item stash to scene
    sc.features.append(stash)
    # search scene and check results
    msg = sc.cmd_search()
    ok_("Hunting Knife" in msg)
コード例 #17
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def get_lair_test():
    # Test retrieving the Lair object from a scene

    # create map
    a_map = map_.Map('story')
    # add a scene
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s1.features = [] # no features
    # add a lair as the only feature
    map_gen.add_lair(a_map)

    # Get the Lair object
    lair = s1.get_lair()
    ok_(isinstance(lair, map_.Lair))
コード例 #18
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def add_item_stash_test():
    # Test if item stash is added to a scene correctly
    a_map = map_.Map('story')

    for i in xrange(50):
        # create scene
        sc = map_gen.new_scene(a_map, 'random', (0,0))
        # create item stash
        map_gen.add_item_stash(sc)
        # find item stash
        stash = None
        for f in sc.features:
            if isinstance(sc, map_.ItemStash):
                stash = f
        n = len(f.hidden_items)
        # test number of items in item stash
        ok_(n >= 1 and n <= 2)
コード例 #19
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def scene_add_clue_test():
    # Test Scene.add_clue method
    # i.e. create a new clue if no clues of same type, otherwise add to 
    # existing clue

    # create a scene
    a_map = map_.Map('story')
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s1.clues = []

    # add first footprint
    s1.add_clue(map_.FootprintClue, "n")
    clue = s1.find_clue(map_.FootprintClue)
    ok_(clue)
    ok_(clue.count == 1)
    ok_(clue.direction == "n")
    # add second footprint
    s1.add_clue(map_.FootprintClue, "n")
    clue = s1.find_clue(map_.FootprintClue)
    ok_(clue)
    ok_(clue.count == 2)

    # add first broken tree
    s1.add_clue(map_.BrokenTreeClue, None)
    clue = s1.find_clue(map_.BrokenTreeClue)
    ok_(clue)
    ok_(clue.count == 1)
    # add second broken tree
    s1.add_clue(map_.BrokenTreeClue, None)
    clue = s1.find_clue(map_.BrokenTreeClue)
    ok_(clue)
    ok_(clue.count == 2)

    # add first slain animal
    s1.add_clue(map_.SlainAnimalClue, None)
    clue = s1.find_clue(map_.SlainAnimalClue)
    ok_(clue)
    ok_(clue.count == 1)
    # add second slain animal
    s1.add_clue(map_.SlainAnimalClue, None)
    clue = s1.find_clue(map_.SlainAnimalClue)
    ok_(clue)
    ok_(clue.count == 2)
コード例 #20
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def get_boss_attack_test():
    # Test when the boss will attack
    # create map and characters
    a_map = map_.Map('story')
    boar = char.Boar()
    boar.effective_stats['max_HP'] = 100
    a_map.characters['boar'] = boar
    # add two adjacent scenes
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)

    # Should not attack (boss not in scene)
    a_map.clock.time = 22
    s1.flags['encounter'] = False
    ok_(not s1.get_boss_attack())
    # Should not attack (HP too low)
    a_map.clock.time = 22
    s1.flags['encounter'] = True
    boar.health['HP'] = 29
    ok_(not s1.get_boss_attack())
    # Should not attack (daytime)
    a_map.clock.time = 10
    s1.flags['encounter'] = True
    boar.health['HP'] = 30
    ok_(not s1.get_boss_attack())
    # Should attack with non-zero chance
    a_map.clock.time = 22
    s1.flags['encounter'] = True
    boar.health['HP'] = 30
    attacked = False
    for i in xrange(50): # 99.999...% chance that this result is correct
        attacked = s1.get_boss_attack()
        if attacked:
            break
    ok_(attacked)
コード例 #21
0
ファイル: map_gen_tests.py プロジェクト: R5D4/dark_forest
def has_link_test():
    a_map = map_.Map('story')

    # case 1: east-west link
    s1 = map_gen.new_scene(a_map, 'scene1', (5, 5))
    s1.name = 'scene1'
    s2 = map_gen.new_scene(a_map, 'scene2', (6, 5))
    s2.name = 'scene2'
    s1.exits['e'] = 'scene2'
    s2.exits['w'] = 'scene1'
    ok_(map_gen.has_link(s1, s2) is True)
    ok_(map_gen.has_link(s2, s1) is True)

    # case 2: north-south link
    s3 = map_gen.new_scene(a_map, 'scene3', (5, 6))
    s3.name = 'scene3'
    s1.exits['s'] = 'scene3'
    s3.exits['n'] = 'scene1'
    ok_(map_gen.has_link(s1, s3) is True)
    ok_(map_gen.has_link(s3, s1) is True)

    # case 3: nw-se link
    s4 = map_gen.new_scene(a_map, 'scene4', (4, 6))
    s4.name = 'scene4'
    s1.exits['sw'] = 'scene4'
    s4.exits['ne'] = 'scene1'
    ok_(map_gen.has_link(s1, s4) is True)
    ok_(map_gen.has_link(s4, s1) is True)

    # case 4: not adjacent (and therefore cannot be linked)
    s5 = map_gen.new_scene(a_map, 'scene5', (9, 9))
    s5.name = 'scene5'
    ok_(map_gen.has_link(s1, s5) is False)
    ok_(map_gen.has_link(s5, s1) is False)
    
    # case 5: adjacent (ne-sw) but no links
    s6 = map_gen.new_scene(a_map, 'scene6', (6, 6))
    s6.name = 'scene6'
    ok_(map_gen.has_link(s1, s6) is False)
    ok_(map_gen.has_link(s6, s1) is False)
コード例 #22
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def construct_path_test():
    # Test path construction

    # map 1: 1-2-3-4
    a_map = map_.Map('story')
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (6, 5))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s3 = map_gen.new_scene(a_map, None, (7, 5))
    s3.name = 'scene3'
    a_map.add_scene(s3)
    s4 = map_gen.new_scene(a_map, None, (8, 5))
    s4.name = 'scene4'
    a_map.add_scene(s4)
    # create links
    map_gen.create_link(s1, s2)
    map_gen.create_link(s2, s3)
    map_gen.create_link(s3, s4)
    # test 1: 1 to 4
    path = a_map.construct_path(s1.name, s4.name)
    print path
    ok_(path == ['scene4', 'scene3', 'scene2'])
    # test 2: 2 to 4
    path = a_map.construct_path(s2.name, s4.name)
    print path
    ok_(path == ['scene4', 'scene3'])
    # test 3: 3 to 4
    path = a_map.construct_path(s3.name, s4.name)
    print path
    ok_(path == ['scene4'])

    # map 2: 
    #   1
    #   |\
    #   2 3
    #   | |
    #   5-4
    a_map = map_.Map('story')
    s1 = map_gen.new_scene(a_map, None, (5, 5))
    s1.name = 'scene1'
    a_map.add_scene(s1)
    s2 = map_gen.new_scene(a_map, None, (5, 6))
    s2.name = 'scene2'
    a_map.add_scene(s2)
    s3 = map_gen.new_scene(a_map, None, (6, 6))
    s3.name = 'scene3'
    a_map.add_scene(s3)
    s4 = map_gen.new_scene(a_map, None, (6, 7))
    s4.name = 'scene4'
    a_map.add_scene(s4)
    s5 = map_gen.new_scene(a_map, None, (5, 7))
    s5.name = 'scene5'
    a_map.add_scene(s5)
    # create links
    map_gen.create_link(s1, s2)
    map_gen.create_link(s1, s3)
    map_gen.create_link(s2, s5)
    map_gen.create_link(s3, s4)
    map_gen.create_link(s4, s5)
    # test 1: 1 to 5
    path = a_map.construct_path(s1.name, s5.name)
    print path
    ok_(path == ['scene5', 'scene2'])
    # test 2: 3 to 2
    path = a_map.construct_path(s3.name, s2.name)
    print path
    ok_(path == ['scene2', 'scene1'])
コード例 #23
0
ファイル: map_tests.py プロジェクト: R5D4/dark_forest
def cmd_drop_test():
    # Test 'drop' command

    ## Setup
    # create scene
    a_map = map_.Map('story')
    a_map.add_player()
    sc = map_gen.new_scene(a_map, 'random', (0,0))

    # initialize player equipment and inventory
    player = sc.characters['player']
    player.unequip('R_hand')
    player.inventory = []
    knife = items.Weapon(TESTING_KNIFE)
    bow = items.Weapon(TESTING_BOW)
    shield = items.Armor(TESTING_SHIELD)

    # set player base stats to be able to equip everything
    player.base_stats.update({'dex': 100, 'str': 100, 'AC': 100})

    ## Testing the 'drop' command
    # no item ID
    msg = sc.cmd_drop(None)
    ok_(msg == "Please indicate item ID.")
    # invalid item ID (out of range)
    msg = sc.cmd_drop('9')
    ok_(msg == "No such item.")
    # invalid item ID (not an integer)
    msg = sc.cmd_drop('nop')
    ok_(msg == "No such item.")
    # drop unequipped weapon
    player.pick_up(knife)
    msg = sc.cmd_drop('0')
    ok_(msg == "Dropped Testing Knife.")
    ok_(knife not in player.inventory)
    ok_(knife in sc.items)
    # drop equipped weapon (1H)
    sc.items = []
    player.pick_up(knife)
    player.equip(knife)
    msg = sc.cmd_drop('0')
    ok_(msg == "Dropped Testing Knife.")
    ok_(not knife.equipped)
    ok_(knife not in player.equipped)
    ok_(player.equipped_names['R_hand'] is None)
    ok_(knife not in player.inventory)
    ok_(knife in sc.items)
    # drop equipped weapon (2H)
    sc.items = []
    player.pick_up(bow)
    player.equip(bow)
    msg = sc.cmd_drop('0')
    ok_(msg == "Dropped Testing Bow.")
    ok_(not bow.equipped)
    ok_(bow not in player.equipped)
    ok_(player.equipped_names['R_hand'] is None)
    ok_(player.equipped_names['L_hand'] is None)
    ok_(bow not in player.inventory)
    ok_(bow in sc.items)

    ## drop one of two equipped weapons
    sc.items = []
    player.pick_up(shield)
    player.pick_up(knife)
    player.equip(shield)
    player.equip(knife)
    msg = sc.cmd_drop('0') # drop shield
    # check left hand is unequipped
    ok_(msg == "Dropped Testing Shield.")
    ok_(not shield.equipped)
    ok_(shield not in player.equipped)
    ok_(player.equipped_names['L_hand'] is None)
    ok_(shield not in player.inventory)
    ok_(shield in sc.items)
    # check right hand is still equipped
    ok_(knife.equipped)
    ok_(knife in player.equipped)
    ok_(player.equipped_names['R_hand'] == "Testing Knife")
    ok_(knife in player.inventory)
    ok_(knife not in sc.items)