SHOW:
|
|
- or go back to the newest paste.
1 | module Main | |
2 | ( main | |
3 | ) where | |
4 | ||
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 |
10 | + | if S.size guessed <= 8 |
11 | - | if isAlpha c |
11 | + | |
12 | c <- getChar | |
13 | - | let newGuessed = (S.insert c guessed) |
13 | + | if isAlpha c |
14 | - | putStrLn $ map (\c -> if c `S.member` newGuessed then c else '_') word |
14 | + | then do |
15 | - | putStrLn $ "Guessed: " ++ S.toList newGuessed |
15 | + | let newGuessed = (S.insert c guessed) |
16 | - | putStrLn $ take 80 $ repeat '-' |
16 | + | putStrLn $ map (\c -> if c `S.member` newGuessed then c else '_') word |
17 | - | putStrLn "" |
17 | + | putStrLn $ "Guessed: " ++ S.toList newGuessed |
18 | putStrLn $ take 80 $ repeat '-' | |
19 | - | if (S.fromList word) `S.isSubsetOf` newGuessed |
19 | + | putStrLn "" |
20 | - | then putStrLn "You won!" >> return () |
20 | + | |
21 | - | else hangman word newGuessed |
21 | + | if (S.fromList word) `S.isSubsetOf` newGuessed |
22 | - | else hangman word guessed |
22 | + | then putStrLn "You won!" |
23 | else hangman word newGuessed | |
24 | else hangman word guessed | |
25 | else putStrLn $ "You lost, you idiot. The word was: " ++ word | |
26 | ||
27 | main :: IO () | |
28 | main = do | |
29 | hangman "hello" S.empty |