import Interactive import Char import System.IO hangman = clearScreen $ readAt (1,1) "Enter a word: " $ \w -> let echo = ['-' | _ <- w] in writeStr (echo ++ "\n") $ game w [] game word guess = readChar $ \c -> let dash w | w `elem` (c:guess) = w | otherwise = '-' reveal = [dash w | w <- word] in writeStr([c] ++ " " ++ reveal ++ "\n") $ if '-' `elem` reveal then game word (c:guess) else newgame newgame = writeStr "Start a new game? (y/n)" $ readChar $ \c -> if toUpper(c) == 'Y' then hangman else end main = do hSetEcho stdin False hSetBuffering stdin NoBuffering hSetBuffering stdout NoBuffering interact hangman