-
-
Save jnicklas/d9e17f304382e3a92231bf91dc1cabb2 to your computer and use it in GitHub Desktop.
Konami Code detector written in effection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { run } from 'effection'; | |
import { once } from '@effection/events'; | |
run(function*() { | |
yield konamiCodeEntered(); | |
alert('99 lives!'); | |
}); | |
function * konamiCodeEntered() { | |
while (true) { | |
if (yield nextKeyIs('ArrowUp')) { | |
if (yield nextKeyIs('ArrowUp')) { | |
if (yield nextKeyIs('ArrowDown')) { | |
if (yield nextKeyIs('ArrowDown')) { | |
if (yield nextKeyIs('ArrowLeft')) { | |
if (yield nextKeyIs('ArrowRight')) { | |
if (yield nextKeyIs('ArrowLeft')) { | |
if (yield nextKeyIs('ArrowRight')) { | |
if (yield nextKeyIs('b')) { | |
if (yield nextKeyIs('a')) { | |
if (yield nextKeyIs('b')) { | |
if (yield nextKeyIs('a')) { | |
return; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
function* nextKeyIs(key: string) { | |
let [event]: [KeyboardEvent] = yield once(document, 'keydown'); | |
return event.key === key | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment