Пример #1
0
 public bool Equals(Bark bark)
 {
     if (sound.CompareTo(bark.sound) == 0)
     {
         return true;
     }
     return false;
 }
Пример #2
0
 public void recognize(Bark bark)
 {
     Console.WriteLine("    BarkRecognizer: Heard a '" + bark.sound + "'");
     foreach (Bark allowedBark in _door.allowedBarks)
     {
         if (allowedBark.Equals(bark))
         {
             _door.Open();
             return;
         }
     }
 }
        static void Main(string[] args)
        {
            Models.DogDoor door = new Models.DogDoor();
            door.AddAllowedBark(new Bark("hauu"));
            door.AddAllowedBark(new Bark("Hrauu"));
            door.AddAllowedBark(new Bark("hauhauu"));
            door.AddAllowedBark(new Bark("hauuuuuu"));
            BarkRecognizer recognizer = new BarkRecognizer(door);
            Remote         remote     = new Remote(door);

            Console.WriteLine("Azor szczeka, by wyjść na spacer...");
            Console.WriteLine();
            recognizer.Recognize(new Bark("hauu"));

            Console.WriteLine("Azor wyszedł na specer");
            Console.WriteLine("Azor załatwił co trzeba...");
            try
            {
                Thread.Sleep(10000);
            }
            catch (Exception ex) { }

            Console.WriteLine(".. ale Azor utknął na zewnątrz!");

            Bark smallDogBark = new Bark("hiauu");

            Console.WriteLine("Mały pies zaczął szczekać");
            recognizer.Recognize(smallDogBark);

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

            Console.WriteLine("\nAzor zaczyna szczekać...");
            recognizer.Recognize(new Bark("hauu"));

            Console.WriteLine("Azor wrócił do domu");

            Console.ReadLine();
        }
Пример #4
0
 private static void InitiateDoorOpen(bool ownersResponsive, bool isOwnersDog, Remote remote, BarkRecognizer recognizer)
 {
     if (ownersResponsive)
     {
         Console.WriteLine("\nSo Gina grabs the remote control ...");
         remote.pressButton();
     }
     else
     {
         if (isOwnersDog)
         {
             // Now Bruce starts barking
             Console.WriteLine("\nBruce starts barking ...");
             recognizer.recognize(new Bark("rooowlf"));
         }
         else
         {
             // Begin with another dog barking
             Bark smallDogBark = new Bark("yip");
             Console.WriteLine("\nBitsie starts barking ...");
             recognizer.recognize(smallDogBark);
         }
     }
 }
Пример #5
0
 public void AddAllowedBark(Bark bark)
 {
     allowedBarks.Add(bark);
 }
Пример #6
0
 public void AddAllowedBark(Bark bark)
 {
     allowedBarks.Add(bark);
 }
 private static void InitiateDoorOpen(bool ownersResponsive, bool isOwnersDog, Remote remote, BarkRecognizer recognizer)
 {
     if (ownersResponsive)
     {
         Console.WriteLine("\nSo Gina grabs the remote control ...");
         remote.pressButton();
     }
     else
     {
         if (isOwnersDog)
         {
             // Now Bruce starts barking
             Console.WriteLine("\nBruce starts barking ...");
             recognizer.recognize(new Bark("rooowlf"));
         }
         else
         {
             // Begin with another dog barking
             Bark smallDogBark = new Bark("yip");
             Console.WriteLine("\nBitsie starts barking ...");
             recognizer.recognize(smallDogBark);
         }
     }
 }