static void Main(string[] args) { #region 中介者模式 //实例化 具体中介者 联合国安理会 UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); //实例化一个美国 USA c1 = new USA(UNSC); //实例化一个里拉开 Iraq c2 = new Iraq(UNSC); //将两个对象赋值给安理会 //具体的中介者必须知道全部的对象 UNSC.Register(c1); UNSC.Register(c2); //美国发表声明,伊拉克接收到 c1.Declare("不准研制核武器,否则要发动战争!"); //伊拉克发表声明,美国收到信息 c2.Declare("我们没有核武器,也不怕侵略。"); #endregion #region 中介者模式 //步骤三:最后,通过mediator发送一个消息 //var response = await mediator.Publish(new Ping()); //Console.WriteLine(response); // "贠乾是个大帅哥" #endregion Console.Read(); }
static void Main(string[] args) { UnitedNationSecurityCouncil UNSC = new UnitedNationSecurityCouncil(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.ColleagueA = c1; UNSC.ColleaguaB = c2; c1.Declare("不准研制核武器, 否则发动战争"); c2.Declare("我们没有核武器, 也不怕侵略"); }
static void Main(string[] args) { UnitedNationsSecurity UNSC = new UnitedNationsSecurity(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.Colleague1 = c1; UNSC.Colleague2 = c2; c1.DeclareX("不准研发核武器,否则发动战争! "); c2.DeclareX("我们没有核武器,也不怕侵略! "); }
static void Main(string[] args) { UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.Country1 = c1; UNSC.Country2 = c2; c1.Declare("不准研制核武器,否则要发动战争!"); c2.Declare("我们没研制核武器,也不怕侵略。"); }
static void Main(string[] args) { UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.Country1 = c1; UNSC.Country2 = c2; c1.Declare("不准研制核武器,否则要发动战争!"); c2.Declare("我们没研制核武器,也不怕侵略。"); }
//中介者 public static void testMediator() { UnitedNationsSecurityCouncil UNSC = new UnitedNationsSecurityCouncil(); USA c1 = new USA(UNSC); Iraq c2 = new Iraq(UNSC); UNSC.Colleague1 = c1; UNSC.Colleague2 = c2; c1.Declare("不准研制核武器,否则要发动战争!"); c2.Declare("我们没有核武器,也不怕侵略。"); Console.Read(); }
static void Main(string[] args) { Console.WriteLine("You are a sergeant in a 3D Low Altitude Air Defense Unit aka LAADSOC. You are leading a team " + "of 3 other marines, a Corporal, Lance Corporal, and a Private First Class. Your team is deployed in " + "Iraq. You have been instructed to go to an 8 digit grid location and establish a stinger position."); Console.WriteLine(); //Appendix Iraq iraq = new Iraq(); M16A4 m16a4 = new M16A4(); M4 m4 = new M4(); RAZR razr = new RAZR(); PrivateFirstClass pfc = new PrivateFirstClass(); LanceCorporal lcpl = new LanceCorporal(); Corporal cpl = new Corporal(); Sergreant sgt = new Sergreant(); //End of appendix iraq.TypeOfTerrain("Iraq"); iraq.WeatherOfTheDay(); razr.Load(); razr.Drive(); razr.Turn("Right"); razr.Drive(); razr.Turn("Left"); razr.Drive(); razr.Brake(); razr.Unload(); Console.WriteLine(); pfc.Work(); lcpl.Work(); cpl.Work(); sgt.Work(); Console.WriteLine(); Console.WriteLine("It has been 6 hours and the marines begin to get hungry."); Console.WriteLine(); pfc.Eat(); lcpl.Eat(); cpl.Eat(); sgt.Eat(); Console.WriteLine(); Console.WriteLine("It is now 20:00 and time for you and your team to get some rest. You assign the Private First Class, and Corporal to take first firewatch while everyone else gets some sleep."); Console.WriteLine(); pfc.FireWatch(); cpl.FireWatch(); lcpl.Sleep(); sgt.Sleep(); Console.WriteLine(); Console.WriteLine("After a few hours of sleep...."); Console.WriteLine(); pfc.Yell(); Console.WriteLine("BANG! BANG! BANG!"); cpl.Contact(); Console.WriteLine(); lcpl.WakeUp(); sgt.WakeUp(); Console.WriteLine("The Lance Corporal grabs his M16A4, and heads towards the threat."); Console.WriteLine("You grab your M4, and head toward the threat."); Console.WriteLine(); m16a4.Aim(); m16a4.Shoot("Sharp Shooter"); Console.WriteLine(); m4.Aim(); m4.Shoot("Expert"); Console.WriteLine(); Console.WriteLine("You have repelled the threat, and notice the PFC has been shot."); pfc.Injured(); lcpl.FirstAid(); Console.WriteLine(); iraq.MissionSuccess(); Console.ReadKey(); }