Ejemplo n.º 1
0
        private static void Feed(IEat eater, IFood food)
        {
            var soundMaker = eater as IMakeSounds;

            Console.WriteLine();
            Console.WriteLine($"Trying to feed {food} (which belongs to the {food.FoodGroup} group, with a food value of {food.FoodValue}) to a {eater}");
            Console.WriteLine($"Which is something it {(eater.CanEat(food) ? "can" : "cannot")} eat");
            if (eater == food)
            {
                Console.WriteLine("Unfortunately it cannot eat itself");
                return;
            }
            Console.WriteLine($"Currently the {eater} has a food level of {eater.FoodLevel}");
            try
            {
                eater.Eat(food);
                Console.WriteLine($"The {eater} ate the {food}");
                WriteSound(soundMaker, s => s.Contentment());
                Console.WriteLine($"Now its food level is {eater.FoodLevel}");
            }
            catch (Exception e)
            {
                WriteSound(soundMaker, s => s.Surprise());
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     IWorker[] workers = new IWorker[3]
     {
         new Managers(),
         new Worker(),
         new Robot()
     };
     foreach (var worker in workers)
     {
         worker.Work();
     }
     IEat[] eat = new IEat[2]
     {
         new Managers(),
         new Worker()
     };
     foreach (var eat in eats)
     {
         eat.Eat();
     }
 }
Ejemplo n.º 3
0
 public void Display()
 {
     eat.Eat();
 }
Ejemplo n.º 4
0
 public void Eat()
 {
     _eat.Eat();
 }
Ejemplo n.º 5
0
 public void Feed(IEat an)
 {
     Console.WriteLine($"{this.GetType().Name} is feeding {an.GetType().Name}");
     an.Eat();
 }
Ejemplo n.º 6
0
 virtual public void WatchE(IEat an)
 {
     Console.Write($"{this.GetType().Name} is watching how ");
     an.Eat();
 }
Ejemplo n.º 7
0
 public void Eat(IEat eat)
 {
     eat.Eat();
 }
Ejemplo n.º 8
0
 public void Eat()
 {
     Ready();                                    // 喝前准备
     m_eat.Eat();                                // 开始喝水
     EatDepth();                                 // 喝完反馈
 }