public bool añadirfp(FlightPlan fp) //añade el plan de vuelo dado como parámetro, solo si no estaba ya en la lista
        {
            int  i     = 0;
            bool found = false;

            //Si no hay ningún FP en la lista, se puede añadir
            if (ListFP.Count == 0)
            {
                ListFP.Add(fp);
            }

            //Si hay algún FP en la lista comprobamos que el que se vaya añadir no esté
            else
            {
                //Recorremos la lista buscando su ID
                while (i < ListFP.Count && found == false)
                {
                    if (fp.GetID() == ListFP[i].GetID())
                    {
                        found = true;
                    }
                    else
                    {
                        i++;
                    }
                }

                //Si no lo encontramos, lo añadimos a la lista
                if (found == false)
                {
                    ListFP.Add(fp);
                }
            }
            return(found); //found=true: ya estaba en la lista, no lo ha añadido / found=false: no estaba en la lista, lo ha añadido
        }
Esempio n. 2
0
 //Constructor copia
 public FlightPlan(FlightPlan fp)
 {
     this.ID          = fp.GetID();
     this.compañia    = fp.GetCompañia();
     this.velocidad   = fp.GetVelocidad();
     this.IX          = fp.GetIX();
     this.FX          = fp.GetFX();
     this.AX          = fp.GetAX();
     this.IY          = fp.GetIY();
     this.FY          = fp.GetFY();
     this.AY          = fp.GetAY();
     this.incrementov = fp.GetIncrementoV();
 }
        public void GuardarVuelos(string fichero)       //escribe fichero con los datos actuales de los vuelos
        {
            StreamWriter W = new StreamWriter(fichero); //escribir fichero
            int          i = 0;

            while (i < ListFP.Count)
            {
                FlightPlan f = ListFP[i];
                W.WriteLine(f.GetID() + " " + f.GetCompañia() + " " + Convert.ToString(f.GetVelocidad()) + " " + Convert.ToString(f.GetIX()) + " " + Convert.ToString(f.GetIY()) + " " + Convert.ToString(f.GetAX()) + " " + Convert.ToString(f.GetAY()) + " " + Convert.ToString(f.GetFX()) + " " + Convert.ToString(f.GetFY()));
                i++;
            }
            W.Close(); //cerrar fichero
        }