Update.hs

1
2
3
4
5
6
7
8
9
10
11
updateGame :: PlayerNumber -> Card -> FlagNumber -> GameState -> GameState
updateGame p c f g =
  case p of
       PlayerOne -> g { gameFlags = flags, gamePlayer1 = player, gameDeck = deck }
       PlayerTwo -> g { gameFlags = flags, gamePlayer2 = player, gameDeck = deck }
  where
    (cards, deck) = draw 1 $ gameDeck g
    player = giveCards cards $ removeCard c $ getPlayer p g
    flag = getFlag f g
    flag' = playCardToFlag p c flag
    flags = replace flag flag' $ gameFlags g

Update.hs (annotation)

1
2
3
4
5
6
7
8
9
10
11
12
updateGame :: PlayerNumber -> Card -> FlagNumber -> GameState -> GameState
updateGame p c f g =
  case p of
       PlayerOne -> g1 { gamePlayer1 = player }
       PlayerTwo -> g1 { gamePlayer2 = player }
  where
    g1 = g { gameFlags = flags, gameDeck = deck }
    (cards, deck) = draw 1 $ gameDeck g
    player = giveCards cards $ removeCard c $ getPlayer p g
    flag = getFlag f g
    flag' = playCardToFlag p c flag
    flags = replace flag flag' $ gameFlags g