コード例 #1
0
ファイル: SeleccionPais.cs プロジェクト: hecmtz/Herencia
        public void AddSeleccion(SeleccionPais s)
        {
            //Si el método MeterVehiculo nos devuelve true, añadiremos el vehículo
            if (MeterJugador(s))
            {
                //Si el objeto que queremos meter es un Taxi, le añadimos uno al contador de taxis.
                if (s.GetType().Name == "Futbolista")
                {
                    nFutbolista++;
                }
                //Si el objeto que queremos meter es un Autobus, le añadimos uno al contador de autobuses.
                else if (s.GetType().Name == "Masajista")
                {
                    nMasajista++;
                }
                else if (s.GetType().Name == "Entrenador")
                {
                    nEntrenador++;
                }

                //Como hemos verificado que se puede meter, lo metemos
                Console.WriteLine("se ha añadido al" + s.GetType().Name + " .");
                pais.Add(s);
            }
        }
コード例 #2
0
ファイル: SeleccionPais.cs プロジェクト: hecmtz/Herencia
 public bool MeterJugador(SeleccionPais s)
 {
     if (pais.Count < 6)
     {
         if (s.GetType().Name == "Masajista" && nMasajista < 1)
         {
             return(true);
         }
         else if (s.GetType().Name == "Taxi" && nEntrenador < 1)
         {
             return(true);
         }
         else if (s.GetType().Name == "Futbolista")
         {
             return(true);
         }
         Console.WriteLine("No caben más " + s.GetType().Name + "s en el equipos");
         Console.ReadLine();
         return(false);
     }
     Console.WriteLine("No caben más " + s.GetType().Name + "s en el equipos");
     Console.ReadLine();
     return(false);
 }