コード例 #1
0
        static void AfficherAttraction(List <Attraction> maListe)
        {
            Console.WriteLine("Voici la liste des attractions :\n");

            foreach (Attraction i in maListe)
            {
                if (i is Spectacle)
                {
                    Spectacle S = i as Spectacle;
                    Console.WriteLine(S);
                }
                if (i is Boutique)
                {
                    Boutique B = i as Boutique;
                    Console.WriteLine(B);
                }
                if (i is DarkRide)
                {
                    DarkRide D = i as DarkRide;
                    Console.WriteLine(D);
                }
                if (i is RollerCoaster)
                {
                    RollerCoaster R = i as RollerCoaster;
                    Console.WriteLine(R);
                }
            }
        }
コード例 #2
0
        static List <Attraction> LectureAttraction(StreamReader monStreamReader)
        {
            List <Attraction> liste_attraction = new List <Attraction>();

            string ligne = null;

            for (int i = 0; i < 18; i++)
            {
                ligne = monStreamReader.ReadLine();
            }


            while (ligne != null)
            {
                string[] temp             = ligne.Split(';');
                int      identifiant      = int.Parse(temp[1]);
                int      nbMinimMonstre   = int.Parse(temp[3]);
                bool     besoinSpecifique = bool.Parse(temp[4]);

                switch (temp[0])
                {
                case "Boutique":
                    typeBoutique monType = typeBoutique.none;
                    try { monType = (typeBoutique)Enum.Parse(typeof(typeBoutique), temp[6]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); }
                    Boutique maBoutique = new Boutique(identifiant, temp[2], nbMinimMonstre, besoinSpecifique, temp[5], monType);
                    liste_attraction.Add(maBoutique);
                    break;

                case "DarkRide":
                    TimeSpan T = new TimeSpan(0, 0, 0);
                    try { int heure = int.Parse(temp[6]); T = new TimeSpan(heure, 0, 0); } catch (Exception e) { Console.Write(e.Message); }
                    bool vehicule = false; try { vehicule = bool.Parse(temp[7]); } catch (InvalidCastException e) { Console.WriteLine(e.Message); }

                    DarkRide monDarkRide = new DarkRide(identifiant, temp[2], nbMinimMonstre, besoinSpecifique, temp[5], T, vehicule);
                    liste_attraction.Add(monDarkRide);
                    break;

                case "RollerCoaster":
                    int           ageMinim    = int.Parse(temp[7]);
                    float         tailleMinim = float.Parse(temp[8]);
                    TypeCategorie MyType;
                    MyType = (TypeCategorie)Enum.Parse(typeof(TypeCategorie), temp[6]);
                    RollerCoaster monRollerCoaster = new RollerCoaster(identifiant, temp[2], nbMinimMonstre, besoinSpecifique, temp[5], MyType, ageMinim, tailleMinim);
                    liste_attraction.Add(monRollerCoaster);
                    break;

                case "Spectacles":
                    List <DateTime> liste_horaire = new List <DateTime>();
                    int             nbPlace       = int.Parse(temp[7]);
                    string[]        temp2         = temp[8].Split(' ');
                    for (int i = 0; i < temp2.Length; i++)
                    {
                        DateTime m = Convert.ToDateTime(temp2[i]);
                        liste_horaire.Add(m);
                    }
                    Spectacle monSpectacle = new Spectacle(identifiant, temp[2], nbMinimMonstre, besoinSpecifique, temp[5], temp[6], nbPlace, liste_horaire);
                    liste_attraction.Add(monSpectacle);
                    break;
                }
                ligne = monStreamReader.ReadLine();
            }
            monStreamReader.Close();
            return(liste_attraction);
        }