示例#1
0
文件: Form1.cs 项目: giladsch/Maze
 public void clearGrid()
 {
     for (int i = 0; i < grid.GetLength(0); i++)
     {
         for (int j = 0; j < grid.GetLength(1); j++)
         {
             grid[i, j].resetBackColor();
         }
     }
     currPos.BackColor(0, 0);
 }
示例#2
0
        private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //MessageBox.Show(e.X.ToString() + " , " + e.Y.ToString());

            start   = grid[0, 0];
            end     = grid[numOfBlocks - 1, numOfBlocks - 1];
            currPos = start;
            currPos.BackColor(0, 0);

            HideGrid();

            if (clearRec == true)
            {
                clearGrid();
            }

            ResetGrid();

            Generate(start);

            ShowGrid();



            /*
             * start.removeFirst();
             */
            end.removeLast();
        }
示例#3
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                Application.Exit();
            }

            else if (currPos != null)
            {
                int x = currPos.x;
                int y = currPos.y;

                if (e.KeyCode == Keys.R)
                {
                    //Create a previously searched array
                    bool[,] alreadySearched = new bool[numOfBlocks, numOfBlocks];
                    //Starts the recursive solver at tile (0,0). If false maze can not be solved.
                    if (!solveMazeRecursion(0, 0, alreadySearched))
                    {
                        MessageBox.Show("Maze can not be solved.");
                    }
                    clearRec = true;
                }
                else if (e.KeyCode == Keys.A)
                {
                    aStar();
                    clearRec = true;
                }
                else if (e.KeyCode == Keys.Up)
                {
                    if (!currPos.walls[0])
                    {
                        currPos.resetBackColor();
                        currPos.show();
                        currPos.LineVisited();
                        currPos.BackColor(x, --y);
                        currPos = grid[x, y];
                    }
                }
                else if (e.KeyCode == Keys.Left)
                {
                    if (!currPos.walls[1])
                    {
                        currPos.resetBackColor();
                        currPos.show();
                        currPos.LineVisited();
                        currPos.BackColor(--x, y);
                        currPos = grid[x, y];
                    }
                }
                else if (e.KeyCode == Keys.Down)
                {
                    if (!currPos.walls[2])
                    {
                        currPos.resetBackColor();
                        currPos.show();
                        currPos.LineVisited();
                        currPos.BackColor(x, ++y);
                        currPos = grid[x, y];
                    }
                }
                else if (e.KeyCode == Keys.Right)
                {
                    if (!currPos.walls[3])
                    {
                        currPos.resetBackColor();
                        currPos.show();
                        currPos.LineVisited();
                        currPos.BackColor(++x, y);
                        currPos = grid[x, y];
                    }
                }
            }
        }