From d034b9c9273a7f3ff91554c4b605dd488207caa1 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Mon, 9 Jan 2023 11:08:02 +0800 Subject: Display player's cards in color --- Player.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Player.hs') diff --git a/Player.hs b/Player.hs index 6dab74c..6f2804d 100644 --- a/Player.hs +++ b/Player.hs @@ -3,6 +3,7 @@ module Player where import qualified Data.List as L import Card (Card) import qualified Card as C +import qualified Color data Player = Player { name :: String , penalty :: Integer @@ -24,6 +25,13 @@ draw :: Player -> [Card] -> Player draw (Player n p cs) cs' = Player n p $ L.sort (cs' ++ cs) -- | Show player's cards, e.g. "1. Spade 2" -showCards :: Player -> String -showCards (Player _ _ cs) = - unlines $ zipWith (\i c -> (show i) ++ ". " ++ C.showCard c) [1..] cs +showCards :: Player -> Card -> String +showCards (Player _ _ cs) prev = + unlines $ zipWith joinAndColorize [1..] cs + where joinAndColorize n c = + if C.isValid prev c + then if C.isSpecial c + then Color.green $ join n c + else join n c + else Color.red $ join n c + join n c = (show n) ++ ". " ++ (C.showCard c) -- cgit v1.2.3