码迷,mamicode.com
首页 > 其他好文 > 详细

20 关卡设计-责任链(Chain of Responsibility)

时间:2017-03-03 20:52:22      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:分享   nbsp   hid   bsp   prot   ext   rac   protect   else   

技术分享

技术分享
 1 /// <summary>
 2 /// 处理信息的接口
 3 /// </summary>
 4 public abstract class Handler {
 5 
 6     /// <summary>
 7     /// 下一个请求接收者
 8     /// </summary>
 9     protected Handler m_NextHandler = null;
10 
11     public Handler(Handler theNextHandler) {
12         m_NextHandler = theNextHandler;
13     }
14 
15     public virtual void HandleRequest(int Cost) {
16         if(m_NextHandler != null) {
17             m_NextHandler.HandleRequest(Cost);
18         }
19     }
20 }
Handler
技术分享
 1 /// <summary>
 2 /// 处理所负责的信息1
 3 /// </summary>
 4 public class ConcreteHandler1:Handler {
 5 
 6     private int m_CostCheck = 10;
 7 
 8     public ConcreteHandler1(Handler theNextHandler) : base(theNextHandler) {
 9 
10     }
11 
12     public override void HandleRequest(int Cost) {
13         if(Cost <= m_CostCheck) {
14             Debug.Log("ConcreteHandler1.HandleRequest核准");
15         } else {
16             base.HandleRequest(Cost);
17         }
18     }
19 }
ConcreteHandler1
技术分享
 1 /// <summary>
 2 /// 处理所负责的信息2
 3 /// </summary>
 4 public class ConcreteHandler2:Handler {
 5 
 6     private int m_CostCheck = 20;
 7 
 8     public ConcreteHandler2(Handler theNextHandler) : base(theNextHandler) {
 9 
10     }
11 
12     public override void HandleRequest(int Cost) {
13         if(Cost <= m_CostCheck) {
14             Debug.Log("ConcreteHandler2.HandleRequest核准");
15         } else {
16             base.HandleRequest(Cost);
17         }
18     }
19 }
ConcreteHandler2
技术分享
 1 /// <summary>
 2 /// 处理所负责的信息3
 3 /// </summary>
 4 public class ConcreteHandler3:Handler {
 5 
 6     public ConcreteHandler3(Handler theNextHandler) : base(theNextHandler) {
 7 
 8     }
 9 
10     public override void HandleRequest(int Cost) {
11         Debug.Log("ConcreteHandler3.HandleRequest核准");
12     }
13 }
ConcreteHandler3

 

20 关卡设计-责任链(Chain of Responsibility)

标签:分享   nbsp   hid   bsp   prot   ext   rac   protect   else   

原文地址:http://www.cnblogs.com/revoid/p/6498154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!