이제 이글루스 게시물을 가져올 것임..




;;;; 게임의 Castle 구성하기..
;;; north south east west up down mobs
(defvar *castle*
'((0 2 0 0 0 0 0 ("You are in the hall way." "There is a door in south." "Through window to the north you can see secret herb garden"))
(1 3 3 3 0 0 0 ("This is the audience chamber" "There is a window to the south. By looking to the right" "Through it you can see the entrance of the castle" "Doors leave this room to the north, east, and south" ))
(2 0 5 2 0 0 0 ("You are in great hall, all-shaped room" "There is doors to the east and to the north" "In the alcove is a door to the west"))
(0 5 0 0 0 0 0 ("This is the monarch's private meeting room" "There is a single exit to the south"))
(4 0 0 3 15 13 0 ("This inner hallway contains a door to the north." "And one to the west, and a circular stairwell" "passes though the room" "You can see ornamental lake through here"))
(0 0 1 0 0 0 0 ("You are at the entrance to a fobidding-looking" "stone castle. You are facing east"))
(0 8 0 0 0 0 0 ("This is castle's kitchen. Though windows in" "The north wall you can see secret herb garden." "A door leave the kitchen to the south" ))
(7 10 0 0 0 0 0 ("You are in store room admist spices" "vegatables, and vast sacks of floud and" "Other provisions. There is a door to the north" "and one to the south"))
(0 19 0 8 0 8 0 ("You are slowly descends."))
(8 0 11 0 0 0 0 ("You are in the real vestibule." "There are windows to the south from which" "you can see ornamental lake" "There is an exit to the east and " "one to north"))
(0 0 10 0 0 0 0 () )
(0 0 0 13 0 0 0 ("you are in dank dark dungeon" "There is single exit, a small hole in" "wall towards to east"))
(0 0 12 0 5 0 0 ("You are in the prison guardroom in the " "basement of the castle. The staiwell" "ends in the room. There is one other" "exit, a small hole in the east wall") )
(0 15 17 0 0 0 0 ("You are in the master bedroom on the upper" "level of the castle..." "Looking down from the window to the west, you" "can see the entrance to the castle, while the" "secret herb garden is visible below to the north" "window. There are doors to the east and" "to the south"))
(14 0 0 0 0 5 0 ("This is L-shaped upper hallway." "To the north is a door, and there is a strairwell in the hall as well. You can see" "the lake through the south windows."))
(17 0 19 0 0 0 0 ("This room was used as the castle treasury in" "by-gone years..." "There are no windows, just exits to the" "north and to the east"))
(18 16 0 14 0 0 0 ("Ooooh.. you are in the chembermaids' bedroom" "There is an exit to the west and a door " "TO the south"))
(0 17 0 0 0 0 0 ("This tiny room on the upper level is the" "dressing chamber. There is a window to the" "north. with a view of the here garden down" "below. A door leaves to the south."))
(9 0 16 0 0 0 0 ("This is a small room outside the castle" "lift which can be entered by a door to the north" "another door leads to the west, you can see" "the lake through the southern windows"))))
;;; 방의 리스트에서 각 요소를 가져오는 함수
(defun get-rooms-element (room element)
(cond ((char= element #\n) (car room))
((char= element #\s) (nth 1 room))
((char= element #\e) (nth 2 room))
((char= element #\w) (nth 3 room))
((char= element #\u) (nth 4 room))
((char= element #\d) (nth 5 room))
((char= element #\m) (nth 6 room))
((char= element #\v) (nth 7 room))
(t
nil)))
;;; 방의 모습을 설명하는 루틴
(defun describe-room ()
(format t "The room is ~A~%" *room*)
(print-room *room*)
(if (= *room* 9) (setf *room* 10)))
;;; 방의 내역을 출력하기
(defun print-room (which-room)
(let ((desc-list (get-rooms-element (get-room which-room ) #\v)))
(labels ((iter (field)
(cond ((null field) )
(t
(format t "~a~%" (car field))
(iter (cdr field))))))
(iter desc-list))))
;;; 전체 이벤트 루프
(defun event-loop ()
(let ((k (get-rooms-element (get-room *room*) #\m))
(game-over nil))
(loop
(status-report)
(cond ((= *room* 11)
(progn
(format t "Congratulation, you escape the castle")
(setf game-over t)))
(t
(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 "u") (go-direction #\u))
((string= input-key "d") (go-direction #\d))
((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 "m") (magic-amulet))
((string= input-key "p") (picking-up))
((string= input-key "i") (inventory))))))
(if (eq game-over t)
(return-from event-loop)))))

;;; 전투모듈실제 전투모드에서는 확률에 의거해 공방을 결정하고, 전투가 끝나는 것도 확률로 결정한다.
(defun fight ()
(prompt-read "press return to fight")
(cond ((= *suit* 1)
(progn
(format t "Your armor increases your chance of success~%")
(setf *ff* (* 3 (floor (/ *ff* 4)))))))
(cond ((and (= *axe* 0) (= *sword* 0))
(progn
(format t "You have no weapons~%You mush fight with Base hands~%")
(setf *ff* (+ *ff* (floor (/ *ff* 5))))))
((and (= *axe* 1) (= *sword* 0))
(progn
(format t "You have only an axe to fight with~%")
(setf *ff* (* 4 (floor (/ *ff* 5))))))
((and (= *sword* 1) (= *axe* 0))
(progn
(format t "You mush fight with your sowrd~%")
(setf *ff* (* 3 (floor (/ *ff* 4))))))
(t
(let ((z (parse-integer (prompt-read "Which weapon? 1- Axe, 2- Sword"))))
(cond ((= z 1) (setf *ff* (* 4 (floor (/ *ff* 5)))))
((= z 2) (setf *ff* (* 3 (floor (/ *ff* 4)))))))))
(taking-arms))

(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 "u") (go-direction #\u))
((string= input-key "d") (go-direction #\d))
((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 "m") (magic-amulet))
((string= input-key "p") (picking-up))
((string= input-key "i") (inventory))))
(if (eq game-over t)
(return-from event-loop)))))
;;; 마법 아뮬렛을 사용할 때 수행할 곳(6번과 11번은 제외 )
(defun magic-amulet ()
(let ((ro (+ (random 19) 1)))
(cond ((or (= ro 6) (= ro 11)) (magic-amulet))
(t
(setf *room* ro)))))
;;; 음식 먹기
(defun consume-food ()
(cond ((>= food 1)
(progn
(format t "You have ~a units of food~%" *food*)
(format t "How many do you want to eat? :")
(let ((z (parse-integer (read-line))))
(if (> z food)
(consume-food)
(progn
(decf *food* z)
(incf *strength* (* 5 z)))))))))
;;; 방의 물건 집기
(defun picking-up ()
(let ((treasure (get-rooms-element
(get-room *room*)
#\m)))
(if (< treasure 10)
(format t "There is no treasure to pickup")
(progn
(incf *wealth* treasure)
(setf (nth 6 (nth (- *room* 1) *castle*)) 0)))))
;;; Show shop
(defun show-shop ()
(format t "You can buy 1 - Flamming Torch ($15)~%")
(format t " 2 - Axe ($10)~%")
(format t " 3 - Sword ($20)~%")
(format t " 4 - Food ($2 per unit)~%")
(format t " 5 - Magic of Amulet ($30)~%")
(format t " 6 - Suit of Armor ($50)~%")
(format t " 0 - To continue Adventure ~%"))
;;; Shop에서 물건사기
(defun inventory ()
(format t "Provision & Inventory~%")
(cond ((> *wealth* 0)
(progn
(show-shop)
(let ((z (parse-integer (prompt-read "Enter no of item:"))))
(cond ((= z 1)
(progn
(setf *light* 1)
(decf *wealth* 15)))
((= z 2)
(progn
(setf *axe* 1)
(decf *wealth* 10)))
((= z 3)
(progn
(setf *sword* 1)
(decf *wealth* 20)))
((= z 4)
(progn
(let ((q (prompt-read "how many food do you want")))
(cond ((> (* q 2) *wealth*)
(format t "You Can't Get enough money"))
(t
(progn
(incf *food* q)
(defc *wealth* (* q 2))))))))
((= z 5)
(progn
(setf *amulet* 1)
(decf *wealth* 30)))
((= z 6)
(progn
(setf *armor* 1)
(decf *wealth* 50)))))))
(t
(format t "You have no money~%"))))
