2

I'm new here. It's OK? My question is simple, I managed to generate walls with this simple for, but I just needed to generate a blank space as if it were a door. I'll leave my code below

enter image description here

class Program
    {
        static void Main(string[] args)
        {

            string[,] m = new string[10, 10];

            int row = m.GetLength(0);
            int colunm = m.GetLength(1);


            for (int i = 0; i < row; i++)
            {
                for (int k = 0; k < colunm; k++)
                {
                    m[i, k] = "-".ToString();

                }
            }


            //    Console.Write(m[1, 1]);

            for (int i = 0; i < row; i++)
            {

                for (int k = 0; k < colunm; k++)
                {
                    if (i == 0 || i == row - 1 || k == 0 || k == colunm - 1)
                        Console.Write(m[i,k] + " ");
                    else
                        Console.Write("  ");

                }
                Console.WriteLine();
            }
            Console.ReadLine();
        }

    }
DerStarkeBaer
  • 669
  • 8
  • 28
  • One way to do it with your current code would be to just set `m[9,4] = " ";` between the loop that fills the array with -s and the loop that prints the border. (But it seems odd that you fill the array for every square and then don't print them all: what was the intention there?) Or you could make an exception in the for loop for the door square. – Rup Jun 14 '20 at 23:43
  • I intend to orient the object in the future and separate it into classes, one class is in charge of generating the shape of the "map" and storing it in the matrix and the other will only print the characters stored in the stored matrix. – Pedro Player.s Jun 14 '20 at 23:46
  • I solved the problem, I thank everyone and I will leave the solution as an edition. – Pedro Player.s Jun 15 '20 at 00:02
  • Please post solution as an "Answer"; not an edit to question. – AmirSina Mashayekh Jun 15 '20 at 11:52

0 Answers0