Created
December 25, 2015 09:57
-
-
Save Thimoteus/7b53aa8de6476b931fe6 to your computer and use it in GitHub Desktop.
the world's simplest incremental game
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
<!doctype html> | |
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:foo="http://www.w3.org/2000/svg"> | |
<head> | |
<title>clickber-builder</title> | |
<style> | |
body { | |
font-family: sans-serif; | |
max-width: 800px; | |
margin: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="app.js"></script> | |
</body> | |
</html> |
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
module Main where | |
import Prelude | |
import Data.Lens (LensP(), (+~), lens) | |
import Control.Monad.Aff (runAff, later, later') | |
import Control.Monad.Eff (Eff()) | |
import Control.Monad.Eff.Exception (throwException) | |
import Control.Monad.Rec.Class (forever) | |
import Halogen | |
( Component(), ComponentHTML(), component | |
, Natural(), ComponentDSL(), HalogenEffects() | |
, runUI, modify, action | |
) | |
import Halogen.Util (appendToBody, onLoad) | |
import Halogen.HTML.Indexed (div_, h1_, text, button) | |
import Halogen.HTML.Events.Indexed (onMouseDown, input_) | |
data Action a = Click a | |
type State = { clicks :: Number } | |
clicks :: LensP State Number | |
clicks = lens _.clicks (_ { clicks = _ }) | |
initialState :: State | |
initialState = { clicks: 0.0 } | |
theButton :: forall g. (Functor g) => Component State Action g | |
theButton = component render eval | |
where | |
render :: State -> ComponentHTML Action | |
render state = | |
div_ | |
[ h1_ | |
[ text "The world's simplest incremental game" ] | |
, button | |
[ onMouseDown (input_ Click) ] | |
[ text "Click me!" ] | |
, div_ | |
[ text (show state.clicks) ] | |
] | |
eval :: Natural Action (ComponentDSL State Action g) | |
eval (Click next) = do | |
modify $ clicks +~ 1.0 | |
pure next | |
main :: Eff (HalogenEffects ()) Unit | |
main = runAff throwException (const (pure unit)) do | |
app <- runUI theButton initialState | |
onLoad $ appendToBody app.node | |
forever do | |
app.driver $ action Click | |
later' 1000 $ pure unit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment