summaryrefslogtreecommitdiff
path: root/fp2/week1/camil/Galgje.icl
diff options
context:
space:
mode:
Diffstat (limited to 'fp2/week1/camil/Galgje.icl')
-rw-r--r--fp2/week1/camil/Galgje.icl21
1 files changed, 13 insertions, 8 deletions
diff --git a/fp2/week1/camil/Galgje.icl b/fp2/week1/camil/Galgje.icl
index f8dd8f3..4225929 100644
--- a/fp2/week1/camil/Galgje.icl
+++ b/fp2/week1/camil/Galgje.icl
@@ -26,17 +26,20 @@ randomWord env
| otherwise = (Just (skip_nl ((shuffle (fromJust ss) seed)!!0)), env)
// word, guesses, mistakes left, stdio -> (win, new guesses, stdio)
-play :: String [Char] Int *File -> (Bool, [Char], *File)
-play w g n io
+play :: String [Char] Int *File *env -> (Bool, [Char], *File, *env) | FileSystem env
+play w g n io world
# io = io <<< stripUnknown w g <<< '\n'
-| stripUnknown w g == w = (True, g, io)
+| stripUnknown w g == w = (True, g, io, world)
+# (round,world) = readFile ("round-" +++ (toString n) +++ ".txt") world
+| round == Nothing = abort "Couldn't get gallow"
+# io = io <<< (fromJust round)
# io = io <<< "Guess (" <<< toString n <<< "): "
# (ok,g`,io) = freadc io
# (_,io) = freadline io // to read until the next \n
| not ok = abort "Couldn't get guessed letter"
-| isMemberString w g` = play w [g`:g] n io
-| n == 0 = (False, [g`:g], io)
-| otherwise = play w [g`:g] (n-1) io
+| isMemberString w g` = play w [g`:g] n io world
+| n == 0 = (False, [g`:g], io, world)
+| otherwise = play w [g`:g] (n-1) io world
Start :: *World -> *World
Start world
@@ -44,8 +47,10 @@ Start world
| word == Nothing = abort "Couldn't get random word"
# word = fromJust word
# (io,world) = stdio world
-# (win,g,io) = play word [] 5 io
-# io = if win (io <<< "You win!\n") (io <<< "You lose!\n")
+# (win,g,io,world) = play word [] 5 io world
+# (lost,world) = readFile "round-lost.txt" world
+| lost == Nothing = abort "Couldn't get gallow"
+# io = if win (io <<< "You win!\n") (io <<< "You lose!\n" <<< fromJust lost)
# (ok,world) = fclose io world
| not ok = abort "Couldn't close stdio"
| otherwise = world