Created
September 26, 2017 20:05
-
-
Save fstiffo/eafd2154fa56fd4ba3cb88bcc0857b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Random | |
wordlist = ["awkward","bagpipes","banjo","bungler","croquet","crypt", | |
"dwarves","fervid","fishhook","fjord","gazebo","gypsy", | |
"haiku","haphazard","hyphen","ivory","jazzy","jiffy", | |
"jinx","jukebox","kayak","kiosk","klutz","memento", | |
"mystify","numbskull","ostracize","oxygen","pajama", | |
"phlegm","pixel","polka","quad","quip","rhythmic","rogue", | |
"sphinx","squawk","swivel","toady","twelfth","unzip","waxy", | |
"wildebeest","yacht","zealous","zigzag","zippy","zombie"] | |
check :: String -> String -> Char -> (Bool, String) | |
check word display c = | |
(c `elem` word, [if x == c | |
then c | |
else y | (x, y) <- zip word display]) | |
turn :: String -> String -> Int -> IO () | |
turn word display n = | |
do if n == 0 | |
then putStrLn "You lose" | |
else if word == display | |
then putStrLn "You win!" | |
else mkguess word display n | |
mkguess :: String -> String -> Int -> IO () | |
mkguess word display n = | |
do putStrLn $ display ++ " " ++ take n (repeat '*') | |
putStr " Enter your guess: " | |
q <- getLine | |
let (correct, display') = check word display (q !! 0) | |
let n' = if correct then n else n - 1 | |
turn word display' n' | |
starman :: Int -> IO () | |
starman n = do | |
index <- randomRIO (0, length wordlist) | |
let word = wordlist !! index | |
turn word ['-' | x <- word] n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment