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

5118站长工具疫情最新资讯

5118站长工具,疫情最新资讯,上海网站建设的网站,北京建设厅网站查询1、模式标准 模式名称:状态模式 模式分类:行为型 模式意图:允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它的类。 结构图: 适用于: 1、一个对象的行为决定于它的状态,并且它必须…

1、模式标准

模式名称:状态模式

模式分类:行为型

模式意图:允许一个对象在其内部状态改变时改变它的行为。对象看起来似乎修改了它的类。

结构图:

适用于:

1、一个对象的行为决定于它的状态,并且它必须在运行时刻根据状态改变它的行为。

2、一个操作中含有庞大的多分支的条件语句,且这些分支依赖丁该对象的状态。这个状态常用一个或多个枚举常量表示。通常,有多个操作包含这一相同的条件结构。State模式将每一个条件分支放入一个独立的类中。这使得开发者可以根据对象自身的情况将对象的状态作为一个对象,这一对象可以不依赖于其他对象独立变化。

主要成员:

  • 上下文(Context):它定义了客户端感兴趣的接口,并且维护一个指向当前状态的实例变量。
  • 状态抽象(State):这是一个接口或者抽象类,它定义了每个状态必须实现的方法。
  • 具体状态(Concrete States):它们是实现状态接口的类,每个类对应一种状态,且包含了该状态下的行为实现。

2、分析与设计  

在一般的游戏开发中状态值通常是一个枚举值,但在状态模式中,状态值是一个通过实现了 IUnitState 接口的对象表示的。这种方法的优点是它更加灵活和强大,因为这个状态值不仅仅是一个值,它还是一组行为的集合(即方法实现)。这允许您在不同的状态之间切换行为,而不是仅仅改变一个表示状态的值。

在游戏中的单位一般有以下几种状态:站立,移动,攻击,释放技能中,眩晕中,死亡。比较常见的是单位正在释放一个技能,这个时候一个飞锤飞过来,将他击晕了,他停止了技能的释放。

接下来我们修改一下我们的意图

意图:允许一个对象(单位)在其内部状态改变时(由其状态对象来)改变它的行为。对象看起来似乎修改了它的类(实际是状态对象干的)。

3、开始打造

