20 关卡设计-责任链(Chain of Responsibility)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20 关卡设计-责任链(Chain of Responsibility)相关的知识,希望对你有一定的参考价值。
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 }
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 }
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 }
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 }
以上是关于20 关卡设计-责任链(Chain of Responsibility)的主要内容,如果未能解决你的问题,请参考以下文章
行为型设计模式—— 责任链模式(Chain of Responsibility Pattern)
行为型设计模式—— 责任链模式(Chain of Responsibility Pattern)
设计模式Chain Of Responsibility责任链模式(未完成)
设计模式(13)--Chain of Responsibility(责任链模式)--行为型