// Constructor private PathFindingGUI() : base("A* Path finding") { _pathFinding = Factory.CreatePathFindingObject(_width / CellSize, _height / CellSize, CellSize, _startPoint); pathNodes = _pathFinding.FindPath(StartX, StartY, EndX, EndY); _wallManagement = (IWallManagement)_pathFinding; OnSpacePressed += Events.TestOnSpace; OnWKeyPressed += Events.TestOnWKey; OnSKeyPressed += Events.TestOnSKey; OnEKeyPressed += Events.TestOnEKey; }
// поиск пути для объекта public void FindPath(IFindPath unit, Vector2Int finish) { if (IsCellUsed(finish)) { return; } if (unit.PathFind != null) { if (unit.PathFind.FindThread != null && unit.PathFind.FindThread.IsAlive) { unit.PathFind.FindThread.Abort(); } unit.PathFind.IsActual = false; } unit.PathFind = new PathFinder(unit, finish); unitPathQueue.Enqueue(unit.PathFind); }
// Reset the the window name, width and height. public override void ResetGUI(string name, int width, int height) { _width = width; _height = height; if (window != null) { window.Close(); } window = Factory.CreateNewWindow(name, _width, _height); _startPoint = Factory.CreatePoint(0, 0); StartX = _width / 10 / CellSize; StartY = _height / 2 / CellSize; EndX = _width / CellSize - StartX; EndY = _height / 2 / CellSize; _pathFinding = Factory.CreatePathFindingObject(_width / CellSize, _height / CellSize, CellSize, _startPoint); _wallManagement = (IWallManagement)_pathFinding; pathNodes = _pathFinding.FindPath(StartX, StartY, EndX, EndY); }
/// <summary> /// Checks if the highscore should be overwritten, and does so if needed /// </summary> public void ReWriteHighScore(IFindPath pathType) { if (pathType is Astar) { //Finds the current highscore string[] textArray = File.ReadAllText("AStarHighScore.txt").Split(';'); //the highscore string float.TryParse(textArray[0], out float currentHighscore); //If this time was faster if (finalTime < currentHighscore) { //it's the new highscore AStarHighScore = finalTime; } File.WriteAllText("AStarHighScore.txt", AStarHighScore.ToString() + ";" + AStarAttemptsCount); return; } else { //Finds the current highscore string[] textArray = File.ReadAllText("BFSHighScore.txt").Split(';'); //the highscore string float.TryParse(textArray[0], out float currentHighscore); //If this time was faster if (finalTime < currentHighscore) { //it's the new highscore bFShighScore = finalTime; } File.WriteAllText("BFSHighScore.txt", bFShighScore.ToString() + ";" + bFSattemptsCount); } }
public PathFinder(IFindPath unit, Vector2Int _finish) : this(unit.GridPosition, _finish, unit.MaxHeight) { onPathfound = unit.OnPathFound; onPathNotFound = unit.OnPathNotFound; }