예제 #1
0
        /// <summary>
        /// A B两人打牌
        /// </summary>
        public static void DoThis()
        {
            AbstractCardPartner A = new PartnerA();

            A.MoneyCount = 20;
            AbstractCardPartner B = new PartnerB();

            B.MoneyCount = 20;

            // A赢了B的钱就减少
            A.ChangeCount(5, B);
            Console.WriteLine("A 现在的钱是:{0}", A.MoneyCount); // 应该是25
            Console.WriteLine("B 现在的钱是:{0}", B.MoneyCount); // 应该是15
            Console.ReadLine();

            // B赢了A的钱也减少
            B.ChangeCount(10, A);
            Console.WriteLine("A 现在的钱是:{0}", A.MoneyCount); // 应该是15
            Console.WriteLine("B 现在的钱是:{0}", B.MoneyCount); // 应该是25
            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            PartnerA a = new PartnerA();

            a.MoneyCount = 20;
            PartnerB b = new PartnerB();

            b.MoneyCount = 30;
            Mediator mediator = new ConcreteMediator(a, b);

            //A赢了
            Console.WriteLine("A赢了");
            a.ChangeCount(5, mediator);
            Console.WriteLine("A现在的钱是:{0}", a.MoneyCount);
            Console.WriteLine("B现在的钱是:{0}", b.MoneyCount);

            //B赢了
            Console.WriteLine("B赢了");
            b.ChangeCount(10, mediator);
            Console.WriteLine("A现在的钱是:{0}", a.MoneyCount);
            Console.WriteLine("B现在的钱是:{0}", b.MoneyCount);
            Console.ReadKey();
        }
예제 #3
0
 public ConcreteMediator(PartnerA partnerA, PartnerB partnerB) : base(partnerA, partnerB)
 {
 }
예제 #4
0
 public Mediator(PartnerA partnerA, PartnerB partnerB)
 {
     this.partnerA = partnerA;
     this.partnerB = partnerB;
 }