Lua情节链设计2
来源:互联网 发布:平克弗洛伊德知乎 编辑:程序博客网 时间:2024/04/30 18:40
--[[ file name . GameList.lua author . Clark/陈泽丹 created . 8.30.2011 purpose . 双向队列--]]module("GameList", package.seeall)--双向队列function list_newList() local m_first = 1 local m_last = 0 local m_list = {} local m_listManager = {} function m_listManager.pushFront(_tempObj) m_first = m_first - 1 m_list[m_first] = _tempObj end function m_listManager.pushBack(_tempObj) m_last = m_last + 1 m_list[m_last] = _tempObj end function m_listManager.temp_getFront() if m_listManager.bool_isEmpty() then return nil else local val = m_list[m_first] return val end end function m_listManager.temp_getBack() if m_listManager.bool_isEmpty() then return nil else local val = m_list[m_last] return val end end function m_listManager.popFront() m_list[m_first] = nil m_first = m_first + 1 end function m_listManager.popBack() m_list[m_last] = nil m_last = m_last - 1 end function m_listManager.clear() while false == m_listManager.bool_isEmpty() do m_listManager.popFront() end end function m_listManager.bool_isEmpty() if m_first > m_last then m_first = 1 m_last = 0 return true else return false end end function m_listManager.d_getSize() if m_listManager.bool_isEmpty() then return 0 else return m_last - m_first + 1 end end return m_listManagerend
--[[ file name : GameEvents.lua author : Clark/陈泽丹 created : 8:30:2011 purpose : 故事情节线--]]module("GameEvents", package.seeall)pakList = require "GameList"pakGameCallBack = require "GameCallBack"g_fun = nil--死亡回调函数function onDieCallBack() g_fun(1)end--事件流function events_newEvents()local TYPE = {FUN_TYPE = 0, TGR_TYPE = 1}local m_funs = pakList.list_newList() --隐藏数据local m_events = {} --公开数据--添加事件function m_events.pushFun(_fun)local tFun = {fun = _fun, fun_type = TYPE.FUN_TYPE}m_funs.pushBack(tFun)endfunction m_events.pushTgr(_fun)function setTgr()print("setTgr ")g_fun = onTgrendfunction onTgr(_callbackPar)print("onTgr " .. _callbackPar)g_fun = nil_fun(_callbackPar)m_events.doEvents()endlocal tFun = {fun = setTgr, fun_type = TYPE.TGR_TYPE}m_funs.pushBack(tFun)end--清空事件function m_events.clear()print("m_events.clear")m_funs.clear()end--开始剧情function m_events.doEvents()while false == m_events.bool_isEmpty() dolocal tFun = m_funs.temp_getFront()m_funs.popFront()tFun.fun()tFun.fun = nilif TYPE.FUN_TYPE ~= tFun.fun_type thentFun = nilreturnendendif m_events.bool_isEmpty() thenm_events.clear()endend--是否还有事件function m_events.bool_isEmpty()return m_funs.bool_isEmpty()endreturn m_events --返回公开数据end
--[[ file name : GameMain.lua author : Clark/陈泽丹 created : 8:30:2011 purpose : 客户端程序--]]module("GameMain", package.seeall)pakGameEvents = require "GameEvents"------------------------ 客户端 -----------------------------function map_newMap() local m_map = {}local m_ETs = pakGameEvents.events_newEvents()function m_map.Fun1()print("1")endfunction m_map.Fun2()print("2")endfunction m_map.Fun3()print("3")end --初始化 function m_map.initScene() print("---------- initScene ----------")m_ETs.pushFun(m_map.Fun1)m_ETs.pushTgr(m_map.Fun2)m_ETs.pushFun(m_map.Fun3)m_ETs.pushTgr(m_map.Fun2)m_ETs.doEvents()pakGameEvents.onDieCallBack()pakGameEvents.onDieCallBack() end --结束 function m_map.uninitScene() print("---------- uninitScene ----------") end return m_mapendfunction main() m_map = map_newMap(007) m_map.initScene()endmain()-------------------------------------------------------------
结果:
>lua -e "io.stdout:setvbuf 'no'" "GameMain.lua"
---------- initScene ----------
1
setTgr
onTgr 1
2
3
setTgr
onTgr 1
2
m_events.clear
>Exit code: 0
- Lua情节链设计2
- Lua里设计情节链
- 情节链设计3
- 情节
- 南京情节
- JAVA情节
- Delphi情节
- 植物情节
- 兄弟情节
- 养老情节
- 足球情节
- lua设计宠物系统
- 我的刘德华情节
- TOMCAT 的.16情节
- 我的文学情节
- 我的IT情节
- 三国情节(占位:)
- 我的羽毛球情节
- The Xbox 360 reset glitch hack
- Java中WeakReference、WeakHashMap、SoftReference、ReferenceQueue的作用和使用场景
- 08-27~29 HDU1010 USACO4.3~4.4 搜索剪枝,模拟,拓扑,网络流
- 用BOOTICE工具创建U盘隐藏分区制作PE启动盘(
- jquery的插件
- Lua情节链设计2
- 帝国时代,罗马复兴【基址+偏移】
- 关于erphp框架的使用说明
- android 对listview数据的增删改查
- Android下可用的wide char 函数库
- 硬件加速 CoolUI 1.0 ----- 【再接再厉】
- 普通软件公司,请别学华为
- Linux 安装JDK1.6
- 在Linux下安装Oracle