Skip to content

Commit

Permalink
Merge pull request #2142 from vlakoff/konami
Browse files Browse the repository at this point in the history
Better implementation of Konami code easter egg
  • Loading branch information
xenolightning committed Jan 4, 2017
2 parents 37c632c + 96ec0a4 commit 140f4e4
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions FortyOne.AudioSwitcher/AudioSwitcher.cs
Expand Up @@ -26,7 +26,7 @@ public partial class AudioSwitcher : Form
/// <summary>
/// EASTER EGG! SHHH!
/// </summary>
private const string KONAMI_CODE = "UUDDLRLRBA";
private readonly Keys[] KONAMI_CODE = { Keys.Up, Keys.Up, Keys.Down, Keys.Down, Keys.Left, Keys.Right, Keys.Left, Keys.Right, Keys.B, Keys.A };

private static AudioSwitcher _instance;
private readonly Icon _originalTrayIcon;
Expand Down Expand Up @@ -58,7 +58,7 @@ public partial class AudioSwitcher : Form
private DeviceState _deviceStateFilter = DeviceState.Active;
private bool _doubleClickHappened;
private bool _firstStart = true;
private string _input = "";
private int _konamiIndex = 0;
private AudioSwitcherVersionInfo _retrievedVersion;
private bool _updateAvailable;
public bool DisableHotKeyFunction = false;
Expand Down Expand Up @@ -464,29 +464,24 @@ private void button1_Click(object sender, EventArgs e)

private void AudioSwitcher_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
_input += "U";
else if (e.KeyCode == Keys.Down)
_input += "D";
else if (e.KeyCode == Keys.Left)
_input += "L";
else if (e.KeyCode == Keys.Right)
_input += "R";
else if (e.KeyCode == Keys.A)
_input += "A";
else if (e.KeyCode == Keys.B)
_input += "B";

if (_input.Length > KONAMI_CODE.Length)
if (e.KeyCode == KONAMI_CODE[_konamiIndex])
{
_input = _input.Substring(1);
}
if (_konamiIndex == KONAMI_CODE.Length - 1)
{
_konamiIndex = 0;

if (_input == KONAMI_CODE)
var rand = new Random();
var index = rand.Next(YOUTUBE_VIDEOS.Length);
Process.Start(YOUTUBE_VIDEOS[index]);
}
else
{
++_konamiIndex;
}
}
else
{
var rand = new Random();
var index = rand.Next(YOUTUBE_VIDEOS.Length);
Process.Start(YOUTUBE_VIDEOS[index]);
_konamiIndex = 0;
}
}

Expand Down

0 comments on commit 140f4e4

Please sign in to comment.