当前位置: 首页 > news >正文

网站怎么添加手机版大沥网站建设

网站怎么添加手机版,大沥网站建设,如何做网站的维护,辽宁省住房和城乡建设部网站主页状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的#xff1a;攻击逻辑 攻击范围 动作等等1 状态很多 2 每个状态有自己的属性和逻辑每种状态单独写一个类 角色…状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的攻击逻辑 攻击范围 动作等等1 状态很多 2 每个状态有自己的属性和逻辑每种状态单独写一个类 角色需要那个状态就加载哪一个 类图 角色  stateBase 抽象状态 stateA 具体状态A stateB 具体状态B stateC 具体状态C FactoryState  状态工厂 代码 RoleContext using System.Collections; using System.Collections.Generic; using UnityEngine;public class RoleContext {string name;StateBase currentState null;public RoleContext(){name 独孤求败;}// 展示动作public void ShowAction(){if (null ! currentState){currentState.Action();}}// 切换状态public void ChangeActionState(StateBase newState){currentState newState;} }StateBase public abstract class StateBase {public abstract void Action(); }StateA  using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateA : StateBase {string name 普攻;public override void Action(){Debug.Log(释放- name);} }StateB  using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateB : StateBase {string name 次元斩;public override void Action(){Debug.Log(释放- name);} }StateC using System.Collections; using System.Collections.Generic; using UnityEngine;public class StateC:StateBase {string name 升龙击;public override void Action(){Debug.Log(释放- name);} }FactoryState using System.Collections; using System.Collections.Generic; using UnityEngine;public class FactoryState {// 单例static FactoryState self null;FactoryState() { }public static FactoryState Instance(){if (null self)self new FactoryState();return self;}Dictionarystring, StateBase dic new Dictionarystring, StateBase();// 获取实例public StateBase GetStateIns(string className){StateBase ins null;switch (className){case StateA:{if (false dic.ContainsKey(className))ins new StateA();elseins dic[className];}break;case StateB:{if (false dic.ContainsKey(className))ins new StateB();elseins dic[className];}break;case StateC:{if (false dic.ContainsKey(className))ins new StateC();elseins dic[className];}break;default:Debug.Log(未发现该类);break;}return ins;} }测试代码 using System.Collections; using System.Collections.Generic; using UnityEngine;public class TestZT : MonoBehaviour {void Start(){RoleContext role new RoleContext();// 切换技能Arole.ChangeActionState(FactoryState.Instance().GetStateIns(StateA));role.ShowAction();// 切换技能Brole.ChangeActionState(FactoryState.Instance().GetStateIns(StateB));role.ShowAction();// 切换技能Crole.ChangeActionState(FactoryState.Instance().GetStateIns(StateC));role.ShowAction();}}结果 总结 状态模式 1 是一个非常好用的 解耦合的手段 角色不同的状态封装不同的动作属性限制 2 非常符合对修改封闭对扩展开发的原则。 3 让状态的职责更加的单一 4 也符合了依赖倒置 依赖了抽象 5 符合了迪米特原则角色对状态类内部的具体实现不知道
http://www.dnsts.com.cn/news/236142.html

相关文章:

  • 数学网站怎么做的营销型网站盈利模式
  • 编写网站方案设计书表格wordpress完美优化
  • 找个人给我做电影网站好房产网站开发文档
  • SEO如何建设网站深圳投资公司排名前十
  • 个别网站网速慢怎么做没有公司做网站
  • 温州网站制作优化广州网站建设小程序开发
  • 三维家是在网站上做还是在app上网站建设技术包括哪些内容
  • 河北做网站哪家公司好茂名企业建站模板
  • 网站链接网址怎么做专业的企业管理软件
  • 私人可以做org后缀网站吗网站设计是用什么软件做
  • 天津企业网站设计报价网页游戏开发语言
  • 做外贸都有哪些好网站湖南服装网站建设
  • wordpress腾讯云搭建网站常用的做网站的工具都有哪些
  • 合肥大型网站成都网站定制建设
  • 胶州做网站的彩票网站网站建设
  • 厦门网站建设优化企业asp网站发送邮件
  • 网站不备案可以使用么中国经济网人事
  • 二级域名 电子商务网站推广方案凡科建站后台登录
  • 网站建设易网拓新手做网站流程
  • h5网站页面设计百度商桥wordpress
  • 网站设置在哪资源共享网站建设
  • 别人做的网站怎么seo优化渝北网站建设
  • 南京网站制作公司招聘南京手机网站设计公司
  • 哪个汽车网站汽贸店免费做wordpress 万能搜索页
  • com网站注册小程序app公众号的区别
  • 自建外贸网站多少钱拍摄公司宣传片制作
  • 西安注册公司在哪个网站软文有哪些
  • 建站大师排名表2021佛山格尔做网站的公司
  • 成都手机微信网站建设报价有没有做粤菜的网站
  • 怎么样可以做网站有名的软件开发公司有哪些