summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 09:52:54 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-15 09:52:54 +0200 |
commit | 9a2d8f37dea8e14afa57affb135def13954df547 (patch) | |
tree | ee7daa101ffdb76bc4a5932c3698b6a89613df78 /client/elm/battlemap/src/Battlemap.elm |
Satisfied with Elm so far, let's go with it.
Diffstat (limited to 'client/elm/battlemap/src/Battlemap.elm')
-rw-r--r-- | client/elm/battlemap/src/Battlemap.elm | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/client/elm/battlemap/src/Battlemap.elm b/client/elm/battlemap/src/Battlemap.elm new file mode 100644 index 0000000..dbf797a --- /dev/null +++ b/client/elm/battlemap/src/Battlemap.elm @@ -0,0 +1,47 @@ +module Battlemap exposing (Battlemap, random, apply_to_tile) + +import Array exposing (Array, set, get) + +import Battlemap.Tile exposing (Tile, generate) +import Battlemap.Direction exposing (..) +import Battlemap.Location exposing (..) + +type alias Battlemap = + { + width : Int, + height : Int, + content : (Array Tile) + } + +random : Battlemap +random = + { + width = 6, + height = 6, + content = (generate 6 6) + } + +location_to_index : Battlemap -> Location -> Int +location_to_index bmap loc = + ((loc.y * bmap.width) + loc.x) + +apply_to_tile : Battlemap -> Location -> (Tile -> Tile) -> (Maybe Battlemap) +apply_to_tile bmap loc fun = + let + index = (location_to_index bmap loc) + at_index = (get index bmap.content) + in + case at_index of + Nothing -> + Nothing + (Just tile) -> + (Just + {bmap | + content = + (set + index + (fun tile) + bmap.content + ) + } + ) |