Exemple #1
0
 private bool StartWave(PlaygroundBlock block, List<IInteractive> enemies)
 {
     int row = block.PositionOnPlayground.X;
     int col = block.PositionOnPlayground.Y;
     for (int i = row - 1; i <= (row + 1); i++)
     {
         for (int j = col - 1; j <= (col + 1); j++)
         {
             PlaygroundBlock nextBlock = _blocks[i, j];
             if ((nextBlock is WaterBlock) && !_forReplaceBuffer.Contains(nextBlock))
             {
                 if (enemies.Any(interactive => interactive.Intersects(block)))
                     return false;
                 _forReplaceBuffer.Add(nextBlock);
                 if (!StartWave(nextBlock, enemies))
                     return false;
             }
         }
     }
     return true;
 }
Exemple #2
0
 private void InitWaveFrom(PlaygroundBlock startBlock, List<IInteractive> enemies)
 {
     int row = startBlock.PositionOnPlayground.X;
     int col = startBlock.PositionOnPlayground.Y;
     for (int i = row - 1; i < (row + 2); i++)
     {
         for (int j = col - 1; j < (col + 2); j++)
         {
             _forReplaceBuffer.Clear();
             PlaygroundBlock nextBlock = _blocks[i, j];
             if (nextBlock is WaterBlock)
                 if (StartWave(nextBlock, enemies))
                     foreach (PlaygroundBlock playgroundBlock in _forReplaceBuffer)
                         ReplaceWithGround(playgroundBlock);
         }
     }
 }
Exemple #3
0
 private void Replace(PlaygroundBlock oldBlock, PlaygroundBlock newBlock)
 {
     newBlock.Position = oldBlock.Position;
     _blocks[oldBlock.PositionOnPlayground.X, oldBlock.PositionOnPlayground.Y] = newBlock;
 }
Exemple #4
0
 public void ReplaceWithWater(PlaygroundBlock oldBlock)
 {
     if (!Game.Completed)
         Game.Scores--;
     oldBlock.Destroy();
     Replace(oldBlock, new WaterBlock(this, oldBlock.PositionOnPlayground));
 }
Exemple #5
0
 public void ReplaceWithPath(PlaygroundBlock oldBlock)
 {
     var pathBlock = new PathBlock(this, oldBlock.PositionOnPlayground);
     Replace(oldBlock, pathBlock);
     _path.Add(pathBlock);
 }
Exemple #6
0
 public void ReplaceWithFixedGround(PlaygroundBlock oldBlock)
 {
     Replace(oldBlock, new FixedGroundBlock(this, oldBlock.PositionOnPlayground));
 }
Exemple #7
0
 public void ReplaceWithDeadPath(PlaygroundBlock oldBlock)
 {
     var deadPathBlock = new DeadPathBlock(this, oldBlock.PositionOnPlayground);
     Replace(oldBlock, deadPathBlock);
     _deadPath.Add(deadPathBlock);
 }
        public PlaygroundBlock[,] GenerateBlocks()
        {
            var blocks = new PlaygroundBlock[_height,_width];
            //генерируем границы
            for (int j = 0; j < _width; j++)
            {
                blocks[0, j] = new BorderBlock(_playground, new Point(0, j));
                blocks[_height - 1, j] = new BorderBlock(_playground, new Point(_height - 1, j));
            }
            for (int i = 0; i < _height; i++)
            {
                blocks[i, 0] = new BorderBlock(_playground, new Point(i, 0));
                blocks[i, _width - 1] = new BorderBlock(_playground, new Point(i, _width - 1));
            }

            for (int i = 1; i < (_height - 1); i++)
            {
                for (int j = 1; j < (_width - 1); j++)
                {
                    blocks[i, j] = new FixedGroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = 7; i < (_height - 7); i++)
            {
                for (int j = 7; j < (_width - 7); j++)
                {
                    blocks[i, j] = new WaterBlock(_playground, new Point(i, j));
                }
            }

            for (int i = 7; i < 14; i++)
            {
                for (int j = 7; j <= (20 - i%14); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = 7; i < 14; i++)
            {
                for (int j = _width - 14 + (i - 7)%7; j <= _width - 7; j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height - 14; i <= (_height - 7); i++)
            {
                for (int j = 7; j <= (7 + 14 - (_height - i)); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height - 14; i <= (_height - 7); i++)
            {
                for (int j = _width - 7; j >= (_width - 7 - (i - (_height - 14))); j--)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height/2 - 7; i < (_height/2); i++)
            {
                for (int j = _width/2; j < (_width/2 + i - (_height/2 - 7)); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height/2 - 7; i < (_height/2); i++)
            {
                for (int j = _width/2; j > (_width/2 - i + (_height/2 - 7)); j--)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height/2; i < (_height/2 + 7); i++)
            {
                for (int j = _width/2; j < (_width/2 + 7 - (i - (_height/2))); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }

            for (int i = _height/2; i < (_height/2 + 7); i++)
            {
                for (int j = 1 + _width/2 - 7 + (i - _height/2); j < (_width/2); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }
            /*for (int i = _height / 2 - _height / 8; i < (_height / 2 + _height/8); i++)
            {
                for (int j = _width/2 - _width/8; j < (_width / 2 + _width / 8); j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }*/
            /*
            for (int i = _height/4; i < 3*_height/4; i++)
            {
                for (int j = _width / 4; j < 3 * _width / 4; j++)
                {
                    blocks[i, j] = new GroundBlock(_playground, new Point(i, j));
                }
            }
            */
            /*for (int i = 0; i < _width; i++)
            {
                for (int j = 0; j < _height; j++)
                {
                    blocks[i, j] = new BorderBlock(_game) {Position = GetBlockPosition(i, j)};
                }
            }*/
            return blocks;
        }