Skip to content

Commit

Permalink
Command instructs Player and then Completes
Browse files Browse the repository at this point in the history
Once the player has moved all their models, the turn advances to the
next phase
  • Loading branch information
mwunsch committed Oct 24, 2016
1 parent 9dd6147 commit 6e560fb
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions src/Main.elm
Expand Up @@ -14,7 +14,6 @@ import Model exposing (Model)
import Mouse
import Player exposing (Player)
import Random
import Result
import String exposing (join)
import Svg exposing (..)
import Svg.Attributes exposing (..)
Expand Down Expand Up @@ -74,7 +73,7 @@ type Msg
= Select Model
| Click Mouse.Position
| Command Action
-- idea here is to command a model to perform a certain action
| Complete Action
| Hover Mouse.Position
| KeyPress Keyboard.KeyCode
| Resize Int
Expand All @@ -98,36 +97,38 @@ update msg game =
in
case game.player.action of
Action.Move ->
let
move : Model -> Model
move f =
case Model.attemptMove f pos of
Ok model ->
model

Err ( _, model ) ->
model
in
Gang.update fighter.id (Maybe.map move) game.player.gang
|> (\gang -> { game | player = game.player |> (\p -> { p | gang = gang, action = Action.Await }) })
|> (flip (,)) Cmd.none
Player.takeAction (Player.Movement fighter pos) game.player
|> (\player -> { game | player = player })
|> (flip (,)) (Task.perform (always NoOp) Complete (Task.succeed Action.Move))

_ ->
let
pos =
positionFromMouseCoords ( x, y ) game.windowScale
in
if Tabletop.isWithinDistance 2 fighter.position pos then
( game, Cmd.none )
else
( { game | player = Player.deselectAll game.player }, Cmd.none )
if Tabletop.isWithinDistance 2 fighter.position pos then
( game, Cmd.none )
else
( { game | player = Player.deselectAll game.player }, Cmd.none )

Nothing ->
( game, Cmd.none )

Command action ->
( { game | player = game.player |> \p -> { p | action = action } }, Cmd.none )

Complete action ->
let
updateGame : GameState
updateGame =
case action of
Action.Move ->
if Gang.toList game.player.gang |> List.any (\m -> m.remainingMove > 0) then
game
else
{ game | turn = Turn.advance game.turn }

_ ->
game
in
( { updateGame | player = Player.await updateGame.player }, Cmd.none )

Hover { x, y } ->
( { game
| player =
Expand Down

0 comments on commit 6e560fb

Please sign in to comment.