이번장에서는 실제로 키보드 입력을 받아들이고 게임을 구성하는 루프를 만든다.
먼저 키보드 입력을 받아들여보자.
다음으로 이벤트 루프를 구성한다.
구성된 이벤트 루프를 토대로 해당하는 방으로 이동하는 함수를 만들고, 나머지 모든 부분을 연결하는 게임함수를 만든다.

먼저 키보드 입력을 받아들여보자.
;;; 사용자 키보드 입력을 체크하고 그에따란 이벤트 처리를 함
(defun keyboard-event ()
(format t "What do you want to do:")
(let ((k (read-line)))
(if (= (length k) 1)
k
(keyboard-event))))
다음으로 이벤트 루프를 구성한다.
;;; 전체 이벤트 루프
(defun event-loop ()
(let ((k (get-rooms-element (get-room *room*) #\m))
(game-over nil))
(loop
(status-report)
(let ((input-key (keyboard-event)))
(cond ((string= input-key "n") (go-direction #\n))
((string= input-key "s") (go-direction #\s))
((string= input-key "e") (go-direction #\e))
((string= input-key "w") (go-direction #\w))
((string= input-key "c") (consume-food))
((string= input-key "f") (fight))
((string= input-key "r") (runaway))
((string= input-key "q") (setf game-over t))
((string= input-key "i") (inventory))))
(if (eq game-over t)
(return-from event-loop)))))
구성된 이벤트 루프를 토대로 해당하는 방으로 이동하는 함수를 만들고, 나머지 모든 부분을 연결하는 게임함수를 만든다.
;;; 해당 방의 방위로 이동하는 함수이제 슬슬 기본틀을 완성된 것 같고.. 음식과 전투, 도망가기, 인벤토리등을 구성하도록 하자
(defun go-direction (direction)
(let ((door (get-rooms-element (get-room *room*) direction)))
(cond ((= door 0) (format t "There is no door in that direction."))
(t
(setf *room* door)))))
;;; 실제 게임 실행부분
(defun run-game ()
;;; 게임 초기화
(reset-mobs)
(init-var)
(get-player-name)
(put-gold 4)
(put-mob 4)
(set-init-treasure)
(event-loop))

댓글 없음:
댓글 쓰기