home *** CD-ROM | disk | FTP | other *** search
- ; book pp.252-253
-
- (load "book/resize")
-
- (send w :add-slot 'step-size 10)
-
- (defmeth w :step-size (&optional (val nil set))
- (if set (setf (slot-value 'step-size) val))
- (slot-value 'step-size))
-
- (defmeth w :move (x y)
- (send self :x (+ x (send self :x)))
- (send self :y (+ y (send self :y)))
- (send self :redraw))
-
- (defmeth w :do-idle ()
- (let ((step (send self :step-size)))
- (case (random 4)
- (0 (send self :move 0 (- step)))
- (1 (send self :move 0 step))
- (2 (send self :move step 0))
- (3 (send self :move (- step) 0)))))
-
- (send w :idle-on t)
-
- (defmeth w :restart ()
- (send self :x (/ (send self :canvas-width) 2))
- (send self :y (/ (send self :canvas-height) 2))
- (send self :redraw))
-
- (setf restart-item
- (send menu-item-proto :new "Restart"
- :action #'(lambda () (send w :restart))))
-
- (setf run-item
- (send menu-item-proto :new "Run"
- :action #'(lambda () (send w :idle-on (not (send w :idle-on))))))
-
- (defmeth run-item :update ()
- (send self :mark (send w :idle-on)))
-
- (setf menu (send menu-proto :new "Random Walk"))
- (send menu :append-items restart-item run-item)
- (send w :menu menu)
- (send menu :install)
-