예제 #1
0
 public void AtualizaGrafo()
 {
     Mapa.Limpa();
     distancia.Clear();
     rotas.Clear();
     try
     {
         StreamReader sr = File.OpenText(aeroportosFileURL);
         string line = sr.ReadLine();
         while (line != null)
         {
             var dados = line.Split(';');
             AeroportoItem aero = new AeroportoItem();
             aero.Name = dados[1];
             Double x, y;
             Double.TryParse(dados[2].Replace('.',','), out x);
             Double.TryParse(dados[3].Replace('.', ','), out y);
             aero.CoordX = x;
             aero.CoordY = y;
             int index;
             Int32.TryParse(dados[0], out index);
             listaAeroportos.Add(index, aero);
             line = sr.ReadLine();
         }
         sr.Close();
     }
     catch (Exception)
     {
         Console.WriteLine("Não consegui acessar o arquivo.");
     }
     try
     {
         StreamReader sr = File.OpenText(rotasFileURL);
         string line = sr.ReadLine();
         while (line != null)
         {
             var dados = line.Split(' ');
             int aerid1, aerid2;
             Int32.TryParse(dados[0], out aerid1);
             Int32.TryParse(dados[1], out aerid2);
             rotasNumeradas.Add(aerid1.ToString() + " " + aerid2.ToString());
             if(!rotasNumeradas.Contains(aerid2.ToString() + " " + aerid1.ToString()))
             {
                 AdicionaRota(aerid1, aerid2);
             }
             line = sr.ReadLine();
         }
         sr.Close();
     }
     catch (Exception)
     {
         Console.WriteLine("Não consegui acessar o arquivo.");
     }
 }
예제 #2
0
 public int DistanciaEntre(AeroportoItem a1, AeroportoItem a2)
 {
     int saida = 0;
     double x1, x2, y1 ,y2, res;
     x1 = x2 = y1 = y2 = 0;
     x1 = a1.CoordX;
     y1 = a1.CoordY;
     x2 = a2.CoordX;
     y2 = a2.CoordY;
     res = DistanceTo(x1, y1, x2, y2, 'K');
     saida = (int)res;
     return saida;
 }