void moveRange(Fleet unit) { Refresh(); HexCell cell = unit.Location; List <HexCell> frontier = new List <HexCell>(); cell.Distance = 0; frontier.Add(cell); while (frontier.Count > 0) { HexCell current = frontier[0]; frontier.RemoveAt(0); for (HexDirection d = HexDirection.NE; d <= HexDirection.NW; d++) { HexCell neighbor = current.GetNeighbor(d); int distance = current.Distance; if (neighbor == null || neighbor.FleetUnit) { continue; } if (neighbor.TerrainTypeIndex == 2) { continue; } else { distance += 5; if (distance > unit.step) { break; } } if (neighbor.Distance == int.MaxValue) { neighbor.Distance = distance; frontier.Add(neighbor); neighbor.SetLabel(neighbor.Distance.ToString()); neighbor.EnableHighlight(Color.white); } else if (distance < neighbor.Distance) { neighbor.Distance = distance; neighbor.SetLabel(neighbor.Distance.ToString()); neighbor.EnableHighlight(Color.white); } frontier.Sort((x, y) => x.Distance.CompareTo(y.Distance)); } } }
void ClearPath() { if (currentPathExists) { HexCell current = currentPathTo; while (current != currentPathForm) { current.SetLabel(null); current.DisableHighlight(); current = current.PathFrom; } current.DisableHighlight(); currentPathExists = false; } currentPathForm = currentPathTo = null; }
void ShowPath(int step) { if (currentPathExists) { HexCell current = currentPathTo; while (current != currentPathForm) { int turn = (current.Distance - 1) / step; current.SetLabel(turn.ToString()); current.EnableHighlight(Color.yellow); current = current.PathFrom; } } currentPathForm.EnableHighlight(Color.blue); currentPathTo.EnableHighlight(Color.red); }