Skip to content

Commit

Permalink
lifecycle: go to LootView once game turn limit is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Sep 20, 2021
1 parent 5e4a0d4 commit 0e4e597
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/shared/Model.hs
Expand Up @@ -111,7 +111,7 @@ gameToDeck GameModel {..} =
PlayerPart {..} = Board.toPart board playingPlayer
inPlace' = inPlace & Map.elems & map (\Creature {creatureId, items} -> IDC creatureId items)

endGame :: GameModel -> Campaign.Outcome -> Model
endGame :: GameModel -> Campaign.Outcome -> LootModel
endGame
GameModel
{ board,
Expand All @@ -123,9 +123,9 @@ endGame
outcome =
case Campaign.succ level of
Nothing -> error "You've finished the game!" -- Not really a nice end for now
Just next -> LootModel' $ LootModel {..}
Just next -> LootModel {..}
where
nbRewards = 1
nbRewards = 1 -- Change this?
rewards = zip (Campaign.loot outcome level team) $ repeat NotPicked
team = Board.toPart board pSpot & Board.team

Expand Down
34 changes: 25 additions & 9 deletions app/shared/Update.hs
Expand Up @@ -271,7 +271,7 @@ data Action
| -- | Actions internal to 'LootView'
LootAction' LootAction
| -- | Go to 'LootView'
LootGo
LootGo LootModel
| NoOp
| MultiPlayerLobbyAction' MultiPlayerLobbyAction
| SayHelloWorld
Expand Down Expand Up @@ -471,13 +471,10 @@ updateGameModel m@GameModel {board, difficulty, shared, turn} GameEndTurnPressed
Game.Result shared' board' () boardui' <- Game.playAll shared board placements
return $ m {anims = boardui', board = board', shared = shared'}
else Right m
updateGameModel m@GameModel {board, shared, turn} GameIncrTurn _ =
case (Turn.next turn, x) of
(turn', _)
| Turn.toNat turn' > Constants.nbTurns ->
undefined -- TODO @smelc Go to LootView
(_, Left err) -> updateDefault m $ ShowErrorInteraction err
(_, Right res) -> res
updateGameModel m@GameModel {board, shared} GameIncrTurn _ =
case x of
Left err -> updateDefault m $ ShowErrorInteraction err
Right res -> res
where
x =
updateGameIncrTurn m
Expand Down Expand Up @@ -775,6 +772,25 @@ updateModel (DeckGo deck) m@(GameModel' GameModel {..}) =
noEff $ DeckModel' $ DeckModel deck m playingPlayer t shared
where
t = Board.toPart board playingPlayer & Board.team
-- Go to 'LootView'
updateModel (LootGo model) _ =
noEff $ LootModel' model
-- Schedule leaving 'GameView', to go to 'LootView'
updateModel _ m@(GameModel' gm@GameModel {board, level, playingPlayer, turn})
| (Turn.next turn & Turn.toNat) > Constants.nbTurns =
case Campaign.succ level of
Nothing -> noEff m -- TODO, go to global victory view
Just _ ->
delayActions m [(toSecs 1, LootGo $ Model.endGame gm outcome)]
where
part = Board.toPart board playingPlayer
(score, enemy) =
(Board.score part, Board.toPart board (otherPlayerSpot playingPlayer) & Board.score)
outcome :: Campaign.Outcome =
case compare score enemy of
LT -> Campaign.Loss
EQ -> Campaign.Draw
GT -> Campaign.Win
-- Leave 'GameView' (maybe)
updateModel (GameAction' GameExecuteCmd) (GameModel' gm@GameModel {board, shared, playingPlayer})
| SharedModel.getCmd shared & isJust =
Expand All @@ -784,7 +800,7 @@ updateModel (GameAction' GameExecuteCmd) (GameModel' gm@GameModel {board, shared
let errMsg = "Unrecognized command: " ++ show cmdStr
in noEff $ GameModel' $ gm {interaction = ShowErrorInteraction $ Text.pack errMsg}
Just (Command.EndGame outcome) ->
noEff $ Model.endGame gm outcome
noEff $ LootModel' $ Model.endGame gm outcome
Just (Command.Gimme cid) ->
withBoard $ Board.addToHand board playingPlayer cid
Just (Command.GimmeMana) ->
Expand Down
4 changes: 2 additions & 2 deletions docs/Model.html
Expand Up @@ -112,7 +112,7 @@
<li class="src short">
<a href="#v:gameToDeck">gameToDeck</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; [<a href="Card.html#t:ID" title="Card">ID</a>]</li>
<li class="src short">
<a href="#v:endGame">endGame</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; <a href="Campaign.html#t:Outcome" title="Campaign">Outcome</a> -&gt; <a href="Model.html#t:Model" title="Model">Model</a>
<a href="#v:endGame">endGame</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; <a href="Campaign.html#t:Outcome" title="Campaign">Outcome</a> -&gt; <a href="Model.html#t:LootModel" title="Model">LootModel</a>
</li>
<li class="src short">
<a href="#v:unsafeLootModel">unsafeLootModel</a> :: <a href="Model.html#t:WelcomeModel" title="Model">WelcomeModel</a> -&gt; <a href="Model.html#t:Model" title="Model">Model</a>
Expand Down Expand Up @@ -819,7 +819,7 @@ <h1>Documentation</h1>
</div>
<div class="top"><p class="src"><a id="v:gameToBuild" class="def">gameToBuild</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; <a href="Model.html#t:BuildModel" title="Model">BuildModel</a> <a href="#v:gameToBuild" class="selflink">#</a></p></div>
<div class="top"><p class="src"><a id="v:gameToDeck" class="def">gameToDeck</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; [<a href="Card.html#t:ID" title="Card">ID</a>] <a href="#v:gameToDeck" class="selflink">#</a></p></div>
<div class="top"><p class="src"><a id="v:endGame" class="def">endGame</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; <a href="Campaign.html#t:Outcome" title="Campaign">Outcome</a> -&gt; <a href="Model.html#t:Model" title="Model">Model</a> <a href="#v:endGame" class="selflink">#</a></p></div>
<div class="top"><p class="src"><a id="v:endGame" class="def">endGame</a> :: <a href="Model.html#t:GameModel" title="Model">GameModel</a> -&gt; <a href="Campaign.html#t:Outcome" title="Campaign">Outcome</a> -&gt; <a href="Model.html#t:LootModel" title="Model">LootModel</a> <a href="#v:endGame" class="selflink">#</a></p></div>
<div class="top">
<p class="src"><a id="v:unsafeLootModel" class="def">unsafeLootModel</a> :: <a href="Model.html#t:WelcomeModel" title="Model">WelcomeModel</a> -&gt; <a href="Model.html#t:Model" title="Model">Model</a> <a href="#v:unsafeLootModel" class="selflink">#</a></p>
<div class="doc"><p>Function for debugging only. Used to
Expand Down
6 changes: 4 additions & 2 deletions docs/Update.html
Expand Up @@ -118,7 +118,7 @@
</li>
<li>| <a href="#v:LootAction-39-">LootAction'</a> <a href="Update.html#t:LootAction" title="Update">LootAction</a>
</li>
<li>| <a href="#v:LootGo">LootGo</a>
<li>| <a href="#v:LootGo">LootGo</a> <a href="Model.html#t:LootModel" title="Model">LootModel</a>
</li>
<li>| <a href="#v:NoOp">NoOp</a>
</li>
Expand Down Expand Up @@ -618,7 +618,9 @@ <h1>Documentation</h1>
<td class="doc"><p>Actions internal to <code>LootView</code></p></td>
</tr>
<tr>
<td class="src"><a id="v:LootGo" class="def">LootGo</a></td>
<td class="src">
<a id="v:LootGo" class="def">LootGo</a> <a href="Model.html#t:LootModel" title="Model">LootModel</a>
</td>
<td class="doc"><p>Go to <code>LootView</code></p></td>
</tr>
<tr>
Expand Down

0 comments on commit 0e4e597

Please sign in to comment.