minor improvements to console output
This commit is contained in:
parent
fa8721ddd5
commit
2810c0ea4b
18
src/Test.hs
18
src/Test.hs
|
|
@ -19,6 +19,7 @@ import System.Random
|
|||
import System.Random.Shuffle
|
||||
|
||||
import qualified Data.IntMap as IM
|
||||
import qualified Data.Map as M
|
||||
|
||||
f1 = Faction "Jesters" Blue
|
||||
l1 = Lord "Prince Henry XXX" "" (QuestBonus [Skullduggery, Commerce] 4)
|
||||
|
|
@ -88,6 +89,10 @@ b5 = Building { _buildingCost = 4
|
|||
clearScreen :: IO ()
|
||||
clearScreen = putStr "\o033[H\o033[2J" >> hFlush stdout
|
||||
|
||||
showTavern :: M.Map Resource Int -> String
|
||||
showTavern = intercalate ", " . map showResource . M.toAscList
|
||||
where showResource (r, n) = show n ++ " " ++ show r
|
||||
|
||||
printWaterdeep :: WaterdeepState -> IO ()
|
||||
printWaterdeep w = do
|
||||
let ps = map snd $ w ^. gamePlayers . to IM.toAscList
|
||||
|
|
@ -113,7 +118,7 @@ printWaterdeep w = do
|
|||
forM_ ps $ \p -> do
|
||||
putStrLn ((p ^. playerName) ++ "'s State:")
|
||||
putStrLn (" Score: " ++ show (p ^. playerScore))
|
||||
putStrLn (" Tavern: " ++ show (p ^. playerTavern))
|
||||
putStrLn (" Tavern: " ++ (p ^. playerTavern . to showTavern))
|
||||
putStrLn (" Color: " ++ show (p ^. playerFaction . factionColor))
|
||||
putStrLn (" Lord: " ++ (p ^. playerLord . lordName))
|
||||
putStrLn (" Faction: " ++ (p ^. playerFaction . factionName))
|
||||
|
|
@ -130,9 +135,9 @@ menuPrompt prm@(SolicitChoice w p t cs) = do
|
|||
let menuLine n t = putStrLn (show n ++ ") " ++ t)
|
||||
let blankLine = putStrLn ""
|
||||
|
||||
let redo why = do
|
||||
let redo = do
|
||||
printWaterdeep w
|
||||
putStrLn ("ERROR: " ++ why)
|
||||
putStrLn ("ERROR: Expected a number between 1 and " ++ show menuSize ++ ".")
|
||||
blankLine
|
||||
menuPrompt prm
|
||||
|
||||
|
|
@ -144,10 +149,9 @@ menuPrompt prm@(SolicitChoice w p t cs) = do
|
|||
response <- getLine
|
||||
|
||||
case reads response of
|
||||
(ix,""):_ -> if ix >= 1 && ix <= menuSize
|
||||
then blankLine >> return (snd $ cs !! (ix-1))
|
||||
else redo "Invalid choice."
|
||||
_ -> redo "Expected a number."
|
||||
(ix,""):_ | ix >= 1 && ix <= menuSize ->
|
||||
blankLine >> return (snd $ cs !! (ix-1))
|
||||
_ -> redo
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
|
|
|
|||
Loading…
Reference in New Issue