-
Notifications
You must be signed in to change notification settings - Fork 0
/
Draw.hs
43 lines (25 loc) · 879 Bytes
/
Draw.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module Draw(
Draw(), draw, write, writePoint
) where
import UI.HSCurses.Curses(mvWAddStr, stdScr, refresh)
import Primitives
write :: String -> Coord -> IO ()
write str (Coord x y) = mvWAddStr stdScr x y str
writePoint :: Coord -> IO ()
writePoint co = write "*" co
writePoints :: [Coord] -> IO ()
writePoints cords = mapM_ writePoint cords
class Draw a where
draw :: a -> IO ()
instance Draw Coord where
draw co = write "*" co
instance Draw Stage where
draw stage = writePoints (stageBorders stage)
instance Draw GameState where
draw GameState{stage=stage, snake=snake, apple=apple, score=score} = do
draw stage >> draw snake >> draw apple
write ("Score - " ++ show score) score_xy
where
score_xy = Coord 0 (height stage + 2)
instance Draw Snake where
draw Snake{cords=cords} = writePoints cords