diff options
author | Darren Bane <dbane@tilde.institute> | 2020-05-05 10:51:29 -0400 |
---|---|---|
committer | Darren Bane <dbane@tilde.institute> | 2020-05-05 10:51:29 -0400 |
commit | 8dc0f67a0d97f0c21fd039f348a73bac9f6f1afc (patch) | |
tree | e9135df03877b4438207ac292f1807d247d02303 | |
parent | 456fe751d1d8f7d1cdca312e50e4763474d62fef (diff) | |
download | lsp-8dc0f67a0d97f0c21fd039f348a73bac9f6f1afc.tar.gz |
Split some funs
-rwxr-xr-x | crpg.lisp | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/crpg.lisp b/crpg.lisp index 6f37799..23e87e4 100755 --- a/crpg.lisp +++ b/crpg.lisp @@ -122,6 +122,64 @@ (defgeneric coord= (l r)) (defmethod coord= ((l <coord>) (r <coord>)) (and (= (row l) (row r)) (= (col l) (col r)))) +(defun attack-cmd () + (if (null *curr-monster*) + (my-print "There's nothing to attack!") + (progn (loop while (and (> (health *curr-monster*) 0) (> (health *the-player*) 0)) + do (cursor 10 1) (clrtoeol) + (cursor 11 1) (clrtoeol) + (cursor 12 1) (clrtoeol) + (cursor 10 1) + (let ((attack (+ (weapon *the-player*) (random 9))) + (monster-attack (attack *curr-monster*))) + (cond + ((= attack monster-attack) + (my-print "No one wins this round.")) + ((> attack monster-attack) + (format *standard-output* "You deal the ~A a blow!~%" (name *curr-monster*)) + (setf (health *curr-monster*) (- (health *curr-monster*) 1))) + ((< attack monster-attack) + (my-print "You have been wounded!") + (setf (health *the-player*) (- (health *the-player*) 1)))) + (my-print +press-key+) + (read-line))) + (cursor 10 1) + (if (> (health *the-player*) 0) + (progn (clrtoeol) + (my-print "You won the fight!") + (format *standard-output* "You found ~A pieces of gold!~%" *monster-gold*) + (setf (gold *the-player*) (+ (gold *the-player*) *monster-gold*)) + (setq *curr-monster* nil) + (setf (monster (aref *map* (row *curr-coord*) (col *curr-coord*))) nil) + (my-print +press-key+) + (read-line)) + (progn (format *standard-output* "The ~A killed you!~%" (name *curr-monster*)) + (my-print "Game over!") + (throw 'quit nil)))))) +(defun take() + (if (null *curr-item*) + (progn (cursor 10 1) + (my-print "Nothing to take!") + (my-print +press-key+) + (read-line)) + (progn (case (class-of *curr-item*) + ((find-class '<food>) + (cursor 10 1) + (format *standard-output* "You eat the ~A.~%" (name *curr-item*)) + (if (>= (health *the-player*) 20) + (my-print "You had no wounds, so the food is wasted.~%") + (progn (setf (health *the-player*) (+ (health *the-player*) (value *curr-item*))) + (format *standard-output* "You gain ~A health points ~%" (value *curr-item*))))) + ((find-class '<weapon>) + (cursor 10 1) + (if (>= (weapon *the-player*) (value *curr-item*)) + (my-print "You have a similar or better weapon.") + (progn (format *standard-output* "You pick up a ~A!") + (setf (weapon *the-player*) (value *curr-item*)) + (format *standard-output* "Your weapon rating is now ~A.~%" (weapon *the-player)))))) + (my-print +press-key+) + (read-line) + (setf (item (aref *map* (row *curr-coord*) (col *curr-coord))) nil)))) (defun handle-cmd (cmd) (cond ((string= cmd "n") @@ -138,62 +196,9 @@ (my-print "You dont have enough gold!") (my-print "You have escaped! Well done!")))) ((string= cmd "a") - (if (null *curr-monster*) - (my-print "There's nothing to attack!") - (progn (loop while (and (> (health *curr-monster*) 0) (> (health *the-player*) 0)) - do (cursor 10 1) (clrtoeol) - (cursor 11 1) (clrtoeol) - (cursor 12 1) (clrtoeol) - (cursor 10 1) - (let ((attack (+ (weapon *the-player*) (random 9))) - (monster-attack (attack *curr-monster*))) - (cond - ((= attack monster-attack) - (my-print "No one wins this round.")) - ((> attack monster-attack) - (format *standard-output* "You deal the ~A a blow!~%" (name *curr-monster*)) - (setf (health *curr-monster*) (- (health *curr-monster*) 1))) - ((< attack monster-attack) - (my-print "You have been wounded!") - (setf (health *the-player*) (- (health *the-player*) 1)))) - (my-print +press-key+) - (read-line))) - (cursor 10 1) - (if (> (health *the-player*) 0) - (progn (my-print "You won the fight!") - (format *standard-output* "You found ~A pieces of gold!~%" *monster-gold*) - (setf (gold *the-player*) (+ (gold *the-player*) *monster-gold*)) - (setq *curr-monster* nil) - (setf (monster (aref *map* (row *curr-coord*) (col *curr-coord*))) nil) - (my-print +press-key+) - (read-line)) - (progn (format *standard-output* "The ~A killed you!~%" (name *curr-monster*)) - (my-print "Game over!") - (throw 'quit nil)))))) + (attack-cmd)) ((string= cmd "t") - (if (null *curr-item*) - (progn (cursor 10 1) - (my-print "Nothing to take!") - (my-print +press-key+) - (read-line)) - (progn (case (class-of *curr-item*) - ((find-class '<food>) - (cursor 10 1) - (format *standard-output* "You eat the ~A.~%" (name *curr-item*)) - (if (>= (health *the-player*) 20) - (my-print "You had no wounds, so the food is wasted.~%") - (progn (setf (health *the-player*) (+ (health *the-player*) (value *curr-item*))) - (format *standard-output* "You gain ~A health points ~%" (value *curr-item*))))) - ((find-class '<weapon>) - (cursor 10 1) - (if (>= (weapon *the-player*) (value *curr-item*)) - (my-print "You have a similar or better weapon.") - (progn (format *standard-output* "You pick up a ~A!") - (setf (weapon *the-player*) (value *curr-item*)) - (format *standard-output* "Your weapon rating is now ~A.~%" (weapon *the-player)))))) - (my-print +press-key+) - (read-line) - (setf (item (aref *map* (row *curr-coord*) (col *curr-coord))) nil)))) + (take)) ((string= cmd "q") (my-print "Bye!") (throw 'quit nil)))) |