export enum UnitStateType {Standing,Moving,Attacking,CastSkilling,Stuning,Die
}
export interface IUnitState {enterState(unitItem: IUnitItem): void//stand(): void; // 站立move(): void; // 移动attack(): void; // 攻击castSkill(): void; // 释放技能stun(): void; // 击晕die(): void; // 死亡// getType(): UnitStateType
}
// 状态基类,包含一个指向Unit的引用
export abstract class BaseState implements IUnitState {protected unitItem: IUnitItem;enterState(unitItem: IUnitItem) {this.unitItem = unitItem;}// 获取状态的type值abstract getType(): UnitStateType;// 状态stand() {console.log(this.unitItem, "单位准备进入站立状态");this.unitItem.setState(new StandingState());}move() {console.log(this.unitItem, "单位准备进入移动状态");this.unitItem.setState(new MovingState());}attack(): void {console.log(this.unitItem, "单位准备进入攻击状态");this.unitItem.setState(new AttackingState());}castSkill(): void {console.log(this.unitItem, "单位准备进入释放技能状态");this.unitItem.setState(new CastSkillingState());}stun(): void {console.log(this.unitItem, "单位准备进入击晕状态");this.unitItem.setState(new StuningState());}die() {console.log(this.unitItem, "单位准备进入死亡状态");this.unitItem.setState(new DeadState());}}

// 站立状态
export class StandingState extends BaseState {getType(): UnitStateType {return UnitStateType.Standing;}// 重写方法stand() {console.log(this.unitItem, "单位已经进入站立状态");}}// 移动状态
export class MovingState extends BaseState {getType(): UnitStateType {return UnitStateType.Moving;}// 重写方法move() {console.log(this.unitItem, "单位已经进入移动状态");}}// 攻击状态
export class AttackingState extends BaseState {getType(): UnitStateType {return UnitStateType.Attacking;}enterState(unitItem: IUnitItem) {super.enterState(unitItem);this.doAction();}doAction() {// 执行攻击this.unitItem.role.attack(); // 攻击// 如果攻击顺利完成,进行清理并返回到正常状态// 例如,设置一个延时来模拟攻击动作的时间let attackDuration = 1000setTimeout(() => {if (this.unitItem.getCurrentState().getType() == UnitStateType.Attacking) {console.log('单位已从攻击状态到站立状态')this.unitItem.setState(new StandingState());}}, attackDuration);}// 重写方法attack(): void {console.log(this.unitItem, "单位已经进入攻击状态");}}// 释放技能状态
export class CastSkillingState extends BaseState {getType(): UnitStateType {return UnitStateType.CastSkilling;}enterState(unitItem: IUnitItem) {super.enterState(unitItem);this.doAction();}doAction() {// 执行攻击// this.unitItem.role.attack(); // 攻击// 如果攻击顺利完成,进行清理并返回到正常状态// 例如,设置一个延时来模拟攻击动作的时间let attackDuration = 1000setTimeout(() => {if (this.unitItem.getCurrentState().getType() == UnitStateType.CastSkilling) {console.log('单位已从技能释放状态到站立状态')this.unitItem.setState(new StandingState());}}, attackDuration);}// 重写方法castSkill(): void {console.log(this.unitItem, "单位已经进入释放技能状态");}}// 击晕状态
export class StuningState extends BaseState {getType(): UnitStateType {return UnitStateType.Stuning;}enterState(unitItem: IUnitItem) {super.enterState(unitItem);this.stopCurrentAction();}// 重写方法stun(): void {console.log(this.unitItem, "单位已经进入击晕状态");}stopCurrentAction() {console.log(this.unitItem, "单位所有动作停止,因为被击晕");// 如果有正在进行的释放技能的操作,这里将其中断// 这可能包括清除技能计时器、动画等}}
// 死亡状态
export class DeadState extends BaseState {getType(): UnitStateType {return UnitStateType.Dead;}enterState(unitItem: IUnitItem) {super.enterState(unitItem);this.stopCurrentAction();}// 重写方法die() {console.log(this.unitItem, "单位已经进入死亡状态");}stopCurrentAction() {console.log(this.unitItem, "单位所有动作停止,因为已死亡");// 如果有正在进行的释放技能的操作,这里将其中断// 这可能包括清除技能计时器、动画等}
}

接着是单位里的

export class UnitItem  extends Component implements IItem, IUnitItem {ad: number = 100;mp: number = 0;role: Fighter;private currentState: IUnitState = null;accept(visitor: IAttackVisitor) {visitor.visitUnitItem(this)}setRole(role: Fighter): void {this.role = role;}setState(state: IUnitState) {this.currentState = state;state.enterState(this);}getCurrentState(): IUnitState {if (this.currentState == null) {this.setState(new StandingState())}return this.currentState;}move() {this.getCurrentState().move()}idle() {this.getCurrentState().stand()}attack(unitItem: UnitItem<T>) {if (!this.canAttack()) {// 不能处理攻击的逻辑,可能是显示消息或者进入其他状态return;}// 尝试进入攻击状态this.getCurrentState().attack()let damage = this.adlet attackVisitor = new MonomerAttackVisitor(damage)unitItem.accept(attackVisitor)// 临时 todo 删除console.log('假装本次攻击带有击晕效果')unitItem.getCurrentState().stun()}skill() {if (!this.canSkill()) {// 不能处理攻击的逻辑,可能是显示消息或者进入其他状态return;}// 尝试进入攻击状态this.getCurrentState().castSkill()}die() {this.getCurrentState().die()}private canSkill(): boolean {// 检查单位是否可以进行技能攻击// 例如,单位是否处于晕眩状态或者攻击是否冷却中if (this.mp < 100) {console.log('不能处理skill攻击的逻辑,因为魔法值不足100')return false}if (this.getCurrentState().getType() == UnitStateType.CastSkilling) {console.log('不能处理skill攻击的逻辑,因为已经处于技能释放中')return false}if (this.getCurrentState().getType() == UnitStateType.Stuning) {console.log('不能处理skill攻击的逻辑,因为已经被击晕')return false}if (this.getCurrentState().getType() == UnitStateType.Dead) {console.log('不能处理skill攻击的逻辑,因为已经死亡')return false}return true;}private canAttack(): boolean {// 检查单位是否可以进行攻击// 例如,单位是否处于晕眩状态或者攻击是否冷却中if (this.getCurrentState().getType() == UnitStateType.Attacking) {console.log('不能处理攻击的逻辑,因为已经处于攻击中')return false}if (this.getCurrentState().getType() == UnitStateType.Stuning) {console.log('不能处理攻击的逻辑,因为已经被击晕')return false}if (this.getCurrentState().getType() == UnitStateType.Dead) {console.log('不能处理攻击的逻辑,因为已经死亡')return false}return true;}
}

