28 lines
881 B
Elm
28 lines
881 B
Elm
module Go.View exposing (..)
|
|
import Go.Util exposing (allIndices, pair, lookup)
|
|
import Go.Types exposing (..)
|
|
import Html exposing (Html, div, text, p)
|
|
import Html.Attributes exposing (class, classList)
|
|
import Html.Events exposing (onClick)
|
|
import List exposing (map)
|
|
|
|
renderIndex : (Index, Maybe Color) -> Html Msg
|
|
renderIndex (index, color) =
|
|
let
|
|
extraClass = case color of
|
|
Just c -> (if c == Black then "black-cell" else "white-cell", True)
|
|
Nothing -> ("", False)
|
|
in
|
|
div [ classList [ ("board-cell", True), extraClass ]
|
|
, onClick (Place index)
|
|
]
|
|
[ div [ class "overlay" ] []
|
|
]
|
|
|
|
renderBoard : Int -> Board -> Html Msg
|
|
renderBoard size board =
|
|
let
|
|
cells = map (\i -> (i, lookup i board)) <| allIndices size
|
|
in
|
|
div [ class "board" ] <| map renderIndex cells
|