Пример #1
0
 def test_block_of_bigger_size_will_hit_the_walls_in_the_next_move(self):
     platform = Platformer(positions=[(2, 1)],
                           directions=[(-1, 0)],
                           block_size=3)
     result = platform.calculate_new_position((2, 1), (-1, 0))
     self.assertEqual((1, 1), result)
     self.assertFalse(platform.block_within_plane(result))
Пример #2
0
 def test_a_single_block_moves_one_iteration_successfully(self):
     platform = Platformer(positions=[(2, 1)], directions=[(-1, 0)])
     platform.move_blocks()
     self.assertEqual(1, len(platform.get_block_positions()))
     self.assertTrue(platform.block_position_exists((1, 1)))
     self.assertListEqual([(1, 1)], platform.get_block_positions())
     self.assertListEqual([(-1, 0)], platform.get_block_directions())
Пример #3
0
 def test_platform_requires_odd_block_sizes_raises_error(self):
     try:
         Platformer(block_size=2)
         self.assertTrue(False)
     except AssertionError as e:
         self.assertTrue(True)
         self.assertEqual(e.message, 'Invalid block size')
Пример #4
0
 def test_two_blocks_move_one_iteration_successfully(self):
     platform = Platformer(positions=[(2, 1), (3, 2)],
                           directions=[(-1, 0), (0, 1)])
     platform.move_blocks()
     self.assertEqual(2, len(platform.get_block_positions()))
     self.assertTrue(platform.block_position_exists((1, 1)))
     self.assertTrue(platform.block_position_exists((3, 3)))
     self.assertListEqual([(1, 1), (3, 3)], platform.get_block_positions())
     self.assertListEqual([(-1, 0), (0, 1)],
                          platform.get_block_directions())
Пример #5
0
 def test_platform_with_custom_positions(self):
     result = Platformer(number_blocks=10, positions=[(2, 3), (3, 4)])
     self.assertEqual(2, len(result.get_block_positions()))
     self.assertTrue(result.block_position_exists((2, 3)))
     self.assertListEqual([(2, 3), (3, 4)], result.get_block_positions())
     self.assertEqual(len(result.get_block_positions()),
                      len(result.get_block_directions()))
Пример #6
0
 def test_basic_custom_platform(self):
     result = Platformer(number_blocks=10)
     self.assertEqual(10, len(result.get_block_positions()))
     self.assertEqual(len(result.get_block_positions()),
                      len(list(set(result.get_block_positions()))))
     self.assertEqual(len(result.get_block_positions()),
                      len(result.get_block_directions()))
Пример #7
0
 def test_10_blocks_of_bigger_size_move_30_iterations_successfully(self):
     platform = Platformer(number_blocks=10, block_size=3)
     for i in range(30):
         platform.move_blocks()
         self.assertEqual(10, len(platform.get_block_positions()))
         self.assertEqual(len(platform.get_block_positions()),
                          len(list(set(platform.get_block_positions()))))
Пример #8
0
 def test_two_blocks_move_30_iterations_successfully(self):
     platform = Platformer(positions=[(3, 1), (3, 2)],
                           directions=[(-1, 0), (0, 1)])
     for i in range(30):
         platform.move_blocks()
         self.assertEqual(2, len(platform.get_block_positions()))
         self.assertEqual(len(platform.get_block_positions()),
                          len(list(set(platform.get_block_positions()))))
Пример #9
0
def the_platform(xz=None):
    block_id = block.WOOD_PLANKS.id
    plane = Plane(x=xz[0], z=xz[1])
    platform = Platformer(number_blocks=NUMBER_BLOCKS, block_size=PLATFORM_BLOCK_SIZE, plane=plane)

    #create the platform shapes
    platform_shapes = []
    for pos in platform.get_block_positions():
        block_pos = Vec3(pos[0], arenaPos.y, pos[1])
        platform_blocks = []
        for x in range(PLATFORM_BLOCK_SIZE):
            for z in range(PLATFORM_BLOCK_SIZE):
                platform_blocks.append(minecraftstuff.ShapeBlock(x, 0, z, block_id))
        platform_shape = minecraftstuff.MinecraftShape(mc, block_pos, platform_blocks)
        platform_shapes.append(platform_shape)

    #move the platforms
    while not levelComplete:
        platform.move_blocks()
        directions = platform.get_block_directions()
        for i in range(len(directions)):
            platform_shapes[i].moveBy(directions[i][0], 0, directions[i][1])
            time.sleep(PLATFORM_SLEEP_TIME)
Пример #10
0
 def test_default_platform(self):
     result = Platformer()
     self.assertEqual(len(result.get_block_positions()),
                      len(list(set(result.get_block_positions()))))
     self.assertEqual(len(result.get_block_positions()),
                      len(result.get_block_directions()))