我正在用 Elm 编写一个游戏,在这个游戏中,有一个按钮,按下时应该将游戏板重置为其初始状态。但是,我不明白如何将按钮单击信号传播到板模型的更新功能。在下面的代码中,我刚刚将单位值传递给stepBoard
但我不能用它做太多所以我该如何解决它?
--MODEL
type Board = [(Int,Int)]
type Game = {name: String, board: Board}
defaultGame = {name = "Test", board = [(3,3)]}
--UPDATE
stepBoard click (colsInit, rowsInit) (rows, cols) g =
{g | board <- if ? then --some initial value (colsInit, rowsInit)
else --some updated value using (rows, cols)}
stepGame: Input -> Game -> Game
stepGame {click, name, rowsColsInit, rowsCols} g = stepBoard click (0,0) (0,0) g
game = foldp stepGame defaultGame input
--INPUT
type Input = {click:(), name: String, rowsColsInit: (Int,Int), rowsCols: (Int,Int)}
input = Input <~ clicks ~ nameSignal ~ rowsColsInitSignal ~ rowsColsSignal
--VIEW
(btn, clicks) = Input.button "Click"