示例#1
0
 def test_add_an_overlapping_room_with_negative_shift(self):
     room = Room(width=3, height=3)
     room.x, room.y = 3, 3
     self.level.add(room)
     overlap_room = Room(width=2, height=2)
     overlap_room.x, overlap_room.y = 2, 2
     with self.assertRaises(Level.RoomOverlap):
         self.level.add(overlap_room)
示例#2
0
 def test_add_an_overlapping_room_with_matching_coordinates(self):
     room = Room(width=1, height=1)
     room.x, room.y = 0, 0
     self.level.add(room)
     overlap_room = Room(width=1, height=1)
     overlap_room.x, overlap_room.y = 0, 0
     with self.assertRaises(Level.RoomOverlap):
         self.level.add(overlap_room)
示例#3
0
 def test_two_fully_adjacent_rooms(self):
     a, b = Room(width=2, height=2), Room(width=2, height=2)
     a.x, a.y, b.x, b.y = 0, 0, 2, 0
     turfs = _get_adjacent_turfs(a, b)
     self.assertEqual(len(turfs), 2)
     self.assertEqual(turfs,
                      (set([((1, 0), (0, 0)), ((1, 1), (0, 1))]), (1, 0)))
示例#4
0
 def test_room_is_partially_adjacent_to_another_from_the_east(self):
     a, b = Room(width=3, height=3), Room(width=3, height=3)
     a.x, a.y, b.x, b.y = 0, 0, 3, 1
     turfs = _get_adjacent_turfs(a, b)
     self.assertEqual(len(turfs), 2)
     self.assertEqual(turfs,
                      (set([((2, 1), (0, 0)), ((2, 2), (0, 1))]), (1, 0)))
示例#5
0
 def test_room_is_partially_adjacent_to_another_room_from_north(self):
     a, b = Room(width=3, height=3), Room(width=3, height=3)
     a.x, a.y, b.x, b.y = 1, 3, 0, 0
     turfs = _get_adjacent_turfs(a, b)
     self.assertEqual(len(turfs), 2)
     self.assertEqual(turfs,
                      (set([((0, 0), (1, 2)), ((1, 0), (2, 2))]), (0, -1)))
示例#6
0
 def test_two_nine_tile_rooms(self):
     """Corridor is chosen randomly out of possible options."""
     room_a, room_b = Room(width=3, height=3), Room(width=3, height=3)
     room_a.x, room_a.y, room_b.x, room_b.y = 0, 0, 4, 1
     self.assertIn(
         _get_corridor_coordinates(room_a, room_b),
         set([((3, 1), ((2, 1), (0, 0)), (1, 0)),
              ((3, 2), ((2, 2), (0, 1)), (1, 0))]))
示例#7
0
 def test_two_diagonaly_adjacent_rooms(self):
     """
     Rooms are not considered to be adjacent if they touch diagonaly.
     """
     for x, y in [(0, 0), (1, 1)]:
         room = Room(width=1, height=1)
         room.x, room.y = x, y
         self.level.add(room)
         turf = iter(room.get(x=0, y=0)).next()
         self.assertEqual(turf.exits, {})
     self.assertEqual(len(self.level.rooms), 2)
示例#8
0
 def test_level_with_two_fully_adjacent_rooms(self):
     """Exits are added to adjacent turfs."""
     a, b = Room(width=1, height=1), Room(width=1, height=1)
     a.x, a.y, b.x, b.y = 0, 0, 1, 0
     self.level.add(a)
     self.level.add(b)
     turf_a = iter(a.get(x=0, y=0)).next()
     turf_b = iter(b.get(x=0, y=0)).next()
     self.assertEqual(len(self.level.rooms), 2)
     self.assertEqual(len(turf_a.exits), 1)
     self.assertEqual(len(turf_b.exits), 1)
     self.assertEqual(turf_a.exits[(1, 0)], turf_b)
     self.assertEqual(turf_b.exits[(-1, 0)], turf_a)
示例#9
0
 def test_level_with_three_adjacent_rooms(self):
     a, b, c = Room(width=1, height=1), Room(1, 1), Room(1, 1)
     a.x, a.y, b.x, b.y, c.x, c.y = 0, 0, 1, 0, 0, 1
     for room in (a, b, c):
         self.level.add(room)
     turf_a = iter(a.get(x=0, y=0)).next()
     turf_b = iter(b.get(x=0, y=0)).next()
     turf_c = iter(c.get(x=0, y=0)).next()
     self.assertEqual(len(turf_a.exits), 2)
     for turf in (turf_b, turf_c):
         self.assertEqual(len(turf.exits), 1)
     self.assertEqual(turf_a.exits, {(1, 0): turf_b, (0, 1): turf_c})
     self.assertEqual(turf_b.exits[(-1, 0)], turf_a)
     self.assertEqual(turf_c.exits[(0, -1)], turf_a)
