Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public override void ChangeCount(int count)
 {
     foreach (AbstractCardPartner p in meditor.list)
     {
         ParterB b = p as ParterB;
         // 如果集合对象中时B对象,则对B的钱添加
         if (b != null)
         {
             b.MoneyCount += count;
         }
         else
         {
             p.MoneyCount -= count;
         }
     }
 }