示例#1
0
        public static void Main(string[] args)
        {
            DogDoor        door       = new DogDoor();
            BarkRecognizer recognizer = new BarkRecognizer(door);
            Remote         remote     = new Remote(door);

            Console.WriteLine("Fido starts barking...");
            recognizer.Recognize("Woof");

            Console.WriteLine("\nFido has gone outside...");
            Console.WriteLine("\nFido's all done...");

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

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

            Console.WriteLine("\nFido starts barking...");
            recognizer.Recognize("Woof");

            Console.WriteLine("\nFido's back inside...");
        }
示例#2
0
        static void Main(string[] args)
        {
            DogDoor door = new DogDoor();

            door.AddAllowedBark(new Bark("rowlf"));
            door.AddAllowedBark(new Bark("rooowlf"));
            door.AddAllowedBark(new Bark("rawlf"));
            door.AddAllowedBark(new Bark("woof"));
            BarkRecognizer recognizer = new BarkRecognizer(door);
            Remote         remote     = new Remote(door);

            // Adjust console output colors
            Console.BackgroundColor = ConsoleColor.DarkGray;

            // Formatting
            Console.WriteLine("------------------------");

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

            Console.WriteLine("Bruce has gone outside...\n");

            System.Threading.Thread.Sleep(10000);

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

            // Simulate the hardware hear a bark (not Bruce!)
            Bark smallDogBark = new Bark("yip");

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

            System.Threading.Thread.Sleep(5000);

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

            Console.WriteLine("Bruce's back inside...");

            // Formatting
            Console.WriteLine("------------------------");

            // Change terminal color back to original
            Console.ResetColor();

            Console.ReadKey();
        }
 public Remote(DogDoor door)
 {
     _door = door;
 }
 public BarkRecognizer(DogDoor door)
 {
     _door = door;
 }
示例#5
0
 public BarkRecognizer(DogDoor door)
 {
     this.door = door;
 }