-
Notifications
You must be signed in to change notification settings - Fork 0
/
history-event.lisp
36 lines (31 loc) · 1.12 KB
/
history-event.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(in-package :strifebarge)
;;;;;;;;;;;;;;;;;;;; creation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod to-json ((m move))
(encode-json-to-string `((x . ,(x m)) (y . ,(y m))
(text . ,(echo m (session-value :player))))))
(defmethod push-record ((g game) event-type message)
(push (make-instance 'history-event
:id (length (history g))
:event-type event-type
:message message)
(history g)))
;;;;;;;;;;;;;;;;;;;; display
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod emit-record ((g game) (p player))
(apply #'concatenate
(cons 'string
(mapcar (lambda (r) (emit-record r p))
(reverse (take 10 (history g)))))))
(defmethod emit-record ((e history-event) (p player))
(format nil "id: ~a~%event: ~a~%data: ~a~%~%"
(id e) (event-type e) (message e)))
;;;;;;;;;;;;;;;;;;;; game logic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod death-check ((g game) (s ship))
(when (dead-p s)
(push-record g "ship-sunk"
(encode-json-to-string `((:type . ,(type-of s))
(:id . ,(instance-to-id s))))))
(when (dead-p (player s))
(push-record g "player-eliminated" (instance-to-id (player s)))))