SHOW:
|
|
- or go back to the newest paste.
1 | module Main | |
2 | ( main | |
3 | ) where | |
4 | ||
5 | - | import Data.Char |
5 | + | import Data.Char |
6 | import qualified Data.Set as S | |
7 | ||
8 | hangman :: String -> S.Set Char -> IO () | |
9 | hangman word guessed = do | |
10 | c <- getChar | |
11 | if isAlpha c | |
12 | then do | |
13 | let newGuessed = (S.insert c guessed) | |
14 | putStrLn $ map (\c -> if c `S.member` newGuessed then c else '_') word | |
15 | putStrLn $ "Guessed: " ++ S.toList newGuessed | |
16 | putStrLn $ take 80 $ repeat '-' | |
17 | putStrLn "" | |
18 | ||
19 | if (S.fromList word) `S.isSubsetOf` newGuessed | |
20 | then putStrLn "You won!" >> return () | |
21 | else hangman word newGuessed | |
22 | else hangman word guessed | |
23 | ||
24 | main :: IO () | |
25 | main = do | |
26 | hangman "hello" S.empty |