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)
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)
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.")
def add_lair_test(): # Test adding the boss' lair a_map = map_.Map('story') map_gen.generate_scenes(a_map) map_gen.add_lair(a_map) # Test that the map has exactly one lair count = 0 for sc in a_map.scenes.values(): for f in sc.features: if isinstance(f, map_.Lair): # found a scene with a lair # test if it's the scene the map thinks the lair is in ok_(sc.name == a_map.lair_scene_name) count +=1 ok_(count == 1)
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))
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())