-- TODO split in model, view module Bucket exposing (createBucket, Bucket, Row, colorToString, Color, draw2d, drawTetromino) import Array exposing (Array) type alias Bucket = Array Row type alias Row = Array Color -- TODO better be an array as well? -> type Color = Cyan | Blue | Orange | Yellow | Lime | Purple | Red | None -- TODO decode JSON -> to lower case instead? colorToString : Color -> String colorToString color = case color of Cyan -> "cyan" Blue -> "blue" Orange -> "orange" Yellow -> "yellow" Lime -> "lime" Purple -> "purple" Red -> "red" None -> "black" createBucket : Int -> Int -> Bucket createBucket width height = Array.append (Array.repeat height (Array.repeat width None)) (Array.repeat 1 (Array.repeat width Red)) tetrominoes = [[ [{x = 2, y = 0}, {x = 2, y = 1}, {x = 2, y = 2}, {x = 2, y = 3}], [{x = 2, y = 0}, {x = 2, y = 1}, {x = 2, y = 2}, {x = 2, y = 3}], [{x = 2, y = 0}, {x = 2, y = 1}, {x = 2, y = 2}, {x = 2, y = 3}], [{x = 2, y = 0}, {x = 2, y = 1}, {x = 2, y = 2}, {x = 2, y = 3}] ],[ [{x = 2, y = 1}, {x = 3, y = 1}, {x = 2, y = 1}, {x = 3, y = 1}], [{x = 2, y = 1}, {x = 3, y = 1}, {x = 2, y = 1}, {x = 3, y = 1}], [{x = 2, y = 1}, {x = 3, y = 1}, {x = 2, y = 1}, {x = 3, y = 1}], [{x = 2, y = 1}, {x = 3, y = 1}, {x = 2, y = 1}, {x = 3, y = 1}] ] ] drawTetromino bucket coords = -- List.map (draw2d bucket) coords draw2d bucket 3 10 -- TODO x and y could be a record (also in definitions, so easy passing) draw2d : Bucket -> Int -> Int -> Bucket draw2d bucket x y = Array.set y ( -- row case Array.get y bucket of Nothing -> Array.repeat 10 None -- column Just row -> Array.set x Yellow row ) bucket