/// <summary>
        /// Returns a rectangle focused on the given Game Object,
        /// so that its centre equals to the object position if possible.
        /// </summary>
        private FixedBoundRectangle GetFocusRectangle(Board board, GameObject focus)
        {
            var focusRectangle = new FixedBoundRectangle(
                0,
                0,
                Math.Min(board.Width, Console.WindowWidth),
                Math.Min(board.Height, Console.WindowHeight));

            var playerPosition = focus.Position;

            if (playerPosition.X - focusRectangle.Width / 2 >= 0)
            {
                focusRectangle.Right = Math.Min(board.Width, playerPosition.X + focusRectangle.Width / 2);
            }

            if (playerPosition.X + focusRectangle.Width / 2 < board.Width)
            {
                focusRectangle.Left = Math.Max(0, playerPosition.X - focusRectangle.Width / 2);
            }

            if (playerPosition.Y - focusRectangle.Height / 2 >= 0)
            {
                focusRectangle.Bottom = Math.Min(board.Height, playerPosition.Y + focusRectangle.Height / 2);
            }

            if (playerPosition.Y + focusRectangle.Height / 2 < board.Height)
            {
                focusRectangle.Top = Math.Max(0, playerPosition.Y - focusRectangle.Height / 2);
            }
            return(focusRectangle);
        }
Beispiel #2
0
 private void DrawBoard(Board board, GameObject focus)
 {
     focusRectangle = GetFocusRectangle(board, focus);
     for (var row = focusRectangle.Top; row < focusRectangle.Bottom; row++)
     {
         for (var col = focusRectangle.Left; col < focusRectangle.Right; col++)
         {
             var currentPosition = new Position(row, col);
             DrawObject(board, currentPosition, BoardToConsolePosition(currentPosition));
         }
     }
 }