

设计模式之状态模式(State)-腾讯游戏学院
source link: http://gad.qq.com/article/detail/288130
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


//状态基类 public abstract class FSMState { public abstract void OnEnter(); public abstract void Update(); public abstract void OnExit(); } //控制器 public class FSMController { public FSMState curState { get; protected set; } public void ChangerState(FSMState state) { if (state != null) { if (curState != state) curState.OnExit(); curState = state; curState.OnEnter(); } } public void Update() { curState.Update(); } }
public enum HeroState { stand, walk, run, } public class OnGroundState { public virtual void HandleInput(HeroState toState) { if(toState == HeroState.stand) { } else if (toState == HeroState.walk) { } else if(toState == HeroState.run) { } //······ } } public class StandState : OnGroundState { public override void HandleInput(HeroState toState) { if (toState == HeroState.stand) { } else if (toState == HeroState.walk) { } //······ //不在处理范围,返回给父类 base.HandleInput(toState); } }
Recommend
-
61
有问题,上知乎。知乎是中文互联网知名知识分享平台,以「知识连接一切」为愿景,致力于构建一个人人都可以便捷接入的知识分享网络,让人们便捷地与世界分享知识、经验和见解,发现更大的世界。
-
49
-
45
前言 之前在我的博客(一枝花算不算浪漫)中已经更新过两篇设计模式相关的内容 【一起学设计模式】策略模式实战一:基于消息发送的策略模式实战
-
26
-
14
Python 设计模式——状态模式 发表于 2020-12-26 ...
-
12
设计模式大冒险第五关:状态模式,if/else的“终结者”这一篇文章是关于
-
11
设计模式与软考试题之状态模式(二) 2011年下半年软件设计...
-
6
设计模式与软考试题之状态模式(一) 从2006年-2012年,在...
-
11
浅谈设计模式(一):状态模式|外观模式|代理模式广发证券 技术工程师计划开一个设计模式的系列,介绍常见的几种设计模式,本文涉及的设计模式包含以下6种状态模式:s...
-
1
设计模式 (十七) 状态模式 State(对象行为型 March 20, 2019 in
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK