;;; gengam1.lsp - Generic Game Pattern 1 (Maclisp) ;;; 2016 David Meyer +JMJ ;;; ;;; Pattern 1: Single-player, fixed number of turns ;;; ;;; To play: ;;; (load "gengam1.lsp") ;;; (play) ;; Program information ... (setq PROGRAM "Generic Game") (setq VERSION "0.0") (setq AUTHOR "David Meyer ") ;; Game parameters ... (setq MAX-TURNS 3) (setq STATUS "initial-game-status") (setq USER-PARMS nil) ;; Message formats ... (setq game-over-fmt "~3&Game over") (setq parm-prompt-fmt "~3&Enter your choice of game parameters: ") (setq rules-query-fmt "~3&Do you want to read the rules?") (setq rules-fmt "~3&This is how you play the game.~2&Hope you have a good time.") (setq status-fmt "~3&Game status:~&~a") ;; Message texts (pre-formatted) ... (setq title-msg (format nil "~2&~a Version ~a~2&by ~a" PROGRAM VERSION AUTHOR)) (setq rules-msg (format nil rules-fmt)) (setq parm-prompt-msg (format nil parm-prompt-fmt)) ;; Functions ... (defun initialize () (princ title-msg) (if (y-or-n-p t rules-query-fmt) (princ rules-msg)) (query-game-parms) (setup-game)) (defun game-over () (format t status-fmt STATUS) (format t game-over-fmt)) (defun game-turn (turn) (format t "~3&Turn ~a" turn) (format t status-fmt STATUS) (update-status (query-command))) (defun query-command () (princ cmd-prompt-msg) (setq USER-PARMS (readline))) (defun query-game-parms () (princ parm-prompt-msg) (setq USER-PARMS (readline))) (defun setup-game () (format t "~2&I'm setting up the game.")) (defun update-status (command) ) ;; Main functions ... (defun play () (initialize) (do ((turn 1 (1+ turn))) ((> turn MAX-TURNS) (game-over)) (game-turn turn)))