diff options
author | Frederick Yin <fkfd@fkfd.me> | 2023-01-05 21:27:27 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2023-01-05 21:27:27 +0800 |
commit | acd9a60a2232cea6efceee64d1c442d19c52235d (patch) | |
tree | 19dd6e3d776dcea0875bd3bb8b7ac8fb1a25b610 /Game.hs | |
parent | 79fba8934969b660298e3a2c875a49d500313d1a (diff) |
prompt returns IO (Maybe Card), turn is skippable
Diffstat (limited to 'Game.hs')
-rw-r--r-- | Game.hs | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -17,11 +17,11 @@ data Game = Game { players :: [Player] , discardPile :: [Card] } -prompt :: Game -> IO Card +prompt :: Game -> IO (Maybe Card) prompt game@(Game plyrs pidx att _ _ _) = do let player = plyrs !! pidx let cards = P.cards player - putStrLn $ P.name player ++ "'s turn" + putStrLn $ P.name player ++ "'s turn (input 0 to skip turn and draw card)" putStrLn $ P.showCards player cardIdxStr <- getLine if any (== False) $ map isDigit cardIdxStr @@ -30,8 +30,12 @@ prompt game@(Game plyrs pidx att _ _ _) = do prompt game else do let cardIdx = read cardIdxStr - 1 - if cardIdx < 0 || cardIdx >= length cards + if cardIdx == -1 then do - putStrLn "This card does not exist, try again" - prompt game - else return $ cards !! cardIdx + return Nothing + else do + if cardIdx < 0 || cardIdx >= length cards + then do + putStrLn "This card does not exist, try again" + prompt game + else return $ Just (cards !! cardIdx) |