示例#1
0
        public void AddNewCage()
        {
            MainCage mc     = new MainCage();
            int      number = 0;

            mc.AddCage(mc);

            ICageComponent expected  = mc;
            ICageComponent component = mc.isOne(number);

            Assert.AreEqual(expected.GetType(), component.GetType());
        }
示例#2
0
        public void CageFromListComponent()
        {
            MainCage mc = new MainCage();
            List <ICageComponent> components = new List <ICageComponent>();

            components.Add(mc);

            int number = 0;

            mc.AddCage(mc);

            ICageComponent component = mc.isOne(number);
            ICageComponent expected  = components[number];

            Assert.AreEqual(expected.GetType(), component.GetType());
        }
示例#3
0
        public void AddAnimal()
        {
            MainCage mc = new MainCage();

            int weight = 10;
            int number = 0;

            Type[] expected = { typeof(Bear), typeof(Wolf), typeof(Giraffe) };

            mc.AddAnimal(weight);
            ICageComponent component = mc.isOne(number);

            foreach (var type in expected)
            {
                if (type == component.GetType())
                {
                    Assert.AreEqual(type, component.GetType());
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            ConsoleKeyInfo        Action;
            MainCage              mc = new MainCage();
            List <ICageComponent> animals;

            Console.WriteLine("Команди для роботи з програмою:");
            Console.WriteLine("1) додати тварину - клавiша А;");
            Console.WriteLine("2) змiнити перiод доби - клавiша Т;");
            Console.WriteLine("3) команда голосу - клавiша V;");
            Console.WriteLine("4) вивести загальну вагу - клавiша W;");
            Console.WriteLine("5) додати клiтку - клавiша С \n");

            while (true)
            {
                Action = Console.ReadKey(true);

                switch (Action.Key)
                {
                //додати тварину
                case ConsoleKey.A:
                    Console.WriteLine("Вага тварини: ");
                    int weight;
                    if ((Int32.TryParse(Console.ReadLine(), out weight) == true))
                    {
                        mc.AddAnimal(weight);
                        animals = mc.GetAnimals();
                        foreach (var a in animals)
                        {
                            Console.WriteLine("Iм'я тварини: {0}, вага тварини: {1}", a.Name, a.Weight);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Невiрний формат введеного");
                    }
                    break;

                //додати клітку
                case ConsoleKey.C:
                    NewCage(mc);
                    Console.WriteLine("Клiтку додано");
                    break;

                //змінити період дня
                case ConsoleKey.T:
                    Console.WriteLine("Перiод дня: day - день, night - нiч");
                    string time = Console.ReadLine();
                    if (time == "day" || time == "night")
                    {
                        mc.Day(time);
                        Console.WriteLine("Час змiнено");
                    }
                    else
                    {
                        Console.WriteLine("Невiрний формат введеного");
                    }
                    break;

                //подати голос
                case ConsoleKey.V:
                    Console.WriteLine("Голос подає: всi тварини - all, окрема тварина - №");
                    string who = Console.ReadLine();
                    int    number;
                    if (who == "all")
                    {
                        Console.WriteLine(mc.Voice());
                    }
                    else if (Int32.TryParse(who, out number))
                    {
                        number--;
                        ICageComponent a = mc.isOne(number);
                        if (a != null)
                        {
                            if (mc.isDay == false)
                            {
                                mc.Day("day");
                                Console.WriteLine(a.Voice());
                                mc.Day("night");
                            }
                            else
                            {
                                Console.WriteLine(a.Voice());
                            }
                        }
                        else
                        {
                            Console.WriteLine("Це не тварина. Виберiть iнше мiсце");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Невiрний формат введеного");
                    }
                    break;

                //загальна вага
                case ConsoleKey.W:
                    Console.WriteLine("Загальна вага: {0}", mc.Weight);
                    break;
                }
            }
        }
示例#5
0
 public void AddCage(ICageComponent cage)
 {
     components.Add(cage);
 }