diff options
Diffstat (limited to 'Game.hs')
-rw-r--r-- | Game.hs | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -1,9 +1,9 @@ module Game where import Data.Char (isDigit) -import Control.Monad (when) +import Control.Monad (mapM_) import System.Random (RandomGen, newStdGen) -import Player (Player, shed, draw) +import Player (Player(..), shed, draw) import qualified Player as P import Card (Card(..)) import qualified Card as C @@ -44,7 +44,7 @@ beginTurn auto game@(Game plyrs pidx att dir prev stock disc) = do putStrLn $ replicate 80 '-' putStrLn $ P.name player ++ "'s turn (input 0 to skip turn and draw card)" - putStrLn $ P.showCards player prev att + -- putStrLn $ P.showCards player prev att putStrLn $ "Stock: " ++ (show $ length stock) ++ ", Discard: " ++ (show $ length disc) putStrLn $ "Current attack: " ++ show att @@ -58,7 +58,7 @@ beginTurn auto game@(Game plyrs pidx att dir prev stock disc) = do Just card -> shedAndContinue card game if playerIdx game' == pidx -- shedAndContinue does this when player wins - then return game' + then endRound game' else beginTurn auto game' -- | Game state after player draws card(s) and skips turn. @@ -138,3 +138,15 @@ automate game@(Game plyrs pidx att _ prev _ _) = then Nothing else Just (head validCards) where validCards = filter (C.isValid prev att) $ P.cards (plyrs !! pidx) + +-- | Keep penalties and reset game for next round. +endRound :: Game -> IO Game +endRound game@(Game plyrs pidx _ _ _ stock disc) = do + putStrLn $ (P.name $ plyrs !! pidx) ++ " wins this round!" + let plyrs' = P.calcPenalties plyrs + putStrLn "Penalties:" + putStrLn $ P.showPenalties plyrs' + return $ Game plyrs' pidx 1 1 (head stock) (tail stock) disc + +wait :: a -> IO a +wait x = getLine >> return x |