refactored so that the chat-noir tests run in drdr
svn: r18770
This commit is contained in:
parent
1621091fc1
commit
dcaa17e860
|
@ -2332,7 +2332,7 @@ and reports the results.
|
|||
This section contains expressions that start
|
||||
the Chat Noir game going.
|
||||
|
||||
First, a function to compute state of the world at the start of a game is defined.
|
||||
First, here is a function to compute state of the world at the start of a game.
|
||||
|
||||
@chunk[<initial-world>
|
||||
(define board-size 11)
|
||||
|
@ -2350,9 +2350,12 @@ First, a function to compute state of the world at the start of a game is define
|
|||
#f
|
||||
#f))]
|
||||
|
||||
Next, the game starts by calling @scheme[big-bang] with the appropriate arguments.
|
||||
Finally, we can define and provide a function to start the game
|
||||
by calling @scheme[big-bang] with the appropriate arguments.
|
||||
|
||||
@chunk[<go>
|
||||
(provide main)
|
||||
(define (main)
|
||||
(void
|
||||
(big-bang (make-initial-world)
|
||||
(on-draw render-world
|
||||
|
@ -2360,4 +2363,4 @@ Next, the game starts by calling @scheme[big-bang] with the appropriate argument
|
|||
(world-height board-size))
|
||||
(on-key change)
|
||||
(on-mouse clack)
|
||||
(name "Chat Noir")))]
|
||||
(name "Chat Noir"))))]
|
||||
|
|
|
@ -15,16 +15,37 @@
|
|||
(define-unit game@
|
||||
(import)
|
||||
(export)
|
||||
(define ns (make-base-namespace))
|
||||
|
||||
(define sub-custodian (make-custodian))
|
||||
(define main-custodian (current-custodian))
|
||||
|
||||
(define (find-windows)
|
||||
(let loop ([cust sub-custodian])
|
||||
(let o-loop ([objs (custodian-managed-list cust main-custodian)])
|
||||
(cond
|
||||
[(null? objs) null]
|
||||
[else
|
||||
(let ([obj (car objs)])
|
||||
(cond
|
||||
[(custodian? obj)
|
||||
(append (loop obj)
|
||||
(o-loop (cdr objs)))]
|
||||
[(eventspace? obj)
|
||||
(append (parameterize ([current-eventspace obj])
|
||||
(get-top-level-windows))
|
||||
(o-loop (cdr objs)))]
|
||||
[else
|
||||
(o-loop (cdr objs))]))]))))
|
||||
|
||||
;; a hack.
|
||||
;; this adds a help button to the world.ss window
|
||||
(thread
|
||||
(λ ()
|
||||
(let loop ([n 0])
|
||||
(when (n . < . 100)
|
||||
(cond
|
||||
[(n . < . 100)
|
||||
(sleep 1/10)
|
||||
(let ([fs (get-top-level-windows)])
|
||||
(let ([fs (find-windows)])
|
||||
(cond
|
||||
[(null? fs)
|
||||
(loop (+ n 1))]
|
||||
|
@ -37,9 +58,16 @@
|
|||
(new button%
|
||||
[parent f]
|
||||
[callback (λ (x y) (show-help))]
|
||||
[label (string-constant help)]))]))))))
|
||||
[label (string-constant help)]))]))]
|
||||
[else
|
||||
(fprintf (current-error-port) "never found a window\n")]))))
|
||||
|
||||
(parameterize ([current-namespace ns])
|
||||
|
||||
;; start up the game
|
||||
|
||||
(parameterize ([current-custodian sub-custodian])
|
||||
(parameterize ([current-namespace (make-base-namespace)])
|
||||
(namespace-attach-module orig-namespace '(lib "mred.ss" "mred"))
|
||||
(namespace-attach-module orig-namespace '(lib "class.ss" "scheme"))
|
||||
(dynamic-require chat-noir #f)))
|
||||
((dynamic-require chat-noir 'main)))))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user