Exemplo n.º 1
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        public GameBoard()
        {
            // Создание объектов на игровом поле
            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 8; y++)
                {
                    Vector2Int      pos          = new Vector2Int(x, y);
                    GameBoardObject randomObject = CreateRandomElement(pos, pos);
                    objectList.Add(randomObject);
                }
            }

            // Удаление комбинаций образовавшихся после случайной генерации объектов
            ComboList comboList = GetComboList();
            int       iteration = 1;

            while (comboList.Count > 0)
            {
                Debug.WriteLine($"Iteration: {iteration}");
                GameBoardObject newObject      = null;
                int             objectsChanged = 0;
                foreach (List <GameBoardObject> combination in comboList)
                {
                    GameBoardObject middleObject = combination[combination.Count / 2];
                    switch (combination[0].GetType().Name)
                    {
                    case nameof(SquareObject):   newObject = new CircleObject(middleObject.worldPos, middleObject.worldPos);   break;

                    case nameof(CircleObject):   newObject = new TriangleObject(middleObject.worldPos, middleObject.worldPos); break;

                    case nameof(TriangleObject): newObject = new HexagonObject(middleObject.worldPos, middleObject.worldPos);  break;

                    case nameof(HexagonObject):  newObject = new DiamondObject(middleObject.worldPos, middleObject.worldPos);  break;

                    case nameof(DiamondObject):  newObject = new SquareObject(middleObject.worldPos, middleObject.worldPos);   break;
                    }
                    objectList.Remove(middleObject);
                    objectList.Add(newObject);
                    objectsChanged++;
                }
                Debug.WriteLine($"Objects changed: {objectsChanged}");
                comboList = GetComboList();
                iteration++;
            }

            //TurnIntoSquare(new Vector2Int(5, 2));
            //TurnIntoBomb(new Vector2Int(5, 2));
            //TurnIntoSquare(new Vector2Int(4, 2));

            //TurnIntoSquare(new Vector2Int(2, 3));
            //TurnIntoSquare(new Vector2Int(3, 3));
            //TurnIntoSquare(new Vector2Int(4, 3));
            //TurnIntoSquare(new Vector2Int(6, 3));

            //TurnIntoSquare(new Vector2Int(4, 4));
            //TurnIntoSquare(new Vector2Int(5, 4));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Создает случайный элемент.
        /// </summary>
        /// <param name="pos">Позиция объекта на игровом поле.</param>
        public GameBoardObject CreateRandomElement(Vector2Int pos, Vector2 spritePos)
        {
            int             randomNumber       = random.Next(5);
            GameBoardObject newGameBoardObject = null;

            switch (randomNumber)
            {
            case 0: newGameBoardObject = new SquareObject(pos, spritePos);   break;

            case 1: newGameBoardObject = new CircleObject(pos, spritePos);   break;

            case 2: newGameBoardObject = new TriangleObject(pos, spritePos); break;

            case 3: newGameBoardObject = new HexagonObject(pos, spritePos);  break;

            case 4: newGameBoardObject = new DiamondObject(pos, spritePos);  break;
            }
            return(newGameBoardObject);
        }