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

网站开发和运行 法律网站设计师工资一般多少

网站开发和运行 法律,网站设计师工资一般多少,深圳专业网站建设价格,wordpress主题grace7状态模式 介绍 设计模式定义案例问题堆积在哪里解决办法状态模式一个对象 状态可以发生改变 不同的状态又有不同的行为逻辑游戏角色 加载不同的技能 每个技能有不同的:攻击逻辑 攻击范围 动作等等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;}Dictionary<string, StateBase> dic = new Dictionary<string, 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.yayakq.cn/news/922444/

相关文章:

  • 网站建设与开发定制开发商逾期交房可以申请退房吗
  • 宁波品牌网站制作哪家好腾讯企业邮箱登录入口二维码
  • 音乐网站开发文档撰写模板嘉兴小程序开发公司
  • 网站建设外包 源代码网站之家查询
  • 邯郸网站建设费用中学生旅游网站开发的论文怎么写
  • 大力推进网站集约化建设wordpress模块化主题
  • 免费的游戏网站建设安全的网站制作公司
  • 网站收录提交接口wordpress标签数据库
  • 好的网站建设重庆航运建设发展有限公司网站
  • 加强公司窗口网站建设镇江市机关效能与作风建设网站
  • 建设一个网站论坛要多少钱襄城县做网站的
  • 湖北专业网站建设产品介绍白熊阅读做网站架构
  • 网站设计方案模板商城网站建设视频教程
  • 职业生涯规划大赛成长赛道网站关键词优化软件
  • 如何查询网站域名备案信息免费的网站推广
  • 排名前十的网站上海市嘉定建设局网站
  • 做字体网站东莞常平中学录取分数线2022
  • 扁平化网站建设公司合肥网站建设王道下拉??
  • 快站建站做网站要营业执照吗
  • 网站建设+临沂质量好网站建设价格
  • 西宁做网站君博领先广告vi设计是什么
  • 做代练去什么网站安全吗sem培训班培训多少钱
  • 在线响应式网站ps做图哪个网站好
  • 网站开发自学流程网络营销有用吗
  • 织梦批量修改网站源代码武威 网站建设
  • 哈尔滨网站设计报价成都装修网站制作价格
  • 腾讯云建设网站视频福安seo
  • 做网站需要买什么wordpress设置ip
  • 微信支付 网站开发建设工程合同法全文
  • 网络网站知识app做爰午夜福利全过程视频网站