public PodGridConfiguration(int maxRows, int maxCols)
 {
     MaxRows = maxRows;
     MaxCols = maxCols;
     Grid = new Pod[MaxRows,MaxCols];
     PodList = new List<Pod>();
     _curRow = 0;
 }
Exemple #2
0
 internal void Update(Pod pod)
 {
     Images = pod.Images;
     States = pod.States;
 }
        /// <summary>
        ///     Sets the RowSpan and ColSpan of a pod from the 2D array.
        /// </summary>
        /// <param name="p">Pod to set the info for</param>
        /// <param name="row">Starting row location</param>
        /// <param name="col">Starting col location</param>
        private void SetRowColSpans(Pod p, int row, int col)
        {
            p.ColSpan = 0;
            p.RowSpan = 0;
            do
            {
                p.RowSpan++;
                row++;
            } while (row < MaxRows && p == Grid[row, col]);

            row--;

            do
            {
                p.ColSpan++;
                col++;
            } while (col < MaxCols && p == Grid[row, col]);
        }
 /// <summary>
 ///     Fills a pod into the grid
 /// </summary>
 /// <param name="p">The pod to fill</param>
 /// <param name="row">The starting row</param>
 /// <param name="col">The starting col</param>
 /// <param name="numRows">The number of rows</param>
 /// <param name="numCols">The number of cols</param>
 private void Fill(Pod p, int row, int col, int numRows, int numCols)
 {
     p.Row = row;
     p.Col = col;
     PodList.Add(p);
     for (int r = 0; r < numRows; r++)
     {
         for (int c = 0; c < numCols; c++)
         {
             Grid[row + r, col + c] = p;
         }
     }
 }
        /// <summary>
        ///     Places a pod with a given size into the grid
        /// </summary>
        /// <param name="p">The pod to place</param>
        /// <param name="numRows">Desired number of rows</param>
        /// <param name="numCols">Desired number of cols</param>
        /// <returns>True if the pod was placed</returns>
        public bool Place(Pod p, int numRows, int numCols)
        {
            for (Row = _curRow; Row < MaxRows; Row++)
            {
                for (Col = 0; Col < MaxCols; Col++)
                {
                    if (CanPlace(numRows, numCols))
                    {
                        Fill(p, Row, Col, numRows, numCols);
                        p.RowSpan = numRows;
                        p.ColSpan = numCols;
                        _curRow = Row;
                        return true;
                    }
                }
            }

            return false;
        }