title: How to properly implement cheat codes?
body: <p>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.</p>
  
  <p>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.</p>
  
  <pre><code>string[] CheatCodes = { "IDDQD", "IDKFA"};
  int[] CheatIndexes = { 0, 0 };
  const int CHEAT_COUNT = 2;
  void KeyPress(char c)
  {
      for (int i = 0; i &lt; 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; 
      }
  }
  </code></pre>
  
  <p>Is this the right way to do it?</p>
  
  <p>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 <strong>did not</strong> want to see Doom's source code or their implementation, but general solution to this problem.</p>