示例#1
0
        public static void DoThis()
        {
            AbstractCardPartner A = new CardPartenrA();
            AbstractCardPartner B = new CardPartenrB();

            // 初始钱
            A.MoneyCount = 20;
            B.MoneyCount = 20;

            AbstractMediator mediator = new MediatorPartner(new InitState());

            //A,B玩家进入游戏
            mediator.Enter(A);
            mediator.Enter(B);

            // A赢了
            mediator.State = new AWinState(mediator);
            mediator.ChangeCount(5);
            Console.WriteLine("A 现在的钱是:{0}", A.MoneyCount);     // 应该是25
            Console.WriteLine("B 现在的钱是:{0}", B.MoneyCount);     // 应该是15
            Console.ReadLine();

            // B赢了
            mediator.State = new BWinState(mediator);
            mediator.ChangeCount(10);
            Console.WriteLine("A 现在的钱是:{0}", A.MoneyCount);     // 应该是15
            Console.WriteLine("B 现在的钱是:{0}", B.MoneyCount);     // 应该是25
            Console.ReadLine();
        }
示例#2
0
        public override void ChangeCount(int count)
        {
            foreach (AbstractCardPartner cardPartner in mediator.list)
            {
                CardPartenrB b = cardPartner as CardPartenrB;

                if (b != null)
                {
                    b.MoneyCount += count;
                }
                else
                {
                    cardPartner.MoneyCount -= count;
                }
            }
        }