--- /dev/null
+module Galgje\r
+\r
+import StdEnv, SimpleFileIO, RandomGetallen\r
+\r
+lexicon_file = "lexicon.txt"\r
+\r
+// From the slides\r
+skip_nl :: String -> String\r
+skip_nl str = if (size str > 0 && str.[size str-1] == '\n') (str%(0,size str-2)) str\r
+\r
+// From a String and a List of guesses (Chars), return a String that shows dots for letters that were not guessed yet\r
+stripUnknown :: String [Char] -> String\r
+stripUnknown s g = toString [if (isMember c g) c '.' \\ c <- (fromString s)]\r
+\r
+// Get a random word from the lexicon file\r
+randomWord :: *env -> (Maybe String, *env) | FileSystem env\r
+randomWord env\r
+# (ss,env) = readLines lexicon_file env\r
+| ss == Nothing = (Nothing, env)\r
+# (seed,env) = getNewRandomSeed env\r
+| otherwise = (Just (skip_nl ((shuffle (fromJust ss) seed)!!0)), env)\r
+\r
+// word, guesses, stdio -> (win, new guesses, stdio)\r
+round :: String [Char] *File -> (Bool, [Char], *File)\r
+round w g io\r
+# io = io <<< stripUnknown w g <<< '\n'\r
+| stripUnknown w g == w = (True, g, io)\r
+# io = io <<< "Guess: "\r
+# (ok,g`,io) = freadc io\r
+# (_,io) = freadline io // to read until the next \n\r
+| not ok = abort "Couldn't get guessed letter"\r
+| otherwise = round w [g`:g] io\r
+\r
+Start :: *World -> *World\r
+Start world\r
+# (word,world) = randomWord world\r
+| word == Nothing = abort "Couldn't get random word"\r
+# word = fromJust word\r
+# (io,world) = stdio world\r
+# (win,g,io) = round word [] io\r
+# io = if win (io <<< "You win!\n") io\r
+# (ok,world) = fclose io world\r
+| not ok = abort "Couldn't close stdio"\r
+| otherwise = world\r