prompt user if game went into overtime when necessary

This commit is contained in:
Jonathan Lamothe 2019-08-29 00:29:30 -04:00
parent 3c8302174b
commit 45427a050e
2 changed files with 22 additions and 5 deletions

View File

@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
module Mtlstats.Events (handleEvent) where
import Control.Monad.Trans.State (gets, modify)
import Data.Char (toUpper)
import Lens.Micro ((^.), (.~))
import Lens.Micro.Extras (view)
import qualified UI.NCurses as C
@ -55,4 +56,14 @@ handleEvent e = gets (view progMode) >>= \case
promptHandler awayScorePrompt e
modify overtimeCheck
return True
| null $ gs ^. overtimeFlag -> do
overtimePrompt e
>>= modify . (progMode.gameStateL.overtimeFlag .~)
return True
| otherwise -> undefined
overtimePrompt :: C.Event -> Action (Maybe Bool)
overtimePrompt (C.EventCharacter c) = case toUpper c of
'Y' -> return (Just True)
'N' -> return (Just False)
_ -> return Nothing

View File

@ -40,10 +40,16 @@ draw s = do
MainMenu -> drawMenu mainMenu
NewSeason -> drawMenu newSeasonMenu
NewGame gs
| null $ gs ^. gameType -> drawMenu gameTypeMenu
| null $ gs ^. otherTeam -> drawPrompt otherTeamPrompt s
| null $ gs ^. homeScore -> drawPrompt homeScorePrompt s
| null $ gs ^. awayScore -> drawPrompt awayScorePrompt s
| otherwise -> undefined
| null $ gs^.gameType -> drawMenu gameTypeMenu
| null $ gs^.otherTeam -> drawPrompt otherTeamPrompt s
| null $ gs^.homeScore -> drawPrompt homeScorePrompt s
| null $ gs^.awayScore -> drawPrompt awayScorePrompt s
| null $ gs^.overtimeFlag -> overtimePrompt
| otherwise -> undefined
C.render
void $ C.setCursorMode cm
overtimePrompt :: C.Update C.CursorMode
overtimePrompt = do
C.drawString "Did the game go into overtime? (Y/N)"
return C.CursorInvisible