三消游戏FSM状态机设计图
三消游戏FSM状态机设计图
1) 设计FSM图
2) smc配置文件
/////////////////////////////////////////////////////////////////////// // ColorTable.sm // -- ColorTable State Map for C++ classes auto-generation // // 1) generate c++ classes: // $ java -jar Smc.jar -c++ ColorTable.sm // // 2) generate graphviz dot graph: // $ java -jar Smc.jar -graph -glevel 1 ColorTable.sm // // see also: // http://graphviz.org/ // // Author: cheungmine // Copyright 2015-?, All rights reserved. // /////////////////////////////////////////////////////////////////////// %class ColorTable %header ColorTable.h %start ColorTableMap::Vacancy %map ColorTableMap %% /** * State { * Transition [Guard Condition] * EndState { * Action(s) * } * * Transition [context.getOwner().is_valid()] * EndState { * Action(s) * } * ... * } */ //==> ColorTableMap::Vacancy Vacancy Entry { enterVacancy(); } Exit { leaveVacancy(); } { // Expose Transitions to other parts if necessary shuffle ShuffleFilled { shuffle(); } } //==> ColorTableMap::ShuffleFilled // only swappable state ShuffleFilled Entry { enterShuffleFilled(); } Exit { leaveShuffleFilled(); } { // !!can swap here!! swap [ context.getOwner().swap_done() ] Filled { } swap ShuffleFilled { // set stack top sub sm: SwapMap } } //==> ColorTableMap::FallenOver FallenOver Entry { enterFallenOver(); } Exit { leaveFallenOver(); } { // Expose Transitions to other parts if necessary fill [ context.getOwner().is_empty() ] Vacancy { } fill Filled { fill(); } } //==> ColorTableMap::Filled Filled Entry { enterFilled(); } Exit { leaveFilled(); } { erase [ context.getOwner().can_erase() ] Unfilled { erase(); } erase Vacancy { empty(); } } //==> ColorTableMap::Unfilled Unfilled Entry { enterUnfilled(); } Exit { leaveUnfilled(); } { fall Fallen { fall(); } } //==> ColorTableMap::Fallen Fallen Entry { enterFallen(); } Exit { leaveFallen(); } { erase [ context.getOwner().can_erase() ] Unfilled { erase(); } erase FallenOver { empty(); } } %%
3) ColorTable.h和ColorTable.cpp
/** * ColorTable.h * 2015-02-01 * cheungmine, all rights reserved. * * col-> * +-------+-------+-------+-------+-------+-------+-------+ * row |00 |01 |02 |03 |04 |05 |06 | * | | | | | | | | | * v | | | | | | | | * +-------+-------+-------+-------+-------+-------+-------+ * |10 |11 |12 |13 |14 |15 |16 | * | | | | | | | | * | | | | | | | | * +-------+-------+-------+-------+-------+-------+-------+ * |20 |21 |22 |23 |24 |25 |26 | * | |(xp,yp)| | | | | | height * | | . | | | | | | * +-------+-------+-------+-------+-------+-------+-------+ * |30 |31 |32 |33 |34 |35 |36 | * | | | | | | | | * | | | | | | | | * +-------+-------+-------+-------+-------+-------+-------+ * y |40 |41 |42 |43 |44 |45 |46 | * ^ | | | | | | | | * | | | | | | | | | * | o-------+-------+-------+-------+-------+-------+-------+ * | origin width * +------------>x * (0,0) * */ #ifndef __COLORTABLE_H__ #define __COLORTABLE_H__ #include "cocos2d.h" USING_NS_CC; #include "ColorTable_sm.h" class ColorTable : public Node { public: // Global Settings: static const int ColorTable_NumRows = 5; static const int ColorTable_NumCols = 7; static const int ColorTable_NumCells = ColorTable_NumRows*ColorTable_NumCols; static const int ColorTable_NumColors = 4; static const int ColorTable_ColorsPal[ColorTable_NumColors+1]; // colors palette // Construct and Deconstruct ColorTable() : swap_done_(false), _fsm(0), _DeltaTime(0.1f), _NumRows(ColorTable_NumCols), _NumCols(ColorTable_NumRows), _NumCells(ColorTable_NumCells) { } // Public Types: enum EnumColor { INVALID = 0, RED = 1, GREEN = 2, BLUE = 3, YELLOW = 4 }; // Public Inline Methods: inline int index(int row, int col) const { return (col*_NumCols + row); } inline int color(int row, int col) const { return table_[index(row, col)]; } inline int result(int row, int col) const { return results_[index(row, col)]; } public: // Public Methods: CREATE_FUNC(ColorTable); virtual bool init(); bool is_empty(); bool can_erase(); bool swap_done(); void shuffle(); void empty(); void erase(); void fall(); void fill(); void print(); public: // Public Callbacks: void enterVacancy(); void leaveVacancy(); void enterShuffleFilled(); void leaveShuffleFilled(); void enterFallenOver(); void leaveFallenOver(); void enterFilled(); void leaveFilled(); void enterUnfilled(); void leaveUnfilled(); void enterFallen(); void leaveFallen(); // Public Events: void onIdleVacancy(float dt); void onIdleShuffleFilled(float dt); void onIdleFallenOver(float dt); void onIdleFilled(float dt); void onIdleUnfilled(float dt); void onIdleFallen(float dt); private: // Private Methods: void init_table(); void exit(); private: // Private Members: ColorTableContext * _fsm; const int _NumRows; const int _NumCols; const int _NumCells; const float _DeltaTime; bool swap_done_; int table_[ColorTable_NumCells]; int results_[ColorTable_NumCells]; }; #endif // __COLORTABLE_H__
/** * ColorTable.cpp * 2015-02-01 * cheungmine, all rights reserved. * */ #include "ColorTable.h" const int ColorTable::ColorTable_ColorsPal[ColorTable_NumColors+1] = {'O', 'R', 'G', 'B', 'Y'}; /////////////////////////// Private Methods //////////////////////////// void ColorTable::init_table() { int fixed[] = { 1,1,3,1,2, 3,2,1,1,4, 2,2,4,3,3, 1,3,3,4,1, 3,4,4,2,4, 2,2,4,1,1, 2,1,1,2,4 }; int at = 0; int * p = table_; while (p - table_ < _NumCells) { *p++ = fixed[at++]; } } /////////////////////////// Public Callbacks /////////////////////////// void ColorTable::enterVacancy() { empty(); this->schedule(schedule_selector(ColorTable::onIdleVacancy), _DeltaTime); } void ColorTable::leaveVacancy() { exit(); } void ColorTable::enterShuffleFilled() { this->schedule(schedule_selector(ColorTable::onIdleShuffleFilled), _DeltaTime); } void ColorTable::leaveShuffleFilled() { exit(); } void ColorTable::enterFallenOver() { this->schedule(schedule_selector(ColorTable::onIdleFallenOver), _DeltaTime); } void ColorTable::leaveFallenOver() { exit(); } void ColorTable::enterFilled() { this->schedule(schedule_selector(ColorTable::onIdleFilled), _DeltaTime); } void ColorTable::leaveFilled() { exit(); } void ColorTable::enterUnfilled() { this->schedule(schedule_selector(ColorTable::onIdleUnfilled), _DeltaTime); } void ColorTable::leaveUnfilled() { exit(); } void ColorTable::enterFallen() { this->schedule(schedule_selector(ColorTable::onIdleFallen), _DeltaTime); } void ColorTable::leaveFallen() { exit(); } //////////////////////////// Public Events //////////////////////////// void ColorTable::onIdleVacancy(float dt) { _fsm->shuffle(); } void ColorTable::onIdleShuffleFilled(float dt) { } void ColorTable::onIdleFallenOver(float dt) { } void ColorTable::onIdleFilled(float dt) { } void ColorTable::onIdleUnfilled(float dt) { } void ColorTable::onIdleFallen(float dt) { } /////////////////////////// Public Methods //////////////////////////// bool ColorTable::init() { _fsm = new ColorTableContext(*this); _fsm->setDebugFlag(true); _fsm->enterStartState(); return true; } void ColorTable::exit() { this->unscheduleAllCallbacks(); } bool ColorTable::is_empty() { for (int index = 0; index < _NumCells; ++index) { if (table_[index] != INVALID) { return false; } } return true; } bool ColorTable::can_erase() { return false; } bool ColorTable::swap_done() { return swap_done_; } void ColorTable::shuffle() { init_table(); } void ColorTable::empty() { for (int cell = 0; cell < _NumCells; ++cell) { table_[cell] = INVALID; results_[cell] = 0; } } void ColorTable::erase() { } void ColorTable::fall() { } void ColorTable::fill() { } void ColorTable::print() { #if defined(COCOS2D_DEBUG) && defined(WIN32) FILE * fp = fopen("c:/temp/color-table.prt", "a+"); if (fp) { fprintf(fp, "\n>>>> %s {", _fsm->getState().getName()); fprintf(fp, "\n---- TABLE ----\n"); for (int row = 0; row < ColorTable_NumRows; ++row) { for (int col = 0; col < ColorTable_NumCols; ++col) { int v = color(row, col); fprintf(fp, " %c", ColorTable_ColorsPal[v]); } fprintf(fp, "\n"); } fprintf(fp, "\n---- RESULTS ----\n"); for (int row = 0; row < ColorTable_NumRows; ++row) { for (int col = 0; col < ColorTable_NumCols; ++col) { int v = result(row, col); fprintf(fp, " %d", v); } fprintf(fp, "\n"); } fprintf(fp, "}\n"); fclose(fp); } #endif }
三消游戏FSM状态机设计图的更多相关文章
- C++ 三消游戏基本实现
最近在研究三消算法,我想试试在完全不借助网络资源的情况下搞定这个东西,所以有些地方可能不是最优的. 代码留此备忘. 1. 3x_desk_event.h 1 #pragma once 2 3 #ifn ...
- 消消乐、candy crush类三消游戏程序逻辑分析
最近在开发一款类似消消乐的三消游戏,在碰到实现斜方向下落的时候卡住了很长时间.好几天没有思路,原本的思路是一次性预判多个宝石的一连串运动路径,运用缓动运动队列来实现宝石运动路径,例如 下落->滑 ...
- cocos2d-x 3.2 它 三消游戏——万圣节大作战
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- Unity3d开发“类三消”游戏
新建一个Project,导入图片素材和声音文件,把图片的Texture Type都修改为Sprite(2D and UI)[1].新建一个命名为Background的GameObject,为之添加背景 ...
- 最近用unity写三消游戏,mark一个准备用的unity插件,用来控制运动。
http://www.pixelplacement.com/itween/index.php itween 听说还不错!
- [翻译]:Artificial Intelligence for games 5.3 STATE MACHINES:状态机
目录 Chapter 5 Decision Making 5.3 STATE MACHINES:状态机 Chapter 5 Decision Making 5.3 STATE MACHINES:状态机 ...
- Creator开源游戏、插件、教程、视频汇总
Creator开源游戏.插件.教程.视频汇总 来源 http://forum.cocos.com/t/creator/44782 王哲首席客服 17-03-17 4 史上最全,没有之一. ...
- UNITY 状态机 + SVN + 码云 下篇
上篇说到自己写的一个FSM状态机,这篇写怎么把代码和码云联系在一起! 首先,我们应该知道为什么使用码云? 码云是开源中国社区2013年推出的基于 Git 的完全免费的代码托管服务,这个服务是基于 Gi ...
- unity 状态机 + svn + 码云 上篇
最近刚找到在实习,忙于公司一个c++ 项目 ,一直想写博客来着,没时间写今天熬夜打算先献上自己前几天自己封装的一个fsm状态机 话不多说,直接上正题,这篇博客主要是在学校的时候状态机一直使用的是pla ...
随机推荐
- J2EE进阶(十七)Hibernate中常用的HQL查询方法(getHibernateTemplate())
J2EE进阶(十七)Hibernate中常用的HQL查询方法(getHibernateTemplate()) 当我们使用Hibernate进行数据的CRUD操作时,利用模版进行操作不失为一种方法. ...
- 在Mac上搭建React Native开发环境
概述 前面我们介绍过在window环境下开发React Native项目,今天说说怎么在mac上搭建一个RN的开发环境. 配置mac开发环境 基本环境安装 1.先安装Homebrew:用于安装Node ...
- 用户创建,删除and并发注册and系统登陆的API研究(学习汇总网上资料)
一.系统登陆链接实现 比如有一个外围支持系统,用户需要在外围系统登录之后点个link就可以登录到Oracle ERP系统中,那么我们需要先把外围系统的用户创建在Oracle ERP中,并且分配职责给他 ...
- [Python]多个装饰器合并
django程序,需要写很多api,每个函数都需要几个装饰器,例如 @csrf_exempt @require_POST def foo(request): pass 既然那么多个方法都需要写2个装饰 ...
- SQLite Update 语句(http://www.w3cschool.cc/sqlite/sqlite-update.html)
SQLite Update 语句 SQLite 的 UPDATE 查询用于修改表中已有的记录.可以使用带有 WHERE 子句的 UPDATE 查询来更新选定行,否则所有的行都会被更新. 语法 带有 W ...
- 集合框架之Collections静态工具类
Collections类提供了一些列静态的方法,用以更方便地操作集合类 排序机制 一个List可以通过下面的方法进行排序: Collections.sort(list); 如果List包含的是字符串, ...
- Android View框架总结(八)ViewGroup事件分发机制
请尊重分享成果,转载请注明出处: http://blog.csdn.net/hejjunlin/article/details/52298780 上篇分析了View的事件分发流程,留了一个问题:如果上 ...
- webStorm破解
B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiw ...
- TCP的发送系列 — 发送缓存的管理(一)
主要内容:TCP发送缓存的初始化.动态调整.申请和释放. 内核版本:3.15.2 我的博客:http://blog.csdn.net/zhangskd 数据结构 TCP对发送缓存的管理是在两个层面上进 ...
- UNIX网络编程——客户/服务器程序设计示范(七)
TCP预先创建线程服务器程序,每个线程各自accept 前面讨论过预先派生一个子进程池快于为每个客户线程派生一个子进程.在支持线程的系统上,我们有理由预期在服务器启动阶段预先创建一个线程池以取 ...