forked from janestreet/learn-ocaml-workshop
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfrogger.ml
69 lines (57 loc) · 1.94 KB
/
frogger.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
open Base
open Scaffold
[@@@warning "-27-32"]
module Frog = struct
type t =
{ position : Position.t
} [@@deriving fields]
let create = Fields.create
end
module World = struct
type t =
{ frog : Frog.t
} [@@deriving fields]
let create = Fields.create
end
let create_frog () =
failwith
"Figure out how to initialize the [Frog.t] at the beginning of the game. \
Call [Frog.create] with some arguments."
;;
let create () =
failwith
"Call [World.create] and [create_frog] to construct the initial state \
of the game. Try using [Random.int] -- variety is the spice of life!"
;;
let tick (world : World.t) =
failwith
"This function will end up getting called every timestep, which happens to \
be set to 1 second for this game in the scaffold (so you can easily see \
what's going on). For the first step (just moving the frog/camel around), \
you can just return [world] here. Later you'll want do interesting things \
like move all the cars and logs, detect collisions and figure out if the \
player has died or won. "
;;
let handle_input (world : World.t) key =
failwith
"This function will end up getting called whenever the player presses one of \
the four arrow keys. What should the new state of the world be? Create and \
return it based on the current state of the world (the [world] argument), \
and the key that was pressed ([key]). Use either [World.create] or the \
record update syntax:
{ world with frog = Frog.create ... }
"
;;
let draw (world : World.t) =
failwith
"Return a list with a single item: a tuple consisting of one of the choices \
in [Images.t] in [scaffold.mli]; and the current position of the [Frog]."
;;
let handle_event world event =
failwith
"This function should probably be just 3 lines long: [match event with ...]"
;;
let finished world =
failwith
"This can probably just return [false] in the beginning."
;;