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