-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathworld-template.rkt
71 lines (50 loc) · 1.1 KB
/
world-template.rkt
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
#lang htdp/isl+
(require 2htdp/image)
(require 2htdp/universe)
(require test-engine/racket-tests)
; ### Constants
(define BACKGROUND-WIDTH 300)
(define BACKGROUND-HEIGHT 200)
(define BACKGROUND (empty-scene BACKGROUND-WIDTH BACKGROUND-HEIGHT))
; ### Data Definitions
; WorldState is a structure (make-world ...)
; Interpretation:
(define-struct world [...])
; ### Functions
; WorldState -> Image
(define (render-world ws)
BACKGROUND
)
; WorldState KeyEvent -> WorldState
; Handles the key events
(define (on-key-press ws ke)
(cond
[(key=? ke "...") ws]
[else ws]
))
; WorldState -> WorldState
; Handles the ticking of the world
(define (tock ws)
ws
)
; WorldState -> Boolean
; Predicate to define when the world comes to an end
(define (over? ws)
#false
)
; WorldState -> Image
; Renders the last image after the world ended
(define (render-final ws)
(render-world ws)
)
(define (main ws)
(big-bang
ws
[to-draw render-world]
[on-key on-key-press]
[on-tick tock]
[stop-when over? render-final]
[check-with world?]
))
(test)
(main (make-world ...))