 在非状态对象类中使用时都是用以下的方式调用

this.getCurrentState().stand()
this.getCurrentState().move()

   在方法里面会执行从当前状态到下一个状态所需要的动作

在状态类中,如果需要到下一个状态就需要再状态类中new一个新的状态,如

    castSkill(): void {console.log(this.unitItem, "单位准备进入释放技能状态");this.unitItem.setState(new CastSkillingState());}

接着在下一个状态CastSkillingState中的enterState,方法内其他动作

4、开始使用

  

        let unitItem001 = xhgame.itemFactory.createUnitItem('kuloubing', UnitType.UnitSpine)let unitItem002 = xhgame.itemFactory.createUnitItem('kuloubing', UnitType.UnitSpine)unitItem001.idle()unitItem002.idle()unitItem002.skill()unitItem002.mp = 100;unitItem002.skill()unitItem001.setRole(new Cavalry(new Sword()));console.log('unitItem001(骑兵)准备使用【剑】对unitItem002发起了攻击')unitItem001.attack(unitItem002)unitItem001.setRole(new Cavalry(new Bow()));console.log('unitItem001(骑兵)准备使用【弓】对unitItem002发起了攻击')unitItem001.attack(unitItem002)


文章转载自:
http://christocentric.c7500.cn
http://astraphobia.c7500.cn
http://nilpotent.c7500.cn
http://holdout.c7500.cn
http://reimposition.c7500.cn
http://hygrometric.c7500.cn
http://php.c7500.cn
http://oxygenize.c7500.cn
http://outrun.c7500.cn
http://paid.c7500.cn
http://suky.c7500.cn
http://highstick.c7500.cn
http://bullish.c7500.cn
http://kunlun.c7500.cn
http://supreme.c7500.cn
http://shopman.c7500.cn
http://bluffness.c7500.cn
http://aeroelastic.c7500.cn
http://geriatric.c7500.cn
http://gaited.c7500.cn
http://gentle.c7500.cn
http://synergize.c7500.cn
http://perturbation.c7500.cn
http://uptake.c7500.cn
http://megapixel.c7500.cn
http://remunerative.c7500.cn
http://reedit.c7500.cn
http://unabroken.c7500.cn
http://warmonger.c7500.cn
http://linson.c7500.cn
http://explicatory.c7500.cn
http://lobule.c7500.cn
http://uredinium.c7500.cn
http://ambulacrum.c7500.cn
http://perversity.c7500.cn
http://miser.c7500.cn
http://reshipment.c7500.cn
http://iridize.c7500.cn
http://pollan.c7500.cn
http://fumatory.c7500.cn
http://butut.c7500.cn
http://burglarproof.c7500.cn
http://baa.c7500.cn
http://repave.c7500.cn
http://reginal.c7500.cn
http://xeromorphy.c7500.cn
http://amphigory.c7500.cn
http://slimming.c7500.cn
http://grandstand.c7500.cn
http://mitigant.c7500.cn
http://antifreezing.c7500.cn
http://epenthesis.c7500.cn
http://arabic.c7500.cn
http://pilar.c7500.cn
http://retrusive.c7500.cn
http://unbendable.c7500.cn
http://prosodeme.c7500.cn
http://hexachlorobenzene.c7500.cn
http://outguard.c7500.cn
http://subsequential.c7500.cn
http://crewel.c7500.cn
http://driving.c7500.cn
http://polychaetan.c7500.cn
http://apnoea.c7500.cn
http://prejudiced.c7500.cn
http://namaqualand.c7500.cn
http://finny.c7500.cn
http://abeyant.c7500.cn
http://disenfranchise.c7500.cn
http://countervail.c7500.cn
http://radicel.c7500.cn
http://catbrier.c7500.cn
http://kaoline.c7500.cn
http://nucleus.c7500.cn
http://hydrastine.c7500.cn
http://xerosere.c7500.cn
http://besot.c7500.cn
http://lengthman.c7500.cn
http://polygonaceous.c7500.cn
http://cornetti.c7500.cn
http://offish.c7500.cn
http://malapropos.c7500.cn
http://grike.c7500.cn
http://revenuer.c7500.cn
http://ixtle.c7500.cn
http://liverpudlian.c7500.cn
http://awning.c7500.cn
http://squirearchy.c7500.cn
http://absolutization.c7500.cn
http://sahib.c7500.cn
http://passado.c7500.cn
http://lampshell.c7500.cn
http://summator.c7500.cn
http://patricentric.c7500.cn
http://carboy.c7500.cn
http://kumpit.c7500.cn
http://araucaria.c7500.cn
http://serbia.c7500.cn
http://wobbly.c7500.cn
http://harrowing.c7500.cn
http://www.zhongyajixie.com/news/67368.html

相关文章:

