Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
module Main(main) where import System.IO import Char hangman :: IO () hangman = do clearScreen writeAt (1,1) "Enter a word: " word <- getWordEchoDashes game word [] game :: String -> String -> IO () game word guess = do c <- getChar let reveal = map (dash (c:guess)) word putStrLn ([c] ++ " " ++ reveal) if elem '-' reveal then game word (c:guess) else newgame dash :: String -> Char -> Char dash guess w | elem w guess = w | otherwise = '-' newgame = do putStr "Start a new game? (y/n)" c <- getChar if toUpper(c) == 'Y' then hangman else return () main = do hSetEcho stdin False hSetBuffering stdin NoBuffering hSetBuffering stdout NoBuffering hangman getWordEchoDashes :: IO String getWordEchoDashes = do c <- getChar if c == '\n' then do putChar '\n' return "" else do putChar '-' w <- getWordEchoDashes return (c:w) cls :: String cls = "\ESC[2J" highlight :: String -> String highlight s = "\ESC[7m"++s++"\ESC[0m" goto :: Int -> Int -> String goto x y = "\ESC[" ++ show y ++ ";" ++ show x ++ "H" home :: String home = goto 1 1 at :: (Int,Int) -> String -> String at (x,y) s = goto x y ++ s clearScreen :: IO () clearScreen = putStr cls writeAt :: (Int,Int) -> String -> IO () writeAt pos s = putStr (at pos s)