游戏中的攻击频率如何实现?
在一款RPG游戏中,假设有角色A和B,
A每秒会进行x次攻击,
B每秒会进行y次攻击,
假设A发起攻击,最终的攻击可能是:
AABAB...
如何计算攻击顺序?
In a RPG game,suppose there are role A and B.
A will conduct x attacks per second
B will conduct y attacks per second
If we suppose A initiates the attack and the final attacks may be :
A A B A B ...
How to calculate the sequence of attacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是在 Python 3.0 中使用生成器和分数执行此操作的一种方法:
输出:
需要检查攻击频率 0。为了简单起见,我没有在上面的代码中这样做,但它很容易修复,并且可能最好在此函数之外处理(无论如何,一个玩家无法攻击的战斗不会很有趣)。
这个想法的一个优点是它可以很容易地扩展到两个以上的同时玩家。
另一个优点是它还可以在不做任何修改的情况下处理每秒小于一次攻击的攻击率(例如B攻击每两秒一次,即攻击频率=0.5)。
Here's one way to do it in Python 3.0 using a generator and fractions:
Output:
An attack frequency of 0 needs to be checked for. I haven't done this in the above code for simplicity, but it's easy to fix and probably best handled outside this function (a battle where one player can't attack wouldn't be very interesting anyway).
An advantage of this idea is that it could be easily extended to more than 2 simultaneous players.
Another advantage is that it can also handle attack rates of less than one attack per second without any modification (e.g. B attacks only once every two seconds, i.e. attack frequency = 0.5).
统计谁的攻击次数多。叫他更多。除以 MORE/LESS 并占据发言权,结果 = N。然后,对于 MORE 的每 N 次攻击,添加 LESS 之一,并在完成后用 MORE 的攻击填充。这就是每一秒。
例子:
另一个例子:
Count who has more attacks. Call him MORE. Divide MORE/LESS and take floor, the result is = N. Then for every N attacks of MORE add one of LESS and pad with attacks of MORE when finished. That's each second.
Example:
Another example: