SHOW:
|
|
- or go back to the newest paste.
1 | - | (defclass battle-entity () |
1 | + | (defclass battleentity () |
2 | ((name :accessor nm | |
3 | :initarg :nm) | |
4 | - | (health :accessor hp |
4 | + | (health :accessor hp |
5 | - | :initarg :hp) |
5 | + | :initarg :hp) |
6 | - | (attack :accessor atk |
6 | + | (attack :accessor atk |
7 | - | :initarg :atk))) |
7 | + | :initarg :atk))) |
8 | ||
9 | - | (defmethod doattack ((self battle-entity) (target battle-entity)) |
9 | + | (defmethod doattack ((self battleentity) (target battleentity)) |
10 | (write-line (format nil "~a attacks ~a" | |
11 | - | (nm self) (nm target))) |
11 | + | (nm self) (nm target))) |
12 | - | (damaged target (atk self)) |
12 | + | (damaged target (atk self))) |
13 | - | ) |
13 | + | |
14 | - | (defmethod damaged ((self battle-entity) (damage integer)) |
14 | + | (defmethod damaged ((self battleentity) (damage integer)) |
15 | - | (format t "~a takes ~a damage" |
15 | + | (write-line (format nil "~a takes ~a damage" |
16 | - | (nm self) damage)) |
16 | + | (nm self) damage)) |
17 | - | (setf (hp self) (- (hp self) damage)) |
17 | + | (setf (hp self) (- (hp self) damage))) |
18 | ||
19 | - | (defmethod status ((self battle-entity)) |
19 | + | (defmethod status ((self battleentity)) |
20 | - | (format t "~a HP: ~a~%" |
20 | + | (write-line (format nil "~a HP: ~a~%" |
21 | - | (nm self) (hp self))) |
21 | + | (nm self) (hp self)))) |
22 | ||
23 | - | (defun make-battle-entity (name health attack) |
23 | + | (defun makebattleentity (name health attack) |
24 | - | (setf temp (make-instance 'battle-entity |
24 | + | (setf temp (make-instance 'battleentity |
25 | - | :nm name |
25 | + | :nm name |
26 | - | :hp health |
26 | + | :hp health |
27 | - | :atk attack)) |
27 | + | :atk attack)) |
28 | temp) | |
29 | ||
30 | - | (setf battlers (list (make-battle-entity "Player" 100 25) |
30 | + | (setf battlers (list (makebattleentity "Player" 100 25) |
31 | - | (make-battle-entity "Goblin" 60 5) |
31 | + | (makebattleentity "Goblin" 60 5) |
32 | - | (make-battle-entity "Troll" 500 80) |
32 | + | (makebattleentity "Troll" 500 80) |
33 | - | (make-battle-entity "Hero" 100 560))) |
33 | + | (makebattleentity "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 |
37 | + | while (<= 0 (min (hp a) (hp b))) do |
38 | - | (doattack a b) |
38 | + | (doattack a b) |
39 | - | (status b) |
39 | + | (status b) |
40 | - | (doattack b a) |
40 | + | (doattack b a) |
41 | - | (status a)) |
41 | + | (status a)) |