Example #1
0
 public bool CheckCell(Point cell, Chunk.ChunkType chunkType)
 {
     return _field[cell.X, cell.Y].Type == chunkType;
 }
Example #2
0
        public Point GetNearest(Chunk.ChunkType chunkType, Point point, bool hasResourses = false)
        {
            float distance = float.MaxValue;
            Point p = new Point(-1,-1);

            for (int i = 0; i < Width; i++)
                for (int j = 0; j < Height; j++)
                    if (_field[i, j].Type == chunkType)
                    {
                        if(hasResourses)
                        {
                            if (_field[i, j].Resourses <= 0) continue;
                        }
                        float curDistance = (float) Math.Sqrt(Math.Pow(i - point.X, 2) + Math.Pow(j - point.Y, 2));

                        if (curDistance < distance)
                        {
                            distance = curDistance;
                            p = new Point(i, j);
                        }
                    }
            return p;
        }
Example #3
0
        public Chunk[,] GetRectangle(Rectangle rectangle)
        {
            //  CheckRectangle(ref rectangle);
            Chunk[,] rect = new Chunk[rectangle.Width,rectangle.Height];

            for (int i = rectangle.X; i < rectangle.Width; i++)
            {
                for (int j = rectangle.Y; j < rectangle.Height; j++)
                {
                    rect[i, j] = _field[i, j];
                }
            }
            return rect;
        }
Example #4
0
 public void Generate()
 {
     //TODO generation
     for (int i = 0; i < Width; i++)
     {
         for (int j = 0; j < Height; j++)
         {
             _field[i, j] = new Chunk(Chunk.ChunkType.Grass, 100);
             if(RandomTool.RandBool(0.5f))
             {
                 _field[i, j] = new Chunk(Chunk.ChunkType.Forest, 100);
             }
         }
     }
 }