def test_original_inhabitants(): layout = MockDungeonLayout() state = Random(0) manager = MockDungeonManager() trap_source = MockTrapSource() populator = OriginalInhabitants(dungeon_manager=manager, trap_source=trap_source, random_state=state) populator.populate(layout) dungeon = Dungeon(layout)
def test_print_dungeon(capsys): """A test to check the printing of the dungeon.""" dungeon = Dungeon(width=20, height=10, random_seed=2) dungeon.print_dungeon() captured = capsys.readouterr() expected = \ 'XXXXXXXXXXXXXXXXXXXX\n' \ 'XXXXXXXXXXXXXXXXXXXX\n' \ 'XX X X X\n' \ 'XX X $ X\n' \ 'XX X X X\n' \ 'XX X X X\n' \ 'XX $ $ X\n' \ 'XX XXXXXXX X\n' \ 'XX XXXXXXX X\n' \ 'XXXXXXXXXXXXXXXXXXXX\n' assert captured.out == expected
BLACK = (0, 0, 0) WHITE = (255, 255, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) # This sets the WIDTH and HEIGHT of each grid location WIDTH = 20 HEIGHT = 20 # This sets the margin between each cell MARGIN = 5 # MY CODE dungeon_width = 35 dungeon_height = 35 dungeon = Dungeon(width=dungeon_width, height=dungeon_height, random_seed=2) # Create a 2 dimensional array. A two dimensional # array is simply a list of lists. grid = dungeon.dungeon # grid = [] # for row in range(10): # # Add an empty array that will hold each cell # # in this row # grid.append([]) # for column in range(10): # grid[row].append(0) # Append a cell # Set row 1, cell 5 to one. (Remember rows and # column numbers start at zero.) # grid[1][5] = 1
def test_module_orders_rooms_correctly(): state = Random(0) layout = DungeonLayout(5, random_state=state) layout.purpose = 'temple' dungeon = Dungeon(layout) assert dungeon.get_room_ids() == {0: 1, 3: 2, 2: 3, 1: 4, 4: 5}
def test_can_open_room_cell_is_not_next_to_walls(): """Test you can't open a door outside of the dungeon.""" dungeon = Dungeon(width=20, height=10, random_seed=2) dungeon._set_dungeon_cell(7, 3, dungeon.DUNGEON_ROOM) can_carve = dungeon._can_carve_entry(7, 2, directions.DOWN) assert can_carve is False
def test_dungeon(): """A test to check the base initialization of a dungeon.""" dungeon = Dungeon(width=10, height=20) assert dungeon.width == 10 assert dungeon.height == 20 assert dungeon.randomness == 0.5
def test_can_open_room_cell_is_not_a_wall(): """Test you can't open a door outside of the dungeon.""" dungeon = Dungeon(width=20, height=10, random_seed=2) can_carve = dungeon._can_carve_entry(2, 2, None) assert can_carve is False
def test_dungeon_randomness_min(): """A test to check the min of a dungeons randomness.""" dungeon = Dungeon(width=10, height=20, randomness=-4) assert dungeon.randomness == 0