adv - ; ADV.SCM ; This file contains the definitions for...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
;; ADV.SCM ;; This file contains the definitions for the objects in the adventure ;; game and some utility procedures. (define-class (place name) (instance-vars (directions-and-neighbors '()) (things '()) (people '()) (entry-procs '()) (exit-procs '())) (method (type) 'place) (method (neighbors) (map cdr directions-and-neighbors)) (method (exits) (map car directions-and-neighbors)) (method (look-in direction) (let ((pair (assoc direction directions-and-neighbors))) (if (not pair) '() ;; nothing in that direction (cdr pair)))) ;; return the place object (method (appear new-thing) (if (memq new-thing things) (error "Thing already in this place" (list name new-thing))) (set! things (cons new-thing things)) 'appeared) (method (enter new-person) (if (memq new-person people) (error "Person already in this place" (list name new-person))) (set! people (cons new-person people)) (for-each (lambda (proc) (proc)) entry-procs) 'appeared) (method (gone thing) (if (not (memq thing things)) (error "Disappearing thing not here" (list name thing))) (set! things (delete thing things)) 'disappeared) (method (exit person) (for-each (lambda (proc) (proc)) exit-procs) (if (not (memq person people)) (error "Disappearing person not here" (list name person))) (set! people (delete person people)) 'disappeared) (method (new-neighbor direction neighbor) (if (assoc direction directions-and-neighbors) (error "Direction already assigned a neighbor" (list name direction))) (set! directions-and-neighbors (cons (cons direction neighbor) directions-and-neighbors))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

adv - ; ADV.SCM ; This file contains the definitions for...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online