Konami Code in C#

后端 未结 11 2132
执笔经年
执笔经年 2020-12-07 19:07

I am looking to have a C# application implement the Konami Code to display an Easter Egg. http://en.wikipedia.org/wiki/Konami_Code

What is the best way to do this?<

11条回答
  •  轮回少年
    2020-12-07 19:52

    Catch keypresses into a 13(or whatever subset of the code, since you probably don't want to include the START key)-character list/array/string/whatever before processing them normally. Every time a key is added, if (and only if) it's the last key in the series, match the buffer against the correct konami code.

    My suggestion is, if they hit an arrow key, map it to the sensible letter... then map B and A as well, simply clearing the buffer for any other keypress.

    Then, making the buffer a string, compare it to: "UUDDLRLRBABA"

提交回复
热议问题