This script does not work... Words repeated the most on this site.

Try this out. Plug it in on an online compiler or in mono/visual. This should print a cube of ‘0’ in the console.

public static int width = 10, height = 10;
		public static char bChar = ' ';
		public static char wChar = '0';
		
		public static void Main(string[] args)
		{
			CreateEmptySpace();
		}
		
		public static void CreateEmptySpace()
		{
			List<List<char>> bG = new List<List<char>>();
			
			for(int i = 0; i < height; i ++)
			{
				bG.Add(new List<Char>());
				for(int j = 0; j < width; j ++)
				{
					bG*.Add(bChar);*
  •  			if(i == height - 1 && j == width - 1)*
    
  •  			{*
    
  •  				CreateWalls(bG);*
    
  •  			}*
    
  •  		}*
    
  •  	}*
    
  •  }*
    
  •  public static void CreateWalls(List<List<char>> bG)*
    
  •  {*
    
  •  	for(int i = 0; i < height; i++)*
    
  •  	{*
    

_ bG*[0] = wChar;_
_ bG[height - 1] = ‘0’;
for(int j = 0; j < width; j++)
{
bG[0][j] = wChar;
bG[height - 1][j] = wChar;
if(i == height - 1 && j == width - 1)
{
Draw(bG);
}
}
}
}
public static void Draw(List<List> bG)
{
for(int i = 0; i < height; i++)
{
Console.Write("
");
for(int j = 0; j < width; j++)
{
Console.Write(bG[j]);
}
}
}
… but it doesn’t. This has been screwing with me for a while.*_

You are always calling the following method from inside the double loop of the previous method - so you end up printing an awful lot of stuff…

You should first concentrate on populating the lists and then call Draw() once to draw everyting if thats the way you want to go.

As for populating the list, the ‘wall character’ should be put into the lists whenever i is 0 or height-1 or j is 0 or width-1 ( if I’m reading your mind right. You are not really describing what you want and what goes wrong). So all you should need is one ‘if’ with 4 conditions inside the inner loop in CreateWall.

	public static int width = 10, height = 10;
	public static char bChar = ' ';
	public static char wChar = '0'; 
	public static List<List<char>> bG = new List<List<char>>();

	public static void Main(string[] args)
	{
		CreateEmptySpace();
		CreateWalls();
		Draw ();
	}

	public static void CreateEmptySpace()
	{	
            // only create the Lists here and fill with empty chars
		for(int i = 0; i < height; i ++)
		{
			bG.Add(new List<Char>());
			for(int j = 0; j < width; j ++)
			{
				bG*.Add(bChar);*
  •  	}*
    
  •  }*
    
  • }*

  • public static void CreateWalls()*

  • {*
    // Only insert the wall chars here

  •  for(int i = 0; i < height; i++)*
    
  •  {*
    
  •  	for(int j = 0; j < width; j++)*
    
  •  	{*
    

// should be wall char if…

  •  		if(i == 0 || // first row* 
    
  •  		   j == 0 || // first column*
    
  •  		   i == height - 1 || // last row*
    
  •  		   j == width - 1) // last column*
    
  •  		{*
    

_ bG*[j] = wChar;_
_
}_
_
}_
_
}_
_
}*_

* public static void Draw()*
* {*
* for(int i = 0; i < height; i++)*
* {*
// draw a line of characters
* for(int j = 0; j < width; j++)*
* {*
_ Console.Write(bG*[j]);
}
// then change row*
* Console.Write("
");
}
}*_