Skip to content

Instantly share code, notes, and snippets.

@jnicklas
Forked from cowboyd/konami.ts
Created April 20, 2021 08:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnicklas/d9e17f304382e3a92231bf91dc1cabb2 to your computer and use it in GitHub Desktop.
Save jnicklas/d9e17f304382e3a92231bf91dc1cabb2 to your computer and use it in GitHub Desktop.
Konami Code detector written in effection
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