示例#1
0
 def test_add_to_map(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     
     # inside
     
     for x in range(0, 9):
         for y in range(0, 9):
             self.assertTrue(self.body.add_to_map(self.map, x, y))
             
             self.check(x, y)
             
     
     # outside
     
     self.assertFalse(self.body.add_to_map(self.map, -1, -1))
     self.assertFalse(self.body.add_to_map(self.map, 9, -1))
     self.assertFalse(self.body.add_to_map(self.map, -1, 9))
     self.assertFalse(self.body.add_to_map(self.map, 9, 9))
     
     self.check(8, 8)
     
     # solid
     
     self.map.get_cell(5, 5).celltype = get_celltype('Wall')
     
     self.assertFalse(self.body.add_to_map(self.map, 5, 5))
     self.assertFalse(self.body.add_to_map(self.map, 4, 5))
     self.assertFalse(self.body.add_to_map(self.map, 5, 4))
     self.assertFalse(self.body.add_to_map(self.map, 4, 4))
     
     self.check(8, 8)
示例#2
0
 def test_map_add_object(self):
     self.map = create_map('Test', 10, 10, 'Floor') 
     
     # inside
     
     for x in range(0, 9):
         for y in range(0, 9):
             self.assertTrue(self.map.add_object(self.obj, x, y))
             
             self.check(x, y)
     
     # outside
     
     self.assertFalse(self.map.add_object(self.obj, -1, 0))
     self.assertFalse(self.map.add_object(self.obj, 0, -1))
     self.assertFalse(self.map.add_object(self.obj, 10, 9))
     self.assertFalse(self.map.add_object(self.obj, 9, 10))
     
     self.check(8, 8)
     
     # solid
     
     self.map.get_cell(5, 5).celltype = get_celltype('Wall')
     
     self.assertFalse(self.map.add_object(self.obj, 5, 5))
     self.assertFalse(self.map.add_object(self.obj, 4, 5))
     self.assertFalse(self.map.add_object(self.obj, 5, 4))
     self.assertFalse(self.map.add_object(self.obj, 4, 4))
     
     self.check(8, 8)
示例#3
0
 def test_get_distance_to_body(self):
     map = create_map('Test', 10, 10, 'Floor')
     map.add_object(self.obj, 5, 5)        
     obj = Object('Simple')
     
     # simple
             
     simple = Simple()
     obj.add_component(simple)
     
     for j in range(-2, 5):
         for k in range(-2, 5):
             map.add_object(obj, 5 + j, 5 + k)
             
             self.assertEqual(self.body.get_distance_to_body(simple), int(math.fabs(j) + math.fabs(k)))
             
     # big
     
     big = Big(3)
     obj.add_component(big)
     
     map.add_object(obj, 2, 2)
     self.assertEqual(self.body.get_distance_to_body(big), 2)
     
     map.add_object(obj, 6, 2)
     self.assertEqual(self.body.get_distance_to_body(big), 2)
     
     map.add_object(obj, 2, 6)
     self.assertEqual(self.body.get_distance_to_body(big), 2)
     
     map.add_object(obj, 6, 6)
     self.assertEqual(self.body.get_distance_to_body(big), 2)
     
     map.add_object(obj, 0, 0)
     self.assertEqual(self.body.get_distance_to_body(big), 6)            
示例#4
0
 def setUp(self):
     self.obj = Object('Test')
     self.body = Big(2)
     self.obj.add_component(self.body)
     create_celltype('Floor', False, False)
     create_celltype('Wall', True, False)
     self.map = create_map('Test', 10, 10, 'Floor')
示例#5
0
 def test_add(self):
     create_celltype('Floor', False, False)
     map = create_map('Test', 10, 20, 'Floor')
     inventory = Inventory()
     obj1 = Object('Test1')
     obj2 = Object('Test2')
     obj3 = Object('Test3')
     map.add_object(obj1, 1, 0)
     map.add_object(obj2, 2, 0)
     map.add_object(obj3, 3, 0)
     
     inventory.add(obj1)
     
     self.assertEquals(len(inventory.objects), 1)
     self.assertTrue(obj1 in inventory.objects)
     self.assertFalse(obj2 in inventory.objects)
     self.assertFalse(obj3 in inventory.objects)
     
     self.assertFalse(obj1.id in map.objects)
     self.assertFalse(obj1.id in map.get_cell(1, 0).objects)
     body = obj1.body
     self.assertEquals(body.map, None)
     self.assertEquals(body.x, None)
     self.assertEquals(body.y, None)        
     
     inventory.add(obj2)
     
     self.assertEquals(len(inventory.objects), 2)
     self.assertTrue(obj1 in inventory.objects)
     self.assertTrue(obj2 in inventory.objects)
     self.assertFalse(obj3 in inventory.objects)
     
     self.assertFalse(obj2.id in map.objects)
     self.assertFalse(obj2.id in map.get_cell(1, 0).objects)
     body = obj2.body
     self.assertEquals(body.map, None)
     self.assertEquals(body.x, None)
     self.assertEquals(body.y, None)
     
     inventory.add(obj3)
     
     self.assertEquals(len(inventory.objects), 3)
     self.assertTrue(obj1 in inventory.objects)
     self.assertTrue(obj2 in inventory.objects)
     self.assertTrue(obj3 in inventory.objects)
     
     self.assertFalse(obj3.id in map.objects)
     self.assertFalse(obj3.id in map.get_cell(1, 0).objects)
     body = obj3.body
     self.assertEquals(body.map, None)
     self.assertEquals(body.x, None)
     self.assertEquals(body.y, None)
     
     inventory.add(obj1)
     
     self.assertEquals(len(inventory.objects), 3)
     self.assertTrue(obj1 in inventory.objects)
     self.assertTrue(obj2 in inventory.objects)
     self.assertTrue(obj3 in inventory.objects)
示例#6
0
 def test_get_occupied_cells(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     
     for x in range(0, 10):
         for y in range(0, 10):
             self.body.add_to_map(self.map, x, y)
             cells = self.body.get_occupied_cells()
             
             self.assertEquals(len(cells), 1)
             self.assertEquals(cells[0], self.map.get_cell(x, y))
示例#7
0
 def test_get_occupied_cells(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     
     for x in range(0, 9):
         for y in range(0, 9):
             self.body.add_to_map(self.map, x, y)
             cells = self.body.get_occupied_cells()
             
             self.assertEquals(len(cells), 4)
             self.assertTrue(self.map.get_cell(x, y) in cells)
             self.assertTrue(self.map.get_cell(x, y + 1) in cells)
             self.assertTrue(self.map.get_cell(x + 1, y) in cells)
             self.assertTrue(self.map.get_cell(x + 1, y + 1) in cells)
示例#8
0
 def test_move(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     self.map.add_object(self.obj, 0, 0)
     
     # inside
     
     self.assertTrue(self.body.move(1))
     self.check(1, 0)
             
     self.assertTrue(self.body.move(0))
     self.check(1, 1)
     
     self.assertTrue(self.body.move(3))
     self.check(0, 1)
     
     self.assertTrue(self.body.move(2))
     self.check(0, 0)
     
     # outside
     
     self.assertFalse(self.body.move(3))
     self.check(0, 0)                
     self.assertFalse(self.body.move(2))
     self.check(0, 0)
     
     self.map.add_object(self.obj, 9, 9)
     
     self.assertFalse(self.body.move(1))
     self.check(9, 9)        
     self.assertFalse(self.body.move(0))
     self.check(9, 9)
     
     # solid
     
     self.map.get_cell(5, 5).celltype = get_celltype('Wall')
     
     self.map.add_object(self.obj, 4, 5)        
     self.assertFalse(self.body.move(1))
     self.check(4, 5)
     
     self.map.add_object(self.obj, 6, 5)        
     self.assertFalse(self.body.move(3))
     self.check(6, 5)
     
     self.map.add_object(self.obj, 5, 4)        
     self.assertFalse(self.body.move(0))
     self.check(5, 4)
     
     self.map.add_object(self.obj, 5, 6)        
     self.check(5, 6)
示例#9
0
 def test_remove_from_map(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     
     for x in range(0, 10):
         for y in range(0, 10):
             self.body.add_to_map(self.map, x, y)        
             self.body.remove_from_map()
             
             self.assertEqual(self.body.map, None)
             self.assertEqual(self.body.x, None)
             self.assertEqual(self.body.y, None)
             
             cell = self.map.get_cell(x, y)
             
             self.assertFalse(self.obj in cell.objects)
     
     for x in range(0, 10):
         for y in range(0, 10):
             self.assertFalse(self.obj in self.map.get_cell(x, y).objects)
示例#10
0
 def test_remove_from_map(self):
     self.map = create_map('Test', 10, 10, 'Floor')
     
     for x in range(0, 9):
         for y in range(0, 9):
             self.body.add_to_map(self.map, x, y)        
             self.body.remove_from_map()
             
             self.assertEqual(self.body.map, None)
             self.assertEqual(self.body.x, None)
             self.assertEqual(self.body.y, None)
             self.assertEquals(len(self.body.occupied_cells), 0)
             
             self.assertFalse(self.obj in self.map.get_cell(x, y).objects)
             self.assertFalse(self.obj in self.map.get_cell(x, y + 1).objects)
             self.assertFalse(self.obj in self.map.get_cell(x + 1, y).objects)
             self.assertFalse(self.obj in self.map.get_cell(x + 1, y + 1).objects)
     
     for x in range(0, 10):
         for y in range(0, 10):
             self.assertFalse(self.obj in self.map.get_cell(x, y).objects)
示例#11
0
 def setUp(self):
     create_celltype('Floor', False, False)
     create_celltype('Wall', True, False)
     self.map = create_map('Test', 10, 20, 'Floor')