如何正确实施作弊码?
一般来说,实施作弊代码的最佳方法是什么? 我想到了 WinForms 应用程序,其中作弊代码可以解锁复活节彩蛋,但实现细节并不相关。
我想到的最好方法是为每个代码保留索引 - 让我们考虑一下著名的 DOOM 代码 - IDDQD 和 IDKFA,在一个虚构的 C# 应用程序中。
string[] CheatCodes = { "IDDQD", "IDKFA"};
int[] CheatIndexes = { 0, 0 };
const int CHEAT_COUNT = 2;
void KeyPress(char c)
{
for (int i = 0; i < CHEAT_COUNT; i++) //for each cheat code
{
if (CheatCodes[i][CheatIndexes[i]] == c)
{ //we have hit the next key in sequence
if (++CheatIndexes[i] == CheatCodes[i].Length) //are we in the end?
{
//Do cheat work
MessageBox.Show(CheatCodes[i]);
//reset cheat index so we can enter it next time
CheatIndexes[i] = 0;
}
}
else //mistyped, reset cheat index
CheatIndexes[i] = 0;
}
}
这是正确的做法吗?
编辑:也许我应该做的最糟糕的事情就是包含来自我头脑中的第一个作弊代码作为示例。我真的不想想要看到 Doom 的源代码或其实现,而是这个问题的一般解决方案。
what would be the best way to implement kind of cheat codes in general?
I have WinForms application in mind, where a cheat code would unlock an easter egg, but the implementation details are not relevant.
The best approach that comes to my mind is to keep index for each code - let's consider famous DOOM codes - IDDQD and IDKFA, in a fictional C# app.
string[] CheatCodes = { "IDDQD", "IDKFA"};
int[] CheatIndexes = { 0, 0 };
const int CHEAT_COUNT = 2;
void KeyPress(char c)
{
for (int i = 0; i < CHEAT_COUNT; i++) //for each cheat code
{
if (CheatCodes[i][CheatIndexes[i]] == c)
{ //we have hit the next key in sequence
if (++CheatIndexes[i] == CheatCodes[i].Length) //are we in the end?
{
//Do cheat work
MessageBox.Show(CheatCodes[i]);
//reset cheat index so we can enter it next time
CheatIndexes[i] = 0;
}
}
else //mistyped, reset cheat index
CheatIndexes[i] = 0;
}
}
Is this the right way to do it?
Edit: Probably the worst thing I should have done was to include the first cheat codes that came from the top of my head as an example. I really did not want to see Doom's source code or their implementation, but general solution to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不下载 DOOM 源代码并亲自看看呢? =)
http://www.doomworld.com/idgames/?id=14576
Why not download the DOOM source and see for yourself? =)
http://www.doomworld.com/idgames/?id=14576
我认为这个更容易理解一点,尽管你原来的可能会比这个表现更好:
I think this one's a bit easier to understand, though your original will probably perform better than this one:
这是来自 doom 源代码的 DOOM 作弊实现:
here is the DOOM cheat implementation from the doom source: