Exemplo n.º 1
0
        public void Run()
        {
            AnimalFactory af = new AnimalFactory();
            string        input;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                var    args = Console.ReadLine().Split();
                string type = input;
                animals.Add(af.CreateAnimal(type, args));
            }
            Print();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ArrayList animals = new ArrayList();

            Console.WriteLine("Welcome to Animal Playland!!!");
            Console.WriteLine("Which animal would you like to interact with?\n\t1. Dog\n\t2. Cat");
            string input = Console.ReadLine();

            IAnimal animal = null;

            switch (input)
            {
            case "1":
                animal = AnimalFactory.GetAnimal <Dog>();
                break;

            case "2":
                animal = AnimalFactory.GetAnimal <Cat>();
                break;

            default:
                Console.WriteLine("Not a valid selection...");
                break;
            }

            Console.WriteLine("What activity would you like to do with the " + animal.Name().ToString() + ".\n\t1. Speak\n\t2. Sit\n\t3. Play");
            input = Console.ReadLine();

            switch (input)
            {
            case "1":
                Console.WriteLine(animal.Speak());
                break;

            case "2":
                Console.WriteLine(animal.Sit());
                break;

            case "3":
                Console.WriteLine(animal.Play());
                break;

            default:
                Console.WriteLine("Not a valid selection...");
                break;
            }

            Console.ReadLine();
        }
Exemplo n.º 3
0
        public static void Main()
        {
            string input;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                var animalData = Console.ReadLine().Split();

                try
                {
                    Animal animal = AnimalFactory.MakeAnimal(input, animalData);
                    Console.WriteLine(animal);
                }
                catch (AnimalArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var animals = new List <Animal>();

            var firstLine = "";

            while ((firstLine = Console.ReadLine()) != "Beast!")
            {
                try
                {
                    var secondLine = Console.ReadLine();

                    var animal = AnimalFactory.GenerateAnimal(firstLine, secondLine.Split());
                    animals.Add(animal);
                }
                catch (ArgumentException ex) { Console.WriteLine(ex.Message); }
            }

            Console.WriteLine(string.Join("\n", animals));
        }
Exemplo n.º 5
0
        public static void Main()
        {
            string type;

            while ((type = Console.ReadLine()) != "Beast!")
            {
                var    args    = Console.ReadLine().Split();
                Animal newType = null;
                try
                {
                    newType = AnimalFactory.CreateAnimal(type, args);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                if (newType != null)
                {
                    Console.WriteLine(newType);
                }
            }
        }
        public void Run()
        {
            string input = string.Empty;

            while ((input = Console.ReadLine()) != "Beast!")
            {
                try
                {
                    string animalType = input;

                    string[] elements = Console.ReadLine()
                                        .Split(" ")
                                        .ToArray();

                    Animal animal = AnimalFactory.Create(animalType, elements);

                    Console.WriteLine(animal);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
        public static void Main()
        {
            string animalType = Console.ReadLine();
            var    animals    = new List <Animal>();

            while (animalType != "Beast!")
            {
                string[] animalInfo = Console.ReadLine().Split(" ");

                try
                {
                    var animal = AnimalFactory.Create(animalType, animalInfo);
                    animals.Add(animal);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                animalType = Console.ReadLine();
            }

            Console.WriteLine($"{string.Join(Environment.NewLine, animals)}");
        }
 public Engine()
 {
     this.animalFactory = new AnimalFactory();
 }