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"); }
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.."); }
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...."); }
public void AddAllowedBark(Bark bark) { allowedBark.Add(bark); }
public void AddAllowedBarks(Bark bark) { _allowedBarks.Add(bark); }