comparison lisp/play/mpuz.el @ 2451:a149f1464f40

(mpuz-try-letter): Use read-char to read digit. Use message directly also. Use downcase. (mpuz-read-map): Deleted.
author Richard M. Stallman <rms@gnu.org>
date Fri, 02 Apr 1993 08:12:40 +0000
parents f287613dfc28
children 507f64624555
comparison
equal deleted inserted replaced
2450:17d258d8e8e4 2451:a149f1464f40
50 ;;---------------------- 50 ;;----------------------
51 (defvar mpuz-mode-hook nil) 51 (defvar mpuz-mode-hook nil)
52 52
53 (defvar mpuz-mode-map nil 53 (defvar mpuz-mode-map nil
54 "Local keymap to use in Mult Puzzle.") 54 "Local keymap to use in Mult Puzzle.")
55
56 (defvar mpuz-read-map nil
57 "Local keymap to use (sometimes) in Mult Puzzle.")
58 55
59 (if mpuz-mode-map nil 56 (if mpuz-mode-map nil
60 (setq mpuz-mode-map (make-sparse-keymap)) 57 (setq mpuz-mode-map (make-sparse-keymap))
61 (define-key mpuz-mode-map "a" 'mpuz-try-letter) 58 (define-key mpuz-mode-map "a" 'mpuz-try-letter)
62 (define-key mpuz-mode-map "b" 'mpuz-try-letter) 59 (define-key mpuz-mode-map "b" 'mpuz-try-letter)
78 (define-key mpuz-mode-map "H" 'mpuz-try-letter) 75 (define-key mpuz-mode-map "H" 'mpuz-try-letter)
79 (define-key mpuz-mode-map "I" 'mpuz-try-letter) 76 (define-key mpuz-mode-map "I" 'mpuz-try-letter)
80 (define-key mpuz-mode-map "J" 'mpuz-try-letter) 77 (define-key mpuz-mode-map "J" 'mpuz-try-letter)
81 (define-key mpuz-mode-map "\C-g" 'mpuz-offer-abort) 78 (define-key mpuz-mode-map "\C-g" 'mpuz-offer-abort)
82 (define-key mpuz-mode-map "?" 'describe-mode)) 79 (define-key mpuz-mode-map "?" 'describe-mode))
83
84 (if mpuz-read-map nil
85 (setq mpuz-read-map (make-keymap))
86 (let ((i 0))
87 (while (< i (length mpuz-read-map))
88 (define-key mpuz-read-map (char-to-string i) 'exit-minibuffer)
89 (setq i (1+ i)))))
90 80
91 (defun mpuz-mode () 81 (defun mpuz-mode ()
92 "Multiplication puzzle mode. 82 "Multiplication puzzle mode.
93 83
94 You have to guess which letters stand for which digits in the 84 You have to guess which letters stand for which digits in the
370 (defun mpuz-try-letter () 360 (defun mpuz-try-letter ()
371 "Propose a digit for a letter in puzzle." 361 "Propose a digit for a letter in puzzle."
372 (interactive) 362 (interactive)
373 (if mpuz-in-progress 363 (if mpuz-in-progress
374 (let (letter-char digit digit-char message) 364 (let (letter-char digit digit-char message)
375 (setq letter-char (if (or (< last-command-char ?a) 365 (setq letter-char (upcase last-command-char)
376 (> last-command-char ?z))
377 last-command-char
378 (- last-command-char 32))
379 digit (mpuz-to-digit (- letter-char ?A))) 366 digit (mpuz-to-digit (- letter-char ?A)))
380 (cond ((mpuz-digit-solved-p digit) 367 (cond ((mpuz-digit-solved-p digit)
381 (message "%c already solved." letter-char)) 368 (message "%c already solved." letter-char))
382 ((null (aref mpuz-board digit)) 369 ((null (aref mpuz-board digit))
383 (message "%c does not appear." letter-char)) 370 (message "%c does not appear." letter-char))
384 ((progn (setq message (format "%c = " letter-char)) 371 ((progn (message "%c = " letter-char)
385 ;; <char> has been entered. 372 ;; <char> has been entered.
386 ;; Print "<char> =" and 373 ;; Print "<char> =" and
387 ;; read <num> or = <num> 374 ;; read <num> or = <num>
388 (read-from-minibuffer message nil mpuz-read-map) 375 (setq digit-char (read-char))
389 (if (= last-input-char ?\=) 376 (if (eq digit-char ?=)
390 (read-from-minibuffer message nil mpuz-read-map)) 377 (setq digit-char (read-char)))
391 (setq digit-char last-input-char)
392 (message "%c = %c" letter-char digit-char) 378 (message "%c = %c" letter-char digit-char)
393 (or (> digit-char ?9) (< digit-char ?0))) ; bad input 379 (or (> digit-char ?9) (< digit-char ?0))) ; bad input
394 (ding t)) 380 (ding t))
395 (t 381 (t
396 (mpuz-try-proposal letter-char digit-char)))) 382 (mpuz-try-proposal letter-char digit-char))))