Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. check :: String -> String -> Char -> (Bool, String)
  2. check word display c
  3.   = (c `elem` word, [if x==c
  4.           then c
  5.           else y | (x,y) <- zip word display])
  6.          
  7. turn :: String -> String -> Int -> IO ()
  8. turn word display n =
  9.   do if n==0
  10.        then putStrLn "You lose"
  11.        else if word==display
  12.               then putStrLn "You win!"
  13.               else mkguess word display n
  14.              
  15. mkguess word display n =
  16.   do putStrLn (display ++ "  " ++ take n (repeat '*'))
  17.      putStr "  Enter your guess: "
  18.      q <- getLine
  19.      let (correct, display') = check word display (q!!0)
  20.     let n' = if correct then n else n-1
  21.      turn word display' n'
  22.      
  23.    
  24. starman :: String -> Int -> IO ()
  25. starman word n = turn word ['-' | x <- word] n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement