1 implementation module Sokoban
8 Start :: *World -> (String, *World)
10 # (s, w) = parse "../sokobanzip/screens/screen.1" w
11 = ("\n" +++ toString s, w)
13 instance toString SokobanPuzzle where
14 toString (Sokoban []) = ""
15 toString (Sokoban [[]:rows]) = "\n" +++ toString (Sokoban rows)
16 toString (Sokoban [[x:xs]:rows]) =
17 toString x +++ toString (Sokoban [xs:rows])
19 instance toString SokobanTile where
26 parse :: String *World -> (SokobanPuzzle, *World)
28 # (ok, f, w) = fopen fp FReadText w
29 | not ok = abort ("Couldn't open file: '" +++ fp +++ "'")
30 # (contents, f) = readEntireFile f
31 | isEmpty contents = abort "File is empty or unreadable"
32 # (ok, w) = fclose f w
33 | not ok = abort "Couldn't close file"
34 = (Sokoban (parseRows contents), w)
36 parseRows :: [Char] -> [[SokobanTile]]
37 parseRows cs = case parseRow cs of
39 (x, rest) = [x:parseRows rest]
41 parseRow :: [Char] -> ([SokobanTile], [Char])
42 parseRow [] = ([], [])
43 parseRow ['\n':xs] = ([], xs)
45 # (rest, xs) = parseRow xs
52 _ = abort ("Unknown char: '" +++ toString x +++ "'")
53 = ([current:rest], xs)
55 readEntireFile :: *File -> *([Char], *File)
57 # (b, c, f) = freadc f
59 # (cs, f) = readEntireFile f