Reputation: 113
I'm trying to write a game of life clone in Elm and I've got some difficulty with how to draw an updating board.
I represent the cells on the board as (List (List Int))
in a variable called gameBoardList
I use this function to update the board
transformBoardList : List (List Int) -> List (List Int)
transformBoardList l = nextVertRow l 0
I'm able to turn the gameBoardList
into a form and draw it as an element, and even apply the transformBoardList
function to that without an issue.
What I don't understand is how I can have my board updating constantly. I've checked out the past dependent mapping but it looks to me like I need some sort of recursive mapping so I can keep applying transformBoardList
every update
Any ideas how I can achieve this?
Upvotes: 2
Views: 497
Reputation: 5958
If you have some game state, and an update function, you can use those and foldp
and a time ticker to get a regularly updating game.
startState = gameBoardList -- for example
update = transformBoardList -- for example
view = .. -- you said you had this too
input = Time.every second -- a time ticker
state = Signal.foldp (\_ s -> update s) startState input
main = view <~ state
Upvotes: 1