Esempio n. 1
0
        /// <summary>
        /// Gets a reference to a neighbouring Cell (if any) in the specified direction.
        /// The direction will be automatically rounded to the nearest Cell.
        ///
        /// If there is a wall in that direction, then null is returned.
        /// </summary>
        /// <param name="direction"> the direction in which to grab the neighbouring Cell. </param>
        /// <returns> the neighbouring Cell in the specified direction. </returns>
        public Cell GetAdjacentCell(Direction direction)
        {
            double radians = direction.GetRadians();

            int relativeRow    = -(int)Math.Round(Math.Cos(radians));
            int relativeColumn = (int)Math.Round(Math.Sin(radians));

            int targetRow    = position.Row + relativeRow;
            int targetColumn = position.Column + relativeColumn;

            Cell target = pigWorld.GetCell(new Position(targetRow, targetColumn));

            if (target == null)
            {
                return(null);
            }

            // If there's a wall between this cell and the target cell ...
            if (pigWorld.IsWallBetweenCells(this, target))
            {
                return(null);
            }

            return(target);
        }
Esempio n. 2
0
 /// <summary>
 /// Creates all the CellViews in this PigWorldView.
 /// </summary>
 private void CreateCellViews()
 {
     cellViews = new CellView[pigWorld.NumOfRows, pigWorld.NumOfColumns];
     for (int row = 0; row < pigWorld.NumOfRows; row++)
     {
         for (int column = 0; column < pigWorld.NumOfColumns; column++)
         {
             Cell     cell        = pigWorld.GetCell(new Position(row, column));
             CellView newCellView = new CellView(this, cell);
             cellViews[row, column] = newCellView;
         }
     }
 }