Skip to content

Commit

Permalink
Hide Turn type constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Oct 19, 2016
1 parent 9c17519 commit 4b73f3a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
49 changes: 27 additions & 22 deletions src/Main.elm
Expand Up @@ -17,7 +17,7 @@ import Svg exposing (..)
import Svg.Attributes exposing (..)
import Tabletop exposing (Tabletop, positionFromMouseCoords)
import Task
import Turn exposing (Turn)
import Turn exposing (Turn, Phase(..))
import Window


Expand Down Expand Up @@ -87,26 +87,31 @@ update msg game =
Click { x, y } ->
case Player.getSelectedGangMember game.player of
Just fighter ->
let
attemptMove : Model -> Maybe Model
attemptMove model =
case
positionFromMouseCoords ( x, y ) game.windowScale
|> Model.attemptMove model
of
Ok m ->
Just m

Err ( s, m ) ->
Just m
in
( { game
| player =
game.player
|> \p -> { p | gang = Gang.update fighter.id ((flip andThen) attemptMove) p.gang }
}
, Cmd.none
)
case Turn.phase game.turn of
Movement ->
let
attemptMove : Model -> Maybe Model
attemptMove model =
case
positionFromMouseCoords ( x, y ) game.windowScale
|> Model.attemptMove model
of
Ok m ->
Just m

Err ( s, m ) ->
Just m
in
( { game
| player =
game.player
|> \p -> { p | gang = Gang.update fighter.id ((flip andThen) attemptMove) p.gang }
}
, Cmd.none
)

_ ->
( game, Cmd.none )

Nothing ->
( game, Cmd.none )
Expand Down Expand Up @@ -204,6 +209,6 @@ view game =
:: measuringTape
++ Gang.view game.player.gang Select
)
, Html.strong [] [ Html.text (toString game.turn.phase) ]
, Html.strong [] [ Html.text (Turn.phase game.turn |> toString) ]
, selectedFighterProfile
]
37 changes: 20 additions & 17 deletions src/Turn.elm
@@ -1,4 +1,4 @@
module Turn exposing (..)
module Turn exposing (Turn, Phase(..), init, round, advance, phase)


type Phase
Expand All @@ -8,33 +8,36 @@ type Phase
| Recovery


type alias Turn =
{ round : Int
, phase : Phase
}
type Turn
= Turn Int Phase


init : Turn
init =
{ round = 1
, phase = Movement
}
Turn 1 Movement


round : Turn -> Int
round (Turn num _) =
num


phase : Turn -> Phase
phase (Turn _ p) =
p


advance : Turn -> Turn
advance turn =
case turn.phase of
advance (Turn round phase) =
case phase of
Movement ->
{ turn | phase = Shooting }
Turn round Shooting

Shooting ->
{ turn | phase = HandToHand }
Turn round HandToHand

HandToHand ->
{ turn | phase = Recovery }
Turn round Recovery

Recovery ->
{ turn
| round = turn.round + 1
, phase = Movement
}
Turn (round + 1) Movement

0 comments on commit 4b73f3a

Please sign in to comment.