Пример #1
0
        public void cooking(object sender, EnergyEventArgs e)
        {
            You you = (You)sender;

            if (e.Energy < 5)
            {
                Console.WriteLine("{0} will cook a meal for you!", name);
                you.EnergyValue = MaxValue;
            }
            return;
        }
Пример #2
0
        public void joking(object sender, MoodEventArgs m)
        {
            You you = (You)sender;

            if (m.Mood < 5)
            {
                Console.WriteLine("{0} will tell you a joke!", name);
                you.MoodValue = MaxValue;
            }
            return;
        }
Пример #3
0
        static void Main(string[] args)
        {
            You you = new You(3, 10);
            Me  me1 = new Me("贝贝");
            Me  me2 = new Me("晶晶");

            you.energyEvent += me1.cooking;
            you.moodEvent   += me1.joking;
            you.energyEvent += me2.cooking;
            you.moodEvent   += me2.joking;
            you.run();
            Console.ReadLine();
        }