예제 #1
0
    public void CreateSlots()
    {
        var entityManager = World.Active.GetOrCreateManager <EntityManager>();

        var levelDescription = new LevelDescription()
        {
            Width  = 5,
            Height = 5
        };

        var sceneConfiguration = CreateTestSceneConfiguration();

        var creationPipeline = new CreateSlotsStep(new Dictionary <int2, Entity>(), sceneConfiguration);

        creationPipeline.Apply(levelDescription, entityManager);

        //check
        var entities        = entityManager.GetAllEntities();
        var slotEntityCount = 0;

        for (int i = 0; i < entities.Length; i++)
        {
            if (entityManager.HasComponent <Slot>(entities[i]))
            {
                slotEntityCount++;
            }
        }
        entities.Dispose();

        Assert.AreEqual(25, slotEntityCount);
    }
    public void NoFall()
    {
        var entityManager = World.Active.GetOrCreateManager <EntityManager>();

        var levelDescription = new LevelDescription()
        {
            Width  = 1,
            Height = 3,
            SlotChipDescriptions = new List <SlotChipDescription>()
            {
                new SlotChipDescription()
                {
                    Position = new int2(0, 2),
                    Color    = ChipColor.Red,
                },
            }
        };

        var slotCache          = new Dictionary <int2, Entity>();
        var sceneConfiguration = CreateTestSceneConfiguration();
        var configuration      = CreateTestConfiguration();

        var createSlots = new CreateSlotsStep(slotCache, sceneConfiguration);

        createSlots.Apply(levelDescription, entityManager);

        var createChips = new CreateChipsStep(configuration);

        createChips.Apply(levelDescription, entityManager);

        var nextY = FallSystem.GetNextEmptyRow(entityManager, slotCache, new int2(0, 2));

        Assert.AreEqual(2, nextY);
    }
예제 #3
0
    public void CreateChipsAndFindThreeGroupButNoCombinations()
    {
        var entityManager = World.Active.GetOrCreateManager <EntityManager>();

        var levelDescription = new LevelDescription()
        {
            Width  = 3,
            Height = 3,
            SlotChipDescriptions = new List <SlotChipDescription>()
            {
                new SlotChipDescription()
                {
                    Position = new int2(0, 0),
                    Color    = ChipColor.Red,
                },
                new SlotChipDescription()
                {
                    Position = new int2(1, 0),
                    Color    = ChipColor.Red,
                },
                new SlotChipDescription()
                {
                    Position = new int2(2, 0),
                    Color    = ChipColor.Blue,
                },

                new SlotChipDescription()
                {
                    Position = new int2(0, 1),
                    Color    = ChipColor.Blue,
                },
                new SlotChipDescription()
                {
                    Position = new int2(1, 1),
                    Color    = ChipColor.Red,
                },
                new SlotChipDescription()
                {
                    Position = new int2(2, 1),
                    Color    = ChipColor.Blue,
                },

                new SlotChipDescription()
                {
                    Position = new int2(0, 2),
                    Color    = ChipColor.Yellow,
                },
                new SlotChipDescription()
                {
                    Position = new int2(1, 2),
                    Color    = ChipColor.Yellow,
                },
                new SlotChipDescription()
                {
                    Position = new int2(2, 2),
                    Color    = ChipColor.Yellow,
                },
            }
        };

        var sceneConfiguration = CreateTestSceneConfiguration();
        var configuration      = CreateTestConfiguration();
        var slotCache          = new Dictionary <int2, Entity>();
        var createSlots        = new CreateSlotsStep(slotCache, sceneConfiguration);

        createSlots.Apply(levelDescription, entityManager);


        var createChips = new CreateChipsStep(configuration);

        createChips.Apply(levelDescription, entityManager);

        var combinationList = new NativeList <Entity>(64, Allocator.Temp);
        var visited         = new NativeHashMap <int2, bool>(64, Allocator.Temp);

        FindCombinationsSystem.Find(entityManager, slotCache, new int2(0, 0), ref visited, ref combinationList);
        Assert.AreEqual(3, combinationList.Length);
        Assert.IsFalse(FindCombinationsSystem.IsCorrectCombination(entityManager, combinationList, levelDescription.Width, levelDescription.Height));

        visited.Dispose();
        combinationList.Dispose();
    }