Esempio n. 1
0
 public void Recognize(Bark bark)
 {
     // The recognize method ask the owner's dog's bark object to see if it is
     // equal to the Bark instance supplied by Doug's hardware, using Bark.equals()
     Console.WriteLine("BarkRecognizer: Heard a '{0}'", bark.getSound());
     List<Bark> allowedBarks = door.getAllowedBarks();
     foreach (Bark allowedBark in allowedBarks)
     {
         if ((bark.equals(allowedBark)))
         {
             door.Open();
             return;
         }
         Console.WriteLine("This dog is not allowed");
         
     }
     
 }
Esempio n. 2
0
        public void RunSimulator()
        {
            // Dog Door Simulator

            DogDoor door = new DogDoor();
            Remote remote = new Remote(door);
            //Create the BarkRecognizer, connect it to the door, and let it listen for some barking.
            BarkRecognizer barkRecognizer = new BarkRecognizer(door);

            String sound = "bark";
            Bark bark = new Bark(sound);
            //Thread currentThread = Thread.CurrentThread;

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


            // Simulate the hardware hearing a bark
            Console.WriteLine("Bruce starts barking.");
            barkRecognizer.Recognize(new Bark("rowlf"));

            Console.WriteLine("\nBruce has gone outside...");
            DogLockedOut(barkRecognizer);

            // Simulate the hardware hearing a bark (not Bruce!)
            Bark smallDogBark = new Bark("yip");
            Console.WriteLine("A small dog starts barking");
            barkRecognizer.Recognize(smallDogBark);

            try
            {
                Thread.Sleep(5000);
            }
            catch (ThreadInterruptedException) { }

            Console.WriteLine("Bruce starts barking.");
            barkRecognizer.Recognize(new Bark("rooowlf"));

            Console.WriteLine("\n Bruce's back inside");
        }
Esempio n. 3
0
 public void addAllowedBark (Bark bark)
 {
     allowedBarks.Add(bark);
 }
Esempio n. 4
0
 public void addAllowedBark(Bark bark)
 {
     allowedBarks.Add(bark);
 }