Last active
February 3, 2017 03:23
-
-
Save jinjor/8cf79904c004dd924e7ce3313135795f to your computer and use it in GitHub Desktop.
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
| <html> | |
| <script src="konami.js"></script> | |
| <script> | |
| var app = Elm.Konami.worker(); | |
| app.ports.succeed.subscribe(function() { | |
| alert('success!'); | |
| }); | |
| </script> | |
| </html> |
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
| port module Konami exposing (..) | |
| import Char | |
| import Keyboard exposing (KeyCode) | |
| main = | |
| Platform.program | |
| { init = init | |
| , update = update | |
| , subscriptions = subscriptions | |
| } | |
| -- PORT | |
| port succeed : () -> Cmd msg | |
| -- COMMAND | |
| up = 38 | |
| down = 40 | |
| left = 37 | |
| right = 39 | |
| b = Char.toCode 'B' | |
| a = Char.toCode 'A' | |
| command : List KeyCode | |
| command = | |
| [ up, up, down, down, left, right, left, right, b, a ] | |
| -- MODEL | |
| type alias Model = List KeyCode | |
| init : (Model, Cmd Msg) | |
| init = | |
| command ! [] | |
| -- UPDATE | |
| type Msg | |
| = Key KeyCode | |
| update : Msg -> Model -> (Model, Cmd Msg) | |
| update msg model = | |
| case msg of | |
| Key keyCode -> | |
| case model of | |
| key :: tail -> | |
| if key == keyCode then | |
| (tail, if tail == [] then succeed () else Cmd.none) | |
| else | |
| command ! [] | |
| _ -> | |
| model ! [] | |
| -- SUBSCRIPTIONS | |
| subscriptions : Model -> Sub Msg | |
| subscriptions model = | |
| Keyboard.downs Key |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an example usage of Platform.program.
This app handles Konami Code.