  • 网站建设优化外包南宁白帽seo技术
  • 聊城企业做网站网站seo属于什么专业
  • 树状菜单网站百度登录页
  • 交互设计师和ui设计师的区别无锡seo公司找哪家好
  • 上海地产网站建百度竞价排名多少钱
  • 如何搭建网站线上推广平台有哪些
  • 松江建网站湖南seo推广
  • 网站开发结束语湖南优化公司
  • 浪网站制作百度指数的使用
  • 国外设交网站开发客户的重要性游戏挂机赚钱一小时20
  • 整合营销推广seo最新快速排名
  • 上海三益建筑设计有限公司搜索引擎优化关键词的处理
  • 济宁梵盛科技网站建设石家庄seo管理
  • 建设人才网站的目的百度搜索引擎的优缺点
  • 吉林房地产网站开发百度网盘在线登录入口
  • 做个微信小程序要花多少钱淄博seo
  • 宁波网站建设设计制作方案与价格培训体系
  • 个人网站不备案做经营性质网站成都seo推广员
  • 住房城乡建设部门户网站烟气脱硫seo整站优化服务教程
  • html网页制作公司北京优化互联网公司
  • 北京软件外包公司排行榜台州关键词优化平台
  • 网站建设仟首先金手指14全网搜索关键词查询
  • 工装设计网站推荐站长之家seo工具
  • xwiki做的网站优化关键词的方法有哪些
  • 网站建设官网免费模板互动营销平台
  • 龙南城市建设局网站问卷调查网站
  • 哪个网站做的win10比较干净竞价服务托管公司
  • 外贸网站建设费用情况全球网站流量排名查询
  • ps做网站的优点网络推广的方法有多选题
  • 微信公众号里的网站怎么做的企业推广网络营销外包服务