summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-21 16:32:09 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-09-21 16:32:09 +0200 |
commit | 0d5fba42a1597e5a43266c071776e7acf58071e2 (patch) | |
tree | 374ab9f5128486f4cbad57fca35cc5d61a8f2f7b | |
parent | 7b9ac4352353203fd1422a93fc7ef3a0daf8a768 (diff) |
Adds movement points, indicator for current char.
-rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 31 | ||||
-rw-r--r-- | client/elm/battlemap/src/Character.elm | 3 | ||||
-rw-r--r-- | client/elm/battlemap/src/Model.elm | 9 | ||||
-rw-r--r-- | client/elm/battlemap/src/Update.elm | 12 | ||||
-rw-r--r-- | client/elm/battlemap/src/View.elm | 25 |
5 files changed, 63 insertions, 17 deletions
diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index e821ac0..3cabf8e 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -12,6 +12,7 @@ import List as Lt exposing (head, tail) import Battlemap exposing (Battlemap, has_location, apply_to_tile) import Battlemap.Direction exposing (Direction(..), opposite_of) import Battlemap.Tile exposing (Tile, set_direction) +import Character exposing (Character) import Battlemap.Location exposing ( @@ -25,15 +26,17 @@ type alias Navigator = { current_location : Location, visited_locations : (Set LocationRef), - previous_directions : (List Direction) + previous_directions : (List Direction), + remaining_points : Int } -new_navigator : Location -> Navigator -new_navigator start = +new_navigator : Location -> Int -> Navigator +new_navigator start points = { current_location = start, visited_locations = empty, - previous_directions = [] + previous_directions = [], + remaining_points = points } @@ -43,14 +46,17 @@ reset_navigation t = nav_level = None } -go : Battlemap -> Navigator -> Direction -> (Battlemap, Navigator) -go battlemap nav dir = +go : Battlemap -> Navigator -> Direction -> (List Character) -> (Battlemap, Navigator) +go battlemap nav dir char_list = let next_location = (neighbor nav.current_location dir) + is_occupied = (Lt.any (\c -> (c.location == next_location)) char_list) in if ( - (has_location battlemap next_location) + (not is_occupied) + && (nav.remaining_points > 0) + && (has_location battlemap next_location) && (nav.current_location /= next_location) && (not (member (to_comparable next_location) nav.visited_locations)) ) @@ -83,10 +89,12 @@ go battlemap nav dir = (to_comparable nav.current_location) nav.visited_locations ), - previous_directions = (dir :: nav.previous_directions) + previous_directions = (dir :: nav.previous_directions), + remaining_points = (nav.remaining_points - 1) } ) - else + else if (not is_occupied) + then case ( (Lt.head nav.previous_directions), @@ -116,8 +124,11 @@ go battlemap nav dir = (to_comparable next_location) nav.visited_locations ), - previous_directions = prev_dir_list + previous_directions = prev_dir_list, + remaining_points = (nav.remaining_points + 1) } ) else (battlemap, nav) + else + (battlemap, nav) diff --git a/client/elm/battlemap/src/Character.elm b/client/elm/battlemap/src/Character.elm index 4804cd0..5c64d45 100644 --- a/client/elm/battlemap/src/Character.elm +++ b/client/elm/battlemap/src/Character.elm @@ -8,7 +8,8 @@ type alias Character = name : String, icon : String, portrait : String, - location : Location + location : Location, + movement_points : Int } type alias CharacterRef = String diff --git a/client/elm/battlemap/src/Model.elm b/client/elm/battlemap/src/Model.elm index a019c45..85b123b 100644 --- a/client/elm/battlemap/src/Model.elm +++ b/client/elm/battlemap/src/Model.elm @@ -30,7 +30,8 @@ model = name = "Char2", icon = "Icon2", portrait = "Portrait2", - location = {x = 1, y = 4} + location = {x = 1, y = 4}, + movement_points = 6 } (insert "1" @@ -39,7 +40,8 @@ model = name = "Char1", icon = "Icon1", portrait = "Portrait1", - location = {x = 4, y = 1} + location = {x = 4, y = 1}, + movement_points = 10 } (insert "0" @@ -48,7 +50,8 @@ model = name = "Char0", icon = "Icon0", portrait = "Portrait0", - location = {x = 0, y = 0} + location = {x = 0, y = 0}, + movement_points = 16 } empty ) diff --git a/client/elm/battlemap/src/Update.elm b/client/elm/battlemap/src/Update.elm index 2c86c4a..0fef667 100644 --- a/client/elm/battlemap/src/Update.elm +++ b/client/elm/battlemap/src/Update.elm @@ -7,7 +7,7 @@ import Battlemap.Direction exposing (Direction) import Battlemap.Navigator as Nr exposing (go, reset_navigation) -import Dict as Dt exposing (get, update) +import Dict as Dt exposing (get, update, values) import Character exposing (CharacterRef) @@ -29,6 +29,7 @@ handle_direction_request model dir = model.battlemap nav dir + (Dt.values model.characters) ) in {model | @@ -50,7 +51,7 @@ handle_select_character model char_id = (case (Dt.get char_id model.characters) of Nothing -> Nothing (Just char) -> - (Just (Nr.new_navigator char.location)) + (Just (Nr.new_navigator char.location char.movement_points)) ) } @@ -65,7 +66,12 @@ handle_end_turn model = (Just char) -> {model | navigator = - (Just (Nr.new_navigator nav.current_location)), + (Just + (Nr.new_navigator + nav.current_location + char.movement_points + ) + ), battlemap = (apply_to_all_tiles (apply_to_tile_unsafe diff --git a/client/elm/battlemap/src/View.elm b/client/elm/battlemap/src/View.elm index d0cb8c8..50fa563 100644 --- a/client/elm/battlemap/src/View.elm +++ b/client/elm/battlemap/src/View.elm @@ -9,6 +9,7 @@ import Model exposing (Model) import Battlemap.Html as Batmap exposing (view) import Battlemap.Direction exposing (Direction(..)) +import Dict as Dt exposing (get) -- VIEW view : Model -> (Html Msg) @@ -39,6 +40,30 @@ view model = (div [] [(Batmap.view model)] + ), + (div + [] + [ + (text + (case (model.selection, model.navigator) of + (Nothing, _) -> "" + (_, Nothing) -> "" + ((Just char_id), (Just nav)) -> + case (Dt.get char_id model.characters) of + Nothing -> "" + (Just char) -> + ( + "Controlling " + ++ char.name + ++ ": " + ++ (toString nav.remaining_points) + ++ "/" + ++ (toString char.movement_points) + ++ " movement points remaining." + ) + ) + ) + ] ) ] ) |