summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2023-01-05 21:27:27 +0800
committerFrederick Yin <fkfd@fkfd.me>2023-01-05 21:27:27 +0800
commitacd9a60a2232cea6efceee64d1c442d19c52235d (patch)
tree19dd6e3d776dcea0875bd3bb8b7ac8fb1a25b610
parent79fba8934969b660298e3a2c875a49d500313d1a (diff)
prompt returns IO (Maybe Card), turn is skippable
-rw-r--r--Game.hs16
1 files changed, 10 insertions, 6 deletions
diff --git a/Game.hs b/Game.hs
index 27d7804..77b2e92 100644
--- a/Game.hs
+++ b/Game.hs
@@ -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)