;;; gengam1.lsp - Generic Game Pattern 1 (Maclisp)
;;; 2016 David Meyer <
[email protected]> +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 <
[email protected]>")
;; Game parameters ...
(setq MAX-TURNS 3)
(setq STATUS "initial-game-status") ; Use globals only for init. val's and constants; use local var's for active state?
(setq USER-PARMS nil)
;; Message formats ...
(setq cmd-prompt-fmt "~2$Your move: ")
(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) ...
(set cmd-prompt-msg (format nil cmd-prompt-fmt))
(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 game-turn (turn)
(if (> turn MAX-TURNS)
(game-over)
(progn
(format t "~3&Turn ~a" turn)
(format t status-fmt STATUS)
(update-status (query-command))
(game-turn (1+ turn)))))
(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)
(setq STATUS "current-game-status"))
;; Main functions ...
(defun play ()
(initialize)
(do ((turn 1 (1+ turn)))
((> turn MAX-TURNS) (game-over))
(game-turn turn)))