Beispiel #1
0
        /**
         * PopulateGrid - populate the grid with GridSpaces
         */
        public void PopulateGrid()
        {
            Random random = new Random();

            int spaces        = this.y * this.x;
            int currentSpace  = 0;
            int usableTerrain = 0;

            //Loop through the grid columns and rows
            for (int y = 0; y < this.y; y++)
            {
                for (int x = 0; x < this.x; x++)
                {
                    int rand = random.Next(100);

                    //If unit requires this space to be useable terrain, set it correctly
                    if (spaces - currentSpace == this.units - usableTerrain || spaces - currentSpace < this.units - usableTerrain)
                    {
                        GridSpace space = new GridSpace(0);
                        this.grid[x, y] = space;
                        usableTerrain++;
                    }
                    //If random is less than user set probability make useable terrain
                    else if (rand < this.probability)
                    {
                        GridSpace space = new GridSpace(0);
                        this.grid[x, y] = space;
                        usableTerrain++;
                    }
                    //Else make it unusable terrain
                    else
                    {
                        GridSpace space = new GridSpace(1);
                        this.grid[x, y] = space;
                    }

                    currentSpace++;
                }
            }
        }