/// <summary> /// 钓竿工作->钓鱼 /// </summary> /// <param name="man"></param> public void ThrowHook(FishingMan man) { Console.WriteLine("开始下钩! "); if (new Random().Next() % 2 == 0) { var type = (FishType) new Random().Next(0, 5); Console.WriteLine("铃铛:叮叮叮,鱼儿咬钩了"); if (FishingEvent != null) { FishingEvent(type); } } }
static void Main(string[] args) { var fishingRod = new FishingRod(); //鱼竿 var jeff = new FishingMan("姜太公"); jeff.FishingRod = fishingRod; //鱼竿分配 //注册观察者 fishingRod.FishingEvent += jeff.Update; //循环钓鱼 while (jeff.FishCount < 5) { jeff.Fishing(); Console.WriteLine("----------------------"); Thread.Sleep(5000); } Console.ReadLine(); }