示例#1
0
        public void Initialize()
        {
            foreach (Type T in _Types)
            {
                bool InputOK = false;
                int  value;

                // TODO: Should factorize this
                do
                {
                    Console.WriteLine("How many {0} do you want to start with? (1-10)", T.Name);

                    string line = Console.ReadLine();

                    if (int.TryParse(line, out value))
                    {
                        // this is an int.
                        if (value > 0 && value <= 10)
                        {
                            InputOK = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Not quite my input.");
                    }
                } while (!InputOK);

                /*
                 * FishTypes will list the type of every fish class that has, as base class, one of the types mentionned in the string array
                 * Add other basetypes to extend functionality
                 */
                Array FishTypes = (CustomGetTypes.GetTypeWhenParent("CSharquarium_console.Models.Instanciable", new[] { typeof(AlgaeEatingFish).Name, typeof(FishEatingFish).Name })).ToArray();

                if (T == typeof(Alga))
                {
                    for (int i = 0; i < value; ++i)
                    {
                        Organisms.Add(T.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }) as Alga);
                    }
                }
                else if (Array.IndexOf(FishTypes, T) != -1) // returning -1 means that IndexOf did not find the value you were looking for
                {
                    for (int i = 0; i < value; ++i)
                    {
                        Organisms.Add(T.GetConstructor(Type.EmptyTypes).Invoke(new object[] { }) as Fish);
                    }
                }
            }
        }
示例#2
0
 public Aquarium()
 {
     Organisms = new List <Organism>();
     _Types    = CustomGetTypes.GetInstanciableTypes("CSharquarium_console.Models.Instanciable");
 }