示例#10
0
 def generate(self, num):
     room_w, room_h = 3, 3
     dx, dy, px, py = 0, 0, 0, 0
     for i in xrange(0, num):
         room = Room(width=room_w, height=room_h)
         coordinates = _get_surrounding_coordinates(
             px, py, room_w, room_h, room_w, room_h)
         while True:
             dx, dy = sample(coordinates, 1)[0]
             room.x, room.y = dx, dy
             try:
                 self.add(room)
                 break
             except self.RoomOverlap:
                 pass
         px, py = dx, dy
示例#11
0
 def test_level_with_two_partially_adjacent_rooms(self):
     """Non-adjacent turfs do not become exits."""
     a, b = Room(width=3, height=3), Room(width=3, height=3)
     a.x, a.y, b.x, b.y = 3, 1, 0, 0
     self.level.add(a)
     self.level.add(b)
     exits = set([((0, 0), (2, 1)), ((0, 1), (2, 2))])
     for ((a_x, a_y), (b_x, b_y)) in exits:
         turf_a = iter(a.get(x=a_x, y=a_y)).next()
         turf_b = iter(b.get(x=b_x, y=b_y)).next()
         self.assertEqual(len(turf_a.exits), 1)
         self.assertEqual(len(turf_b.exits), 1)
         self.assertEqual(turf_a.exits[(-1, 0)], turf_b)
         self.assertEqual(turf_b.exits[(1, 0)], turf_a)
     no_exits = {
         a: set([(0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]),
         b: set([(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0)])}
     for room, coordinates in no_exits.items():
         for (x, y) in coordinates:
             turf = iter(room.get(x=x, y=y)).next()
             self.assertEqual(len(turf.exits), 0)
示例#12
0
 def test_two_non_overlapping_rooms(self):
     a, b = Room(width=1, height=1), Room(width=1, height=1)
     coordinates = [(0, 0, 1, 0), (2, 2, 5, 5), (0, 0, 1, 1)]
     for coordinate_set in coordinates:
         a.x, a.y, b.x, b.y = coordinate_set
         self.assertFalse(_rooms_overlap(a, b))
示例#13
0
 def test_two_one_tile_rooms_from_north(self):
     room_a, room_b = Room(width=1, height=1), Room(width=1, height=1)
     room_a.x, room_a.y, room_b.x, room_b.y = 0, 2, 0, 0
     self.assertEqual(_get_corridor_coordinates(room_a, room_b),
                      ((0, -1), ((0, 0), (0, 0)), (0, -1)))
示例#14
0
 def test_two_unadjacent_rooms(self):
     a, b = Room(width=1, height=1), Room(width=1, height=1)
     a.x, a.y, b.x, b.y = 0, 0, 2, 2
     self.assertEqual(_get_adjacent_turfs(a, b), (set(), (None, None)))
示例#15
0
 def test_two_overlapping_rooms(self):
     a, b = Room(width=2, height=2), Room(width=2, height=2)
     coordinates = [(0, 0, 1, 1), (2, 2, 1, 1), (0, 0, 0, 1)]
     for coordinate_set in coordinates:
         a.x, a.y, b.x, b.y = coordinate_set
         self.assertFalse(_rooms_adjacent(a, b))
示例#16
0
 def test_two_adjacent_rooms(self):
     a, b = Room(width=2, height=2), Room(width=2, height=2)
     coordinates = [(0, 0, 2, 0), (0, 2, 0, 0), (0, 0, 1, 2)]
     for coordinate_set in coordinates:
         a.x, a.y, b.x, b.y = coordinate_set
         self.assertTrue(_rooms_adjacent(a, b))
示例#17
0
 def test_two_unadjacent_rooms(self):
     a, b = Room(width=1, height=1), Room(width=1, height=1)
     coordinates = [(0, 0, 1, 1), (1, 1, 0, 0), (0, 0, 4, 4)]
     for coordinate_set in coordinates:
         a.x, a.y, b.x, b.y = coordinate_set
         self.assertFalse(_rooms_adjacent(a, b))
示例#18
0
 def test_one_room_within_another(self):
     a, b = Room(width=3, height=3), Room(width=1, height=1)
     a.x, a.y, b.x, b.y = 0, 0, 1, 1
     self.assertTrue(_rooms_overlap(a, b))
示例#19
0
 def test_rooms_are_too_far_away(self):
     room_a, room_b = Room(width=1, height=1), Room(width=1, height=1)
     room_a.x, room_a.y, room_b.x, room_b.y = 0, 0, 9, 9
     self.assertEqual(_get_corridor_coordinates(room_a, room_b),
                      (None, (None, None), None))
示例#20
0
 def test_level_with_one_room(self):
     room = Room(width=1, height=1)
     room.x, room.y = 0, 0
     self.level.add(room)
     self.assertEqual(self.level.rooms, set([room]))
示例#21
0
 def test_level_with_two_non_adjacent_rooms(self):
     for x, y in [(0, 0), (3, 3)]:
         room = Room(width=1, height=1)
         room.x, room.y = x, y
         self.level.add(room)
     self.assertEqual(len(self.level.rooms), 2)