forked from janestreet/learn-ocaml-workshop
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscaffold.ml
90 lines (76 loc) · 1.33 KB
/
scaffold.ml
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
open Base
module Position = struct
type t =
{ x : int
; y : int
} [@@deriving fields, sexp]
let create = Fields.create
end
module Image = struct
type t =
| Frog_up
| Frog_down
| Frog_left
| Frog_right
| Car1_left
| Car1_right
| Car2_left
| Car2_right
| Car3_left
| Car3_right
| Log1
| Log2
| Log3
| Confetti
| Skull_and_crossbones
[@@deriving sexp, variants]
end
module Display_list = struct
module Display_command = struct
type nonrec t = Image.t * Position.t [@@deriving sexp]
end
type t = Display_command.t list [@@deriving sexp]
end
module Key = struct
type t =
| Arrow_up
| Arrow_down
| Arrow_left
| Arrow_right
end
module Event = struct
type t =
| Tick
| Keypress of Key.t
end
module Board = struct
(** Every row of the game board is one of these three kinds. *)
module Row = struct
type t =
| Safe_strip
| Road
| River
end
let num_cols = 10
(** The first and last rows are guaranteed to be [Safe_strip]s. *)
let rows =
let open Row in
[ Safe_strip
; River
; River
; River
; River
; River
; Safe_strip
; Road
; Road
; Road
; Road
; Safe_strip
]
|> List.rev
;;
end
let console_log s =
Js_of_ocaml.Firebug.console##log s
;;