我正在学习如何在c#中制作递归迷宫的教程。 这是教程:http://www.c-sharpcorner.com/uploadfile/4a950c/solving-mazes-using-recursion/
我正在按照这些步骤进行操作,但我无法继续使用,因为当我运行此代码时,图片框不会像在教程中那样显示出来。
这是他们应该做的部分:
private void createNewMaze()
{
mazeTiles = new PictureBox[XTILES, YTILES];
//Loop for getting all tiles
for (int i = 0; i < XTILES; i++)
{
for (int j = 0; j < YTILES; j++)
{
//initialize a new PictureBox array at cordinate XTILES, YTILES
mazeTiles[i, j] = new PictureBox();
//calculate size and location
int xPosition = (i * TILESIZE) ; //13 is padding from left
int yPosition = (j * TILESIZE) ; //45 is padding from top
mazeTiles[i, j].SetBounds(xPosition, yPosition, TILESIZE, TILESIZE);
//make top left and right bottom corner light blue. Used for start and finish
if ((i == 0 && j == 0) || (i == XTILES - 1 && j == YTILES - 1))
mazeTiles[i, j].BackColor = Color.LightBlue;
else
{
//make all other tiles white
mazeTiles[i, j].BackColor = Color.White;
//make it clickable
EventHandler clickEvent = new EventHandler(PictureBox_Click);
mazeTiles[i, j].Click += clickEvent; // += used in case other events are used
}
//Add to controls to form (display picture box)
this.Controls.Add(mazeTiles[i, j]);
}
}
}
这是我得到的: Maze
我无法找到解决方案,也许有人可以,提前谢谢。