public void AppMain() { AbstractCardPartner A = new ParterA(); AbstractCardPartner B = new ParterB(); // 初始钱 A.Money = 20; B.Money = 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.Money); // 应该是25 Console.WriteLine("B 现在的钱是:{0}", B.Money); // 应该是15 // B 赢了 mediator.State = new BWinState(mediator); mediator.ChangeCount(10); Console.WriteLine("A 现在的钱是:{0}", A.Money); // 应该是25 Console.WriteLine("B 现在的钱是:{0}", B.Money); // 应该是15 }
public override void ChangeCount(int count) { foreach (AbstractCardPartner p in meditor.list) { ParterA a = p as ParterA; // if (a != null) { a.Money += count; } else { p.Money -= count; } } }