Advertisement
Kitsunay

RPG Test

Aug 27th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.24 KB | None | 0 0
  1. (defclass battle-entity ()
  2.   ((name  :accessor nm
  3.           :initarg :nm)
  4.   (health :accessor hp
  5.           :initarg :hp)
  6.   (attack :accessor atk
  7.           :initarg :atk)))
  8.  
  9. (defmethod doattack ((self battle-entity) (target battle-entity))
  10.   (write-line (format nil "~a attacks ~a"
  11.                             (nm self) (nm target)))
  12.   (damaged target (atk self))
  13. )
  14. (defmethod damaged ((self battle-entity) (damage integer))
  15.   (format t "~a takes ~a damage"
  16.                             (nm self) damage))
  17.   (setf (hp self) (- (hp self) damage))
  18.  
  19. (defmethod status ((self battle-entity))
  20.   (format t "~a HP: ~a~%"
  21.                       (nm self) (hp self)))
  22.  
  23. (defun make-battle-entity (name health attack)
  24.   (setf temp (make-instance 'battle-entity
  25.                :nm name
  26.                :hp health
  27.                :atk attack))
  28.   temp)
  29.  
  30. (setf battlers (list (make-battle-entity "Player" 100 25)
  31.                      (make-battle-entity "Goblin" 60  5)
  32.                      (make-battle-entity "Troll" 500 80)
  33.                      (make-battle-entity "Hero" 100 560)))
  34.  
  35. (setf a (nth 1 battlers) b (nth 2 battlers))
  36. (loop
  37.   while (<= 0 (min (hp a) (hp b))) do
  38.     (doattack a b)
  39.     (status b)
  40.     (doattack b a)
  41.     (status a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement