コード例 #1
0
        static void Main(string[] args)
        {
            AbstractCardPartner A = new ParterA();
            AbstractCardPartner B = new ParterB();

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

            AbstractMediator mediator = new MediatorPater(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

            // B 赢了
            mediator.State = new BWinState(mediator);
            mediator.ChangeCount(10);
            Console.WriteLine("A 现在的钱是:{0}", A.MoneyCount); // 应该是25
            Console.WriteLine("B 现在的钱是:{0}", B.MoneyCount); // 应该是15
            Console.Read();
        }
コード例 #2
0
 public override void ChangeCount(int count)
 {
     foreach (AbstractCardPartner p in meditor.list)
     {
         ParterA a = p as ParterA;
         //
         if (a != null)
         {
             a.MoneyCount += count;
         }
         else
         {
             p.MoneyCount -= count;
         }
     }
 }