Please help me with the task: Draw lit area

Hello, I’m working on this task:

Next, take the class Point from the previous task and rename it to Point2D (2D stands for two-dimensional). Also take the LitArea class and rename it to LitArea2D. Add a public method Draw() to the LitArea2D class that takes no arguments and returns void. In the Main method, read four integers from the console, each from the new line: xTopLeft , yTopLeft , xBottomRight, and yBottomRight . Create an object of type LitArea2D, passing these four integers as parameters to a constructor. These four integers represent coordinates on a 2D grid: the coordinate system starts in the top left corner; X axes are horizontal, and Y are vertical. See the following figure for an example. Implement method Draw() in the class LitArea2D to draw an area using ASCII art, according to integer coordinates that the user input. The dark area to the left and above the lit area should be indicated with a dot (“.”), and the lit area itself with a pound sign (“#”). Then, call this method from Main. For example:
>2
>3
>5
>6



…####
…####
…####
…####
/* In the above example, the lit area starts at point [2, 3] and ends at point [5, 6] */

Example 2:
>0
>0
>2
>4

/* In the above example, the lit area starts at point [0, 0] and ends at point [2, 4] */

Here is my code:


namespace AccessModifiers
{
   class Point2D
   {
       public int X;
       public int Y;
   }

   class LitArea2D
   {
       private Point2D _topLeft;
       private Point2D _bottomRight;

       public LitArea2D(int xTopLeft, int yTopLeft, int xBottomRight, int yBottomRight)
       {
           _topLeft = new Point2D
           {
               X = xTopLeft,
               Y = yTopLeft
           };
           _bottomRight = new Point2D
           {
               X = xBottomRight,
               Y = yBottomRight
           };
       }
       public void Draw()
       {
           for(int i = 0; i < _bottomRight.Y + 1; i++)
           {
               for(int j = 0; j < _bottomRight.X + 1; j++)
               {
                   if(i >= _topLeft.X && j >= _topLeft.Y)
                       Console.Write("#");
                   else
                       Console.Write(".");
               }
               Console.WriteLine();
           }
       }
   }

   class DrawLitArea
   {
       public static void Main()
       {
           int xTopLeft = int.Parse(Console.ReadLine());
           int yTopLeft = int.Parse(Console.ReadLine());
           int xBottomRight = int.Parse(Console.ReadLine());
           int yBottomRight = int.Parse(Console.ReadLine());

           var area = new LitArea2D(xTopLeft, yTopLeft, xBottomRight, yBottomRight);
           area.Draw();
       }
   }
}

Can anyone please help me to solve it?

The logic is correct! But in the following line:

you’ve accidentally switched X and Y and got a reversed result. i is responsible for Y direction, and j for X.

1 Like

Ohh, god bless you. I did`nt see it. :face_holding_back_tears: :heart: