Created
November 19, 2020 19:42
-
-
Save cowboyd/c30afd4f789c9249a54e78ca5a0921ae to your computer and use it in GitHub Desktop.
Konami Code detector written in effection
This file contains 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