コード例 #1
0
        public static void DogDoorTestPath(int dogOutsideTime, bool ownersResponsive)
        {
            DogDoor door = new DogDoor();
            BarkRecognizer recognizer = new BarkRecognizer(door);
            Remote remote = new Remote(door);

            Console.WriteLine("\nFido barks to go outside ...");
            InitiateDoorOpen(ownersResponsive, remote, recognizer);

            Console.WriteLine("\nFido has gone outside for " + dogOutsideTime/1000 + " seconds ...");
            System.Threading.Thread.Sleep(dogOutsideTime);
            Console.WriteLine("\nFido's all done ...");

            bool firstBark = true;
            while (!door.isOpen)
            {
                if (firstBark)
                {
                    Console.WriteLine("\n... But he's stuck outside!");
                    Console.WriteLine("\nFido starts barking ...");
                    firstBark = false;
                    InitiateDoorOpen(ownersResponsive, remote, recognizer);
                }
            }

            Console.WriteLine("\nFido's back inside ...");

            while(door.isOpen)
            {
                // Wait
            }
        }
コード例 #2
0
        public static void DogDoorTestPath(int dogOutsideTime)
        {
            DogDoor door = new DogDoor();
            Remote remote = new Remote(door);

            Console.WriteLine("\nFido barks to go outside ...");
            remote.pressButton();

            Console.WriteLine("\nFido has gone outside for " + dogOutsideTime/1000 + " seconds ...");
            System.Threading.Thread.Sleep(dogOutsideTime);
            Console.WriteLine("\nFido's all done ...");

            bool firstBark = true;
            while (!door.isOpen)
            {
                if (firstBark)
                {
                    Console.WriteLine("\n... But he's stuck outside!");
                    Console.WriteLine("\nFido starts barking ...");
                    firstBark = false;
                    Console.WriteLine("\nSo Gina grabs the remote control ...");
                    remote.pressButton();
                }
            }

            Console.WriteLine("\nFido's back inside ...");

            while(door.isOpen)
            {
                // Wait
            }
            Console.WriteLine("\nTest passed! Press any key to continue.\n");
            
            Console.ReadKey();
        }
コード例 #3
0
        public static int DogDoorTestPath(int dogOutsideTime, bool ownersResponsive)
        {
            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);

            bool isOwnersDog = true;

            Console.WriteLine("\nBruce barks to go outside ...");
            InitiateDoorOpen(ownersResponsive, isOwnersDog, remote, recognizer);

            Console.WriteLine("\nBruce has gone outside for " + dogOutsideTime/1000 + " seconds ...");
            System.Threading.Thread.Sleep(dogOutsideTime);
            Console.WriteLine("\nBruce is all done ...");

            bool firstBark = true;
            while (!door.isOpen)
            {
                if (firstBark)
                {
                    Console.WriteLine("\n... But he's stuck outside!");
                    firstBark = false;

                    // A different dog barks
                    if (!ownersResponsive)
                    {
                        InitiateDoorOpen(ownersResponsive, !isOwnersDog, remote, recognizer);
                        if (door.isOpen)
                        {
                            Console.WriteLine("\nAnother dog besides Bruce has come inside! ...");
                            return 1;
                        }
                        Console.WriteLine("\nThis dog is not allowed ...");
                    }
                    

                    // Bruce barks
                    InitiateDoorOpen(ownersResponsive, isOwnersDog, remote, recognizer);
                    if (door.isOpen)
                    {
                        Console.WriteLine("\nBruce is back inside ...");
                    }
                }
            }

            while(door.isOpen)
            {
                // Wait
            }

            return 0;
        }
コード例 #4
0
 private static void InitiateDoorOpen(bool ownersResponsive, Remote remote, BarkRecognizer recognizer)
 {
     if (ownersResponsive)
     {
         Console.WriteLine("\nSo Gina grabs the remote control ...");
         remote.pressButton();
     }
     else
     {
         recognizer.recognize("Woof");
         Console.WriteLine("\nThe door hears the dog and opens ...");
     }
 }
コード例 #5
0
        public static void dogDoorTest()
        {
            DogDoor door = new DogDoor();
            Remote remote = new Remote(door);

            Console.WriteLine("Fido barks to go outside ...");
            remote.pressButton();
            Console.WriteLine("\nFido has gone outside ...");
            remote.pressButton();
            Console.WriteLine("\nFido's all done ...");
            remote.pressButton();
            Console.WriteLine("\nFido's back inside ...");
            remote.pressButton();
            Console.ReadKey();
        }
コード例 #6
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);
         }
     }
 }