Beispiel #1
0
        /// <summary>
        /// Get the next step of the path search
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PathTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            _pathTimer.Stop();
            var resetTimer = false;

            // Do the next step in the path
            var searchStatus = _algorithms[_currentAlgorithm].GetPathTick();

            StatsUpdate(searchStatus);

            // If the path is found, draw the path, otherwise draw the updated search
            if (searchStatus.PathFound)
            {
                BuildPath(searchStatus);
            }
            else
            {
                _mazeDrawer.Draw();

                _soundManager.PlaySound(searchStatus.DistanceOfCurrentNode);
                resetTimer = true;
            }

            if (resetTimer)
            {
                _pathTimer.Start();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Set up a maze and initialise the algorithm variables
        /// </summary>
        private void InitialiseMaze()
        {
            _pathTimer.Stop();

            // Generate mazes until one if made that has a valid path between A and B
            var workingSeed = 0;

            while (workingSeed == 0)
            {
                workingSeed = FindWorkingSeed();
            }

            // Set/reset the algorithm settings and draw the maze
            _currentAlgorithm = -1;
            _mazeDrawer       = new MazeDrawer(pbMaze, workingSeed);
            _algorithms       = new AlgorithmBase[] { new Dijkstra(_mazeDrawer.Grid), new AStar(_mazeDrawer.Grid), new BreadthFirst(_mazeDrawer.Grid), new DepthFirst(_mazeDrawer.Grid) };
            Text = @"Path Finding " + _mazeDrawer.Seed;
            _mazeDrawer.Draw();
        }