예제 #1
0
        //Добавляет в стэш спавнера бонус-элемент
        private void SpawnBonus(Vector2 spawnPosition, ElementToCreate elementToCreate, Vector2 lineBonusDest)
        {
            switch (elementToCreate)
            {
            case ElementToCreate.LineBonus:
                Texture2D texture;
                if (lineBonusDest.X == 1)
                {
                    texture = MainGameState.LinePlanetTextures[(int)this.planetType];
                }
                else
                {
                    texture = MainGameState.LinePlanetTextures[(int)this.planetType + 5];
                }
                LineBonus temp_sprite = new LineBonus(texture)
                {
                    planetType     = this.planetType,
                    Position       = spawnPosition,
                    BonusDirection = lineBonusDest
                };
                MainGameState.spriteSpawner.AddBonusToStash(temp_sprite);
                break;

            case ElementToCreate.Bomb:
                Bomb bomb = new Bomb(MainGameState.BombPlanetTextures[(int)this.planetType])
                {
                    Position   = spawnPosition,
                    planetType = this.planetType
                };
                MainGameState.spriteSpawner.AddBonusToStash(bomb);
                break;
            }
        }
예제 #2
0
        public override void MatchDetection(GameTime gameTime, List <Sprite> sprites)
        {
            if (IsRemoved == false && GetType() != typeof(Destroyer))
            {
                int             indexOf_X;
                List <Sprite>   cleared_sprites = sprites.Where(sp => sp.GetType() != typeof(Destroyer)).Select(x => x).ToList();
                Vector2         spawnPosition   = this.Position;
                ElementToCreate elementToCreate = ElementToCreate.None;


                //Горизонтальная проверка
                List <Sprite> x_neighbours = cleared_sprites.Where(sprite => sprite.rectangle.Top == rectangle.Top)
                                             .OrderBy(x => x.Position.X).ToList();
                indexOf_X = x_neighbours.IndexOf(this);
                int right_matches = GetMatchElements(x_neighbours, indexOf_X, 1);
                int left_matches  = GetMatchElements(x_neighbours, indexOf_X, -1);

                int indexOf_Y;
                ////Вертикальная проверка
                List <Sprite> y_neighbours = cleared_sprites.Where(sprite => sprite.Position.X == Position.X)
                                             .OrderBy(x => x.Position.Y).ToList();
                indexOf_Y = y_neighbours.IndexOf(this);
                int bot_matches = GetBottomMatchElements(y_neighbours, indexOf_Y, 1);
                int top_matches = GetBottomMatchElements(y_neighbours, indexOf_Y, -1);

                //Текущий элемент точно на пересечении
                if (right_matches + left_matches >= 2 && top_matches + bot_matches >= 2)
                {
                    spawnPosition   = this.Position;
                    elementToCreate = ElementToCreate.Bomb;
                    SpawnBonus(spawnPosition, elementToCreate, new Vector2(0, 0));
                    //DeleteMatchElements(right_matches, left_matches, indexOf_X, x_neighbours);
                    //DeleteMatchElements(bot_matches, top_matches, indexOf_Y, y_neighbours);
                    //return;
                }
                //Поиск потенциального пересечения двигаясь по Х
                else if (right_matches + left_matches >= 2)
                {
                    for (int i = indexOf_X - left_matches; i <= right_matches + indexOf_X; i++)
                    {
                        int new_indexOf_Y;
                        ////Вертикальная проверка
                        List <Sprite> new_y_neighbours = cleared_sprites.Where(sprite => sprite.Position.X == x_neighbours[i].Position.X)
                                                         .OrderBy(x => x.Position.Y).ToList();
                        new_indexOf_Y = new_y_neighbours.IndexOf(x_neighbours[i]);
                        int new_bot_matches = GetBottomMatchElements(new_y_neighbours, new_indexOf_Y, 1);
                        int new_top_matches = GetBottomMatchElements(new_y_neighbours, new_indexOf_Y, -1);
                        if (new_bot_matches + new_top_matches < 2)
                        {
                            continue;
                        }
                        else
                        {
                            spawnPosition   = x_neighbours[i].Position;
                            elementToCreate = ElementToCreate.Bomb;
                            SpawnBonus(spawnPosition, elementToCreate, new Vector2(0, 0));
                            DeleteMatchElements(new_bot_matches, new_top_matches, new_indexOf_Y, new_y_neighbours);
                            //return;
                        }
                    }
                    if (right_matches + left_matches == 3)
                    {
                        SpawnBonus(this.Position, ElementToCreate.LineBonus, new Vector2(1, 0));
                    }
                    else if (right_matches + left_matches > 3)
                    {
                        SpawnBonus(this.Position, ElementToCreate.Bomb, new Vector2(0, 0));
                    }
                }
                //Поиск потенциального пересечения двигаясь по Y
                else if (top_matches + bot_matches >= 2)
                {
                    for (int i = indexOf_Y - top_matches; i <= bot_matches + indexOf_Y; i++)
                    {
                        int new_indexOf_X;
                        //Горизонтальная проверка
                        List <Sprite> new_x_neighbours = cleared_sprites.Where(sprite => sprite.rectangle.Top == y_neighbours[i].rectangle.Top)
                                                         .OrderBy(x => x.Position.X).ToList();
                        new_indexOf_X = new_x_neighbours.IndexOf(y_neighbours[i]);
                        int new_right_matches = GetMatchElements(new_x_neighbours, new_indexOf_X, 1);
                        int new_left_matches  = GetMatchElements(new_x_neighbours, new_indexOf_X, -1);

                        if (new_left_matches + new_right_matches < 2)
                        {
                            continue;
                        }
                        else
                        {
                            SpawnBonus(y_neighbours[i].Position, ElementToCreate.Bomb, new Vector2(0, 0));
                            DeleteMatchElements(new_right_matches, new_left_matches, new_indexOf_X, new_x_neighbours);
                        }
                    }

                    if (top_matches + bot_matches == 3)
                    {
                        SpawnBonus(this.Position, ElementToCreate.LineBonus, new Vector2(0, 1));
                    }
                    else if (top_matches + bot_matches > 3)
                    {
                        SpawnBonus(this.Position, ElementToCreate.Bomb, new Vector2(0, 0));
                    }
                }

                //Обязательная подчистка всего остального
                if (right_matches + left_matches >= 2)
                {
                    DeleteMatchElements(right_matches, left_matches, indexOf_X, x_neighbours);
                }
                if (top_matches + bot_matches >= 2)
                {
                    DeleteMatchElements(bot_matches, top_matches, indexOf_Y, y_neighbours);
                }

                //SpawnBombsDeleteMatches(sprites, ref indexOf_X, x_neighbours, ref right_matches, left_matches, new Vector2(1, 0));
                //SpawnBombsDeleteMatches(sprites, ref indexOf_Y, y_neighbours, ref bot_matches, top_matches, new Vector2(0, 1));
            }
        }