-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rkt
More file actions
263 lines (226 loc) · 9.5 KB
/
main.rkt
File metadata and controls
263 lines (226 loc) · 9.5 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#lang racket/gui
(require "./screens/login.rkt")
(require "./frame.rkt")
(require "./libs/game.rkt")
(require "./libs/pdata.rkt")
(define bg (make-object bitmap% "img/bg.jpg"))
(define bg-howto (make-object bitmap% "img/HOWTO.jpg"))
(define bg-scores (make-object bitmap% "img/scores.jpg"))
(struct gpt (x y))
(struct gbutton (pt-1 pt-2 img img-pt))
(define coordinates (build-list 10 (lambda (x) (+ (* x 10) 100))))
; (struct gbutton (pt-1 pt-2 img img-pt cb))
;-- defines menu-canvas where it connects to all other screens
(define menu-canvas%
(class canvas%
(inherit refresh)
(define sel-button 'none)
(define sel-button-pt 'none)
(define scores (make-object bitmap% "img/score.jpg"))
(define play (make-object bitmap% "img/play.jpg"))
(define howto (make-object bitmap% "img/howto.jpg"))
(define buttons
(list
(gbutton (gpt 60 442) (gpt 222 529) scores (gpt 38 420))
(gbutton (gpt 362 339) (gpt 545 409) play (gpt 362 339))
(gbutton (gpt 710 85) (gpt 883 163) howto (gpt 702 74))))
(define (handle-mouse-motion x y)
(let loop ([bl buttons])
(if (empty? bl)
(refresh)
(let* ([b (car bl)]
[pt-1 (gbutton-pt-1 b)]
[pt-1-x (gpt-x pt-1)]
[pt-1-y (gpt-y pt-1)]
[pt-2 (gbutton-pt-2 b)]
[pt-2-x (gpt-x pt-2)]
[pt-2-y (gpt-y pt-2)])
(if (and (> x pt-1-x) (> y pt-1-y) (< x pt-2-x) (< y pt-2-y))
(begin
(set! sel-button (gbutton-img b))
(set! sel-button-pt (gbutton-img-pt b))
(refresh))
(begin
(set! sel-button 'none)
(set! sel-button-pt 'none)
(loop (cdr bl))))))))
(define (action x y)
(cond
([and (and (> x (gpt-x (gbutton-pt-1 (first buttons))))
(< x (gpt-x (gbutton-pt-2 (first buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (first buttons))))
(< y (gpt-y (gbutton-pt-2 (first buttons)))))] (set-canvas 1))
([and (and (> x (gpt-x (gbutton-pt-1 (second buttons))))
(< x (gpt-x (gbutton-pt-2 (second buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (second buttons))))
(< y (gpt-y (gbutton-pt-2 (second buttons)))))] (set-canvas 2))
([and (and (> x (gpt-x (gbutton-pt-1 (third buttons))))
(< x (gpt-x (gbutton-pt-2 (third buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (third buttons))))
(< y (gpt-y (gbutton-pt-2 (third buttons)))))] (set-canvas 3))
))
(define/override (on-event evt)
(let ([evt-type (send evt get-event-type)]
[evt-x (send evt get-x)]
[evt-y (send evt get-y)])
(cond
[(eq? evt-type 'motion)
(handle-mouse-motion evt-x evt-y)]
[(eq? evt-type 'left-up)
(begin
(action evt-x evt-y)
(printf "Click % (~a, ~a)~n" evt-x evt-y))])))
(define/private (paint-game self dc)
(send dc draw-bitmap bg 0 0)
(send dc set-pen "blue" 1 'solid) (send dc set-brush "white" 'transparent) (cond
[(not (eq? sel-button 'none))
(let ([img-x (gpt-x sel-button-pt)]
[img-y (gpt-y sel-button-pt)])
(send dc draw-bitmap sel-button img-x img-y))]))
(super-new (paint-callback (lambda (c dc) (paint-game c dc))))))
;-- howto canvas begins
(define howto-canvas%
(class canvas%
(inherit refresh)
(define sel-button 'none)
(define sel-button-pt 'none)
(define manual (make-object bitmap% "img/MAN_HOVER.jpg"))
(define back (make-object bitmap% "img/HBACK_HOVER.jpg"))
(define buttons
(list
(gbutton (gpt 164 407) (gpt 231 482) manual (gpt 148 392))
(gbutton (gpt 731 399) (gpt 822 471) back (gpt 713 380))))
(define (handle-mouse-motion x y)
(let loop ([bl buttons])
(if (empty? bl)
(refresh)
(let* ([b (car bl)]
[pt-1 (gbutton-pt-1 b)]
[pt-1-x (gpt-x pt-1)]
[pt-1-y (gpt-y pt-1)]
[pt-2 (gbutton-pt-2 b)]
[pt-2-x (gpt-x pt-2)]
[pt-2-y (gpt-y pt-2)])
(if (and (> x pt-1-x) (> y pt-1-y) (< x pt-2-x) (< y pt-2-y))
(begin
(set! sel-button (gbutton-img b))
(set! sel-button-pt (gbutton-img-pt b))
(refresh))
(begin
(set! sel-button 'none)
(set! sel-button-pt 'none)
(loop (cdr bl))))))))
(define (action x y)
(cond
([and (and (> x (gpt-x (gbutton-pt-1 (first buttons))))
(< x (gpt-x (gbutton-pt-2 (first buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (first buttons))))
(< y (gpt-y (gbutton-pt-2 (first buttons)))))] (system "mupdf ./pdf/man.pdf"))
([and (and (> x (gpt-x (gbutton-pt-1 (second buttons))))
(< x (gpt-x (gbutton-pt-2 (second buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (second buttons))))
(< y (gpt-y (gbutton-pt-2 (second buttons)))))] (set-canvas 4))))
(define/override (on-event evt)
(let ([evt-type (send evt get-event-type)]
[evt-x (send evt get-x)]
[evt-y (send evt get-y)])
(cond
[(eq? evt-type 'motion)
(handle-mouse-motion evt-x evt-y)]
[(eq? evt-type 'left-up)
(begin
(action evt-x evt-y)
(printf "Click % (~a, ~a)~n" evt-x evt-y))])))
(define/private (paint-game self dc)
(send dc draw-bitmap bg-howto 0 0)
(send dc set-pen "blue" 1 'solid) (send dc set-brush "white" 'transparent) (cond
[(not (eq? sel-button 'none))
(let ([img-x (gpt-x sel-button-pt)]
[img-y (gpt-y sel-button-pt)])
(send dc draw-bitmap sel-button img-x img-y))]))
(super-new (paint-callback (lambda (c dc) (paint-game c dc))))))
;--score canvas begins here
(define score-canvas%
(class canvas%
(inherit refresh)
(define sel-button 'none)
(define sel-button-pt 'none)
(define back (make-object bitmap% "img/SBACK_HOVER.jpg"))
(define buttons
(list
(gbutton (gpt 731 399) (gpt 822 471) back (gpt 713 380))
(gbutton (gpt 731 399) (gpt 822 471) back (gpt 713 380))))
(define (handle-mouse-motion x y)
(let loop ([bl buttons])
(if (empty? bl)
(refresh)
(let* ([b (car bl)]
[pt-1 (gbutton-pt-1 b)]
[pt-1-x (gpt-x pt-1)]
[pt-1-y (gpt-y pt-1)]
[pt-2 (gbutton-pt-2 b)]
[pt-2-x (gpt-x pt-2)]
[pt-2-y (gpt-y pt-2)])
(if (and (> x pt-1-x) (> y pt-1-y) (< x pt-2-x) (< y pt-2-y))
(begin
(set! sel-button (gbutton-img b))
(set! sel-button-pt (gbutton-img-pt b))
(refresh))
(begin
(set! sel-button 'none)
(set! sel-button-pt 'none)
(loop (cdr bl))))))))
(define (action x y)
(cond
([and (and (> x (gpt-x (gbutton-pt-1 (second buttons))))
(< x (gpt-x (gbutton-pt-2 (second buttons)))))
(and (> y (gpt-y (gbutton-pt-1 (second buttons))))
(< y (gpt-y (gbutton-pt-2 (second buttons)))))] (set-canvas 4))))
(define/override (on-event evt)
(let ([evt-type (send evt get-event-type)]
[evt-x (send evt get-x)]
[evt-y (send evt get-y)])
(cond
[(eq? evt-type 'motion)
(handle-mouse-motion evt-x evt-y)]
[(eq? evt-type 'left-up)
(begin
(action evt-x evt-y)
(printf "Click % (~a, ~a)~n" evt-x evt-y))])))
(define (paint-high dc c)
(if (< c (length (getHigh)))
(begin
(send dc draw-text (list-ref (getHigh) c) 250 (+ 150 (* c 11)))
(paint-high dc (+ c 1))
)
(void)
)
)
(define/private (paint-game self dc)
(send dc draw-bitmap bg-scores 0 0)
(paint-high dc 0)
(send dc set-pen "blue" 1 'solid) (send dc set-brush "white" 'transparent) (cond
[(not (eq? sel-button 'none))
(let ([img-x (gpt-x sel-button-pt)]
[img-y (gpt-y sel-button-pt)])
(send dc draw-bitmap sel-button img-x img-y))]))
(super-new (paint-callback (lambda (c dc) (paint-game c dc))))))
(define main-canvas (new menu-canvas% (parent mainframe)))
;-- changes canvas according to button number
(define (set-canvas opt)
(case opt
((1) (begin (new score-canvas% (parent mainframe))
(send mainframe delete-child (car (send mainframe get-children)))
(send mainframe show #t)))
((2) (begin (new loginf-canvas% (parent mainframe))
(send mainframe delete-child (car (send mainframe get-children)))
(send mainframe show #t)))
((3) (begin (new howto-canvas% (parent mainframe))
(send mainframe delete-child (car (send mainframe get-children)))
(send mainframe show #t)))
((4) (begin (new menu-canvas% (parent mainframe))
(send mainframe delete-child (car (send mainframe get-children)))
(send mainframe show #t)))
)
)
(send mainframe show #t)