66
1552
1514
后起之秀
(defun C:test nil (TicTacToe)); Tic Tac Toe; Written By Grrr; Credits: Lee Mac(defun TicTacToe ( / SubstNth GroupByN kL vL *error* dcl des dch dcf tmp ) (defun SubstNth ( n v L / i ) (setq i -1) (mapcar (function (lambda (x) (if (eq n (setq i (1+ i))) v x))) L)) (defun GroupByN ( n L / r ) ; Grrr (repeat n (and L (setq r (cons (car L) r))) (setq L (cdr L)) r) (if L (cons (reverse r) (GroupByN n L)) (list (reverse r))) ); defun GroupByN (setq kL '( ("A1" "B1" "C1") ("A2" "B2" "C2") ("A3" "B3" "C3") ); list ); setq kL (setq vL '( (nil nil nil) (nil nil nil) (nil nil nil) ) ) (defun *error* ( msg ) (and (< 0 dch) (unload_dialog dch)) (and (eq 'FILE (type des)) (close des)) (and (eq 'STR (type dcl)) (findfile dcl) (vl-file-delete dcl)) (and msg (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\nError: " msg)) )) (princ) ); defun *error* (cond ( (progn (while (not (member dcf '(0 1))) (*error* nil) (cond ( (not ; Rewrite and Reload the dialog continiously (and (setq dcl (vl-filename-mktemp nil nil ".dcl")) (setq des (open dcl "w")) (vl-every (function (lambda (x) (princ (strcat "\n" x) des))) (list "test : dialog " "{ label = "Tic Tac Toe"; spacer;" " : column " " {" (apply (function strcat) (mapcar (function (lambda (kL vL) (strcat "\n" " : row " " { fixed_width = true; alignment = centered; " (apply (function strcat) (mapcar (function (lambda (k v) (strcat "\n" " : button { key = "" k ""; label = "" (cond (v)("")) ""; width = 3; fixed_width = true; height = 1.5; }") ); lambda (xx) ); function kL vL ); mapcar ); apply 'strcat " }" ); strcat ); lambda (r) ); function kL vL ); mapcar ); apply 'strcat " }" " spacer_1; ok_only; : text { key = "error"; }" "}" ); list ); vl-every (not (setq des (close des))) (< 0 (setq dch (load_dialog dcl))) ); and ); not (princ "\nUnable to write or load the DCL file.") (setq dcf 0) ) ( (not (new_dialog "test" dch)) (princ "\nUnable to display the dialog") (setq dcf 0) ) (T (eval (read (apply 'strcat (mapcar 'chr '(40 83 69 84 95 84 73 76 69 32 34 101 114 114 111 114 34 32 34 87 114 105 116 116 101 110 32 98 121 32 71 114 114 114 34 41))))) (mapcar (function (lambda (rk rv) (mapcar (function (lambda ( k v ) (action_tile k (vl-prin1-to-string (quote ( (lambda ( / i n tmp ) (cond ( (not (nth (setq i (vl-position $key (apply 'append kL))) (apply 'append vL))) (setq vL (GroupByN 3 (SubstNth i "O" (apply 'append vL)))) (cond ( (vl-some 'null (apply 'append vL)) ; SubstNth ( n v L ) (cond ; apply a little logic (but not alot, since we don't want to draw everytime) ( ; row (and (setq n -1) (setq n