예제 #1
0
        // This is called when Space key is pressesd.
        public static void TestOnSpace(object sender, OnPathChangedEventArgs onPathChangedEventArgs)
        {
            PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;

            if (onPathChangedEventArgs.pathFinding != null)
            {
                for (int i = 1; i < onPathChangedEventArgs.pathFinding.GetVisitedPath().Count; i++)
                {
                    PathNode searchNode = onPathChangedEventArgs.pathFinding.GetVisitedPath()[i];
                    SplashKit.FillRectangle(Color.LightBlue, searchNode.X * pathFindingGUI.CellSize + 2, searchNode.Y * pathFindingGUI.CellSize + 2, pathFindingGUI.CellSize - 2, pathFindingGUI.CellSize - 2);
                    if (i % 5 == 0)
                    {
                        pathFindingGUI.window.Refresh(60);
                    }
                }
                // If there is no path found, return.
                if (pathFindingGUI.pathNodes == null)
                {
                    return;
                }

                for (int i = 1; i < pathFindingGUI.pathNodes.Count - 1; i++)
                {
                    // Color Green, x is axis of pathNodes[i] in grid * cellSize, y is thr ordinate location of pathNodes[i] in grid * cellSize, with and height = cellSize
                    Util.FillSquare(Color.Yellow, pathFindingGUI.pathNodes[i].X, pathFindingGUI.pathNodes[i].Y, pathFindingGUI.CellSize);
                    pathFindingGUI.window.Refresh(60);
                }
                SplashKit.Delay(5000);
            }
        }
 static void Main(){
     // Using singleton GetInstance.
     PathFindingGUI pathFindingGUI = PathFindingGUI.GetInstance();
     while(!SplashKit.QuitRequested()){
         // Display the window.
         pathFindingGUI.DisplayGUI();
         // Handle events.
         pathFindingGUI.HandleEvents();
         Thread.Sleep(30);
     }
     
 }
예제 #3
0
        // This is called when S key is pressesd.
        public static void TestOnSKey(object sender, OnPathChangedEventArgs onPathChangedEventArgs)
        {
            PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;

            pathFindingGUI.StartX = onPathChangedEventArgs.pathFinding.GetGrid().GetColumnNumber(SplashKit.MousePosition());
            pathFindingGUI.StartY = onPathChangedEventArgs.pathFinding.GetGrid().GetRowNumber(SplashKit.MousePosition());
            if (onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY) != null)
            {
                pathFindingGUI.pathNodes = onPathChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
            }
            onPathChangedEventArgs.pathFinding.GetGrid().PrintGrid();
        }
 // Creates singleton
 public static PathFindingGUI GetInstance()
 {
     if (_instance == null)
     {
         _instance = new PathFindingGUI();
         return(_instance);
     }
     else
     {
         return(_instance);
     }
 }
예제 #5
0
        // This is called when W key is pressesd.
        public static void TestOnWKey(object sender, OnWallChangedEventArgs onWallChangedEventArgs)
        {
            PathFindingGUI pathFindingGUI = (PathFindingGUI)sender;

            onWallChangedEventArgs.pathFinding.GetGrid().GetRowColumnNumber(SplashKit.MousePosition(), out double x, out double y);
            if (onWallChangedEventArgs.pathFinding.GetGrid().GetValue(SplashKit.MousePosition()) != null)
            {
                if (!onWallChangedEventArgs.pathFinding.GetGrid().GetValue(SplashKit.MousePosition()).IsWalkAble)
                {
                    onWallChangedEventArgs.wallManagement.RemoveWall(Convert.ToInt32(x), Convert.ToInt32(y));
                    pathFindingGUI.pathNodes = onWallChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
                    Util.FillSquare(Color.White, Convert.ToInt32(x), Convert.ToInt32(y), pathFindingGUI.CellSize);
                }
                else
                {
                    onWallChangedEventArgs.wallManagement.MakeWall(Convert.ToInt32(x), Convert.ToInt32(y));
                    pathFindingGUI.pathNodes = onWallChangedEventArgs.pathFinding.FindPath(pathFindingGUI.StartX, pathFindingGUI.StartY, pathFindingGUI.EndX, pathFindingGUI.EndY);
                    Util.FillSquare(Color.Black, Convert.ToInt32(x), Convert.ToInt32(y), pathFindingGUI.CellSize);
                }
            }
        }