示例#1
0
        /// <summary>
        /// Превращает объект в заданной позиции в Line.
        /// </summary>
        public void TurnIntoLine(Vector2Int pos)
        {
            GameBoardObject obj  = GetObjectAtPosition(pos);
            LineBonus       bomb = new LineBonus(obj, true, obj.worldPos, obj.worldPos);

            objectList.Remove(obj);
            objectList.Add(bomb);
        }
示例#2
0
        private void onLineBonusUpdate(LineBonus linebonus, LineBonus.LineBonusEventAgrs lineEventArgs)
        {
            List <Element> elements = GetElementsBetweenPositions(
                lineEventArgs.prevPosition.ToPoint(), lineEventArgs.newPosition.ToPoint()
                );

            foreach (Element el in elements)
            {
                DestroyElement(el);
            }
        }
示例#3
0
        private LineBonus CreateLineBonus(Element el, int colEnd, int rowEnd, Vector2 dir)
        {
            LineBonus res = new LineBonus(Game,
                                          el.rectangle.Center.ToVector2(),
                                          GetRectangleByColAndRow(colEnd, rowEnd).Center.ToVector2(),
                                          dir,
                                          Config.lineBonusShift);

            res.onUpdate += onLineBonusUpdate;
            res.onEnd    += onLineBonusUpdate;
            return(res);
        }
示例#4
0
        /// <summary>
        /// Активирует бонус Line.
        /// </summary>
        public void TriggerLineBonus(LineBonus lineBonus)
        {
            Debug.WriteLine("Creating destroyers");
            // Скорость разрушителей
            Vector2 destroyerDestination1;
            Vector2 destroyerDestination2;

            if (lineBonus.vertical)
            {
                destroyerDestination1 = new Vector2(lineBonus.worldPos.x, -1.0f);
                destroyerDestination2 = new Vector2(lineBonus.worldPos.x, 8.0f);
            }
            else
            {
                destroyerDestination1 = new Vector2(-1.0f, lineBonus.worldPos.y);
                destroyerDestination2 = new Vector2(8.0f, lineBonus.worldPos.y);
            }
            // Создание разрушителей
            Destroyer destroyer1 = new Destroyer(lineBonus.worldPos);
            Destroyer destroyer2 = new Destroyer(lineBonus.worldPos);

            destroyerList.Add(destroyer1);
            destroyerList.Add(destroyer2);
            // Запуск анимации
            MoveAnimation moveAnimation1 = new MoveAnimation(
                destroyer1,
                speed: 10.0,
                lineBonus.worldPos,
                destroyerDestination1,
                blocking: true,
                finishedCallback: _ => destroyerList.Remove(destroyer1)
                );
            MoveAnimation moveAnimation2 = new MoveAnimation(
                destroyer2,
                speed: 10.0,
                lineBonus.worldPos,
                destroyerDestination2,
                blocking: true,
                finishedCallback: _ => destroyerList.Remove(destroyer2)
                );

            activeAnimations.Add(moveAnimation1);
            activeAnimations.Add(moveAnimation2);
        }
示例#5
0
        /// <summary>
        /// Удаление комбинаций.
        /// </summary>
        public void DeleteCombos(ComboList comboList)
        {
            // Список удаляемых объектов
            List <GameBoardObject> objectsToDelete = comboList.SelectMany(tempList => tempList).ToList();

            score += objectsToDelete.Count;

            // Срабатывание бонусов
            List <LineBonus> lineBonuses = objectsToDelete.FindAll(obj => obj.GetType() == typeof(LineBonus)).Cast <LineBonus>().ToList();

            foreach (LineBonus lineBonus in lineBonuses)
            {
                TriggerLineBonus(lineBonus);
                currentGamePhase = GamePhase.Bonus;
            }
            List <BombBonus> bombBonuses = objectsToDelete.FindAll(obj => obj.GetType() == typeof(BombBonus)).Cast <BombBonus>().ToList();

            foreach (BombBonus bombBonus in bombBonuses)
            {
                TriggerBombBonus(bombBonus);
                currentGamePhase = GamePhase.Bonus;
            }

            // Если бонусы активны, то новые создавать нельзя.
            if (currentGamePhase == GamePhase.Bonus)
            {
                return;
            }

            // Запуск анимации исчезновения
            implodingObjects.Clear();
            foreach (GameBoardObject obj in objectsToDelete)
            {
                implodingObjects.Add(obj);
                ScaleAnimation implodeAnimation = new ScaleAnimation(obj, 1.0, 0.0, blocking: true, finishedCallback: _ => objectList.Remove(obj));
                activeAnimations.Add(implodeAnimation);
            }

            // Бонус Bomb
            // Комбинации из 5 и более
            List <Vector2Int>      newBombPositions       = new List <Vector2Int>();
            ComboList              combinationsOf5AndMore = comboList.FindAll(combination => combination.Count >= 5);
            List <GameBoardObject> combination            = combinationsOf5AndMore.Find(combination => combination.Contains(objectSwap2));

            if (combination != null)
            {
                CreateBombBonus(objectSwap2);
                newBombPositions.Add(objectSwap2.worldPos);
            }
            // Перекрестные комбинации из 3 и более
            CrossList crosses = new CrossList();
            ComboList verticalCombinations   = comboList.FindAll(combination => combination[0].worldPos.x == combination[1].worldPos.x);
            ComboList horizontalCombinations = comboList.FindAll(combination => combination[0].worldPos.y == combination[1].worldPos.y);

            foreach (List <GameBoardObject> verticalCombination in verticalCombinations)
            {
                foreach (List <GameBoardObject> horizontalCombination in horizontalCombinations)
                {
                    List <GameBoardObject> intersection = verticalCombination.Intersect(horizontalCombination).ToList();
                    if (intersection.Count > 0)
                    {
                        GameBoardObject objectAtIntersection = intersection[0];
                        if (!newBombPositions.Contains(objectAtIntersection.worldPos))
                        {
                            CreateBombBonus(objectAtIntersection);
                            newBombPositions.Add(objectAtIntersection.worldPos);
                        }
                    }
                }
            }
            // Бонус Line
            ComboList combinationsOf4 = comboList.FindAll(combination => combination.Count == 4);

            combination = combinationsOf4.Find(combination => combination.Contains(objectSwap2));
            if (combination != null && !newBombPositions.Contains(objectSwap2.worldPos))
            {
                Debug.WriteLine($"Creating line bonus in {objectSwap2.worldPos}");
                bool vertical = combination[0].worldPos.x == combination[1].worldPos.x;
                // Создаем объект
                LineBonus newLineBonus = new LineBonus(objectSwap2, vertical, objectSwap2.worldPos, objectSwap2.worldPos);
                objectList.Add(newLineBonus);
                // Запускаем анимацию появления
                ScaleAnimation spawnAnimation = new ScaleAnimation(newLineBonus, 0.0, 1.0, blocking: true);
                activeAnimations.Add(spawnAnimation);
            }
        }