//------------------------------------------------------------------------------------------------------------- //----------------------------------------------MAP UPDATER---------------------------------------------------- //------------------------------------------------------------------------------------------------------------- public void TileClicked(Vector2 node) { //Third click reset the path if (node == startNode) { return; } if (startNodeSelected && endNodeSelected) { startNodeSelected = false; endNodeSelected = false; foreach (Node n in currentPath) { actualTiles[n.x.ToString() + n.y.ToString()].GetComponent <HexTile>().ResetColor(); //Reseting tiles color } currentPath.Clear(); } //First click select the start node else if (!startNodeSelected) { startNode = node; startNodeSelected = true; actualTiles[startNode.x.ToString() + startNode.y.ToString()].GetComponent <HexTile>().Selected(true); //Selected tile color } //Second click select the end node else if (startNodeSelected && !endNodeSelected) { endNode = node; endNodeSelected = true; actualTiles[endNode.x.ToString() + endNode.y.ToString()].GetComponent <HexTile>().Selected(true); //Selected tile color currentPath = AStar.GetPath(graph[Mathf.RoundToInt(startNode.x), Mathf.RoundToInt(startNode.y)], graph[Mathf.RoundToInt(endNode.x), Mathf.RoundToInt(endNode.y)]); //Getting Path foreach (Node n in currentPath) { //Setting pathColor if (new Vector2(n.x, n.y) != startNode && new Vector2(n.x, n.y) != endNode) { actualTiles[n.x.ToString() + n.y.ToString()].GetComponent <HexTile>().Selected(); } } } }
private void refreshTimer_Tick(object sender, EventArgs e) { refreshTimer.Enabled = false;//间隔10后时钟触发停下,处理状况 labelcost.Visible = false; if (MethodNum > 0) { while (IsChosen[CurrentMethod] == false) //对应初始情况,找到勾选的第一个算法 { CurrentMethod++; } switch (CurrentMethod) { case 0: CurrentStatus = breadthSearch.GetPath(); break; case 1: CurrentStatus = depthSearch.GetPath(); break; case 2: CurrentStatus = bestSearch.GetPath(); break; case 3: CurrentStatus = dijkstraSearch.GetPath(); break; case 4: CurrentStatus = astarSearch.GetPath(); break; case 5: CurrentStatus = bibreadthSearch.GetPath(); break; default: Console.WriteLine("按算法搜索时出现错误"); break; } ShowResult(CurrentStatus); if (CurrentStatus.PathFound) //一种搜索算法搜索结束,找到路径 { for (int i = 1; i < CurrentStatus.Path.Length - 1; i++) //不改变起终点 { Cor step = CurrentStatus.Path[i]; myDraw.Laby.SetCell(step, Type.Path); myDraw.DrawLaby(); Application.DoEvents(); System.Threading.Thread.Sleep(20); } MethodNum--; UpdateMinimum(CurrentStatus); Console.WriteLine("MiniCost:{0},MiniLength:{1}", minPathCost, minPathLength); System.Threading.Thread.Sleep(1200); CurrentMethod++; if (MethodNum > 0) { addLine(); myDraw.Change(CurrentLaby); } myDraw.DrawLaby(); } else if (CurrentStatus.PathNotFound) { MethodNum--; UpdateMinimum(CurrentStatus); ShowResult(CurrentStatus); System.Threading.Thread.Sleep(1200); CurrentMethod++; if (MethodNum > 0) { addLine(); myDraw.Change(CurrentLaby); } myDraw.DrawLaby(); } else//还在搜索过程中 { System.Threading.Thread.Sleep(15); myDraw.DrawLaby(); } refreshTimer.Enabled = true; } else//对应初始情况与所有算法都搜索结束 { refreshTimer.Enabled = false; labelcost.Visible = true; labyPicture.Enabled = true; generateButton.Enabled = true; startButton.Enabled = true; SaveButton.Enabled = true; labelcost.Visible = true; materialTabSelector.Enabled = true; ResetButton.Enabled = true; minPathLength = int.MaxValue; minPathCost = int.MaxValue; } }