Newer
Older
mazes / distance-grid.lisp
(in-package :mazes)

(defclass distance-grid (grid)
  ((distances :initform nil :accessor distances))
  (:documentation "A subclass of GRID that displays distance values of the cells."))

(defmethod contents-of ((g grid) (c cell))
  (let ((dist (distances g))
        (chars "0123456789abcdef"))
    (if (and (not (null dist)) (< (gethash c dist) (length chars)))
        (format nil "~a" (subseq chars (gethash c dist) (1+ (gethash c dist))))
        "*")))

(defun make-distance-grid (rows cols)
  (make-instance 'distance-grid :rows rows :cols cols))