public void Recognize(Bark bark)
        {
            Console.WriteLine("Bark Recognizer : Heard a '" + bark.Sound + "'");
            List <Bark>        allowedBarks = _door.GetAllowedBark;
            IEnumerator <Bark> iterator     = allowedBarks.GetEnumerator();

            while (iterator.MoveNext())
            {
                Bark allowedBark = (Bark)iterator.Current;
                if (allowedBark.Equals(bark))
                {
                    _door.Open();
                    return;
                }
            }
            Console.WriteLine("Dog is not allowed");
        }
Example #2
0
        public void Recognize(Bark bark)
        {
            Console.WriteLine("   BarkRecognizer: Heard a '" + bark.Sound
                              + "'");
            List <Bark> allowedBarks = door.AllowedBark;

            foreach (Bark b in allowedBarks)
            {
                Bark allowedBark = b;
                if (allowedBark.Equals(bark))
                {
                    door.Open();
                    return;
                }
            }
            Console.WriteLine("This Dog is not Allowed..");
        }
Example #3
0
        static void Main(string[] args)
        {
            var door = new DogDoor();

            door.AddAllowedBark(new Bark("rowlf"));
            door.AddAllowedBark(new Bark("rooowlf"));
            door.AddAllowedBark(new Bark("rawlf"));
            door.AddAllowedBark(new Bark("woof"));

            var recognizer = new BarkRecognizer(door);
            var remote     = new Remote(door);

            Console.WriteLine("Bruce starts Barking...");
            recognizer.Recognize(new Bark("rowlf"));
            Console.WriteLine("Bruce has gone outside....");

            try
            {
                Thread.Sleep(10000);;
            }
            catch (Exception exception) { }

            Console.WriteLine("Bruce all done....");
            Console.WriteLine("...but he's stuck outside!");

            Bark smallDogBark = new Bark("yip");

            Console.WriteLine("A small dog starts barking..");
            recognizer.Recognize(smallDogBark);

            try
            {
                Thread.Sleep(5000);
            }
            catch (Exception exception) { }

            Console.WriteLine("Bruce Starts Barking....");
            recognizer.Recognize(new Bark("rowlf"));
            Console.WriteLine("Bruce's back inside....");
        }
Example #4
0
 public void AddAllowedBark(Bark bark)
 {
     allowedBark.Add(bark);
 }
Example #5
0
 public void AddAllowedBarks(Bark bark)
 {
     _allowedBarks.Add(bark);
 }