【发布时间】:2010-11-20 19:29:10
【问题描述】:
我正在写一个文字游戏,我需要一个简单的战斗系统,就像在 MUD 中一样,你发出命令,偶尔会发生“滴答”,当所有这些命令执行时,玩家和怪物会造成各种伤害不同的事情发生。我如何实现这个概念? 我考虑过创建一个保存最后滴答时间的变量,以及一个仅将事件放在堆栈上的函数,当那个时间是 (time +x) 时,它们会同时执行。有没有更简单或更干净的变体来做到这一点?
可能的语法是什么?
double lastTickTime;
double currentTime;
void eventsPile(int event, int target)
{
// how do i implement stack of events? And send them to execute() when time is up?
}
void execute(int event, int target)
{
if ((currentTime - lastTickTime) == 2)
{
eventsHandler(event, target);
}
else
{ // How do I put events on stack?
}
}
【问题讨论】:
-
你所拥有的对我来说听起来不错。
-
我过去曾使用过这种方法,效果很好,物有所值。
-
已更新,在实施或阅读内容方面需要帮助。