Skip to content

Instantly share code, notes, and snippets.

@smaldini
Last active August 29, 2015 14:21
Show Gist options
  • Save smaldini/5d890e21dc3211aeb705 to your computer and use it in GitHub Desktop.
Save smaldini/5d890e21dc3211aeb705 to your computer and use it in GitHub Desktop.
Konami
final Broadcaster<Integer> keyboardStream = Broadcaster.create();
Promise<List<Boolean>> konamis = keyboardStream
.skipWhile(key -> KeyEvent.VK_UP != key)
.buffer(10, 1)
.map(keys -> keys.size() == 10 &&
keys.get(0) == KeyEvent.VK_UP &&
keys.get(1) == KeyEvent.VK_UP &&
keys.get(2) == KeyEvent.VK_DOWN &&
keys.get(3) == KeyEvent.VK_DOWN &&
keys.get(4) == KeyEvent.VK_LEFT &&
keys.get(5) == KeyEvent.VK_RIGHT &&
keys.get(6) == KeyEvent.VK_LEFT &&
keys.get(7) == KeyEvent.VK_RIGHT &&
keys.get(8) == KeyEvent.VK_B &&
keys.get(9) == KeyEvent.VK_A
)
.toList();
keyboardStream.onNext(KeyEvent.VK_UP);
keyboardStream.onNext(KeyEvent.VK_UP);
keyboardStream.onNext(KeyEvent.VK_UP);
keyboardStream.onNext(KeyEvent.VK_DOWN);
keyboardStream.onNext(KeyEvent.VK_DOWN);
keyboardStream.onNext(KeyEvent.VK_LEFT);
keyboardStream.onNext(KeyEvent.VK_RIGHT);
keyboardStream.onNext(KeyEvent.VK_LEFT);
keyboardStream.onNext(KeyEvent.VK_RIGHT);
keyboardStream.onNext(KeyEvent.VK_B);
keyboardStream.onNext(KeyEvent.VK_A);
keyboardStream.onNext(KeyEvent.VK_C);
keyboardStream.onComplete();
System.out.println(konamis.await());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment