Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-Split game.lisp off into three files (game, player and history-event)
-Removed some testing code that managed to slip by -Amended .asd -Added finished-p field to game (though it's not used yet)
- Loading branch information
inaimathi
committed
Mar 13, 2012
1 parent
23f698e
commit 5e15ec9
Showing
7 changed files
with
84 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(in-package :strifebarge) | ||
|
||
;;;;;;;;;;;;;;;;;;;; player creation | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
(defun make-player (&rest ship-types) | ||
(let ((p (make-instance 'player))) | ||
(setf (ships p) | ||
(mapcar (lambda (s) (make-instance s :player p)) ship-types)) | ||
p)) | ||
|
||
;;;;;;;;;;;;;;;;;;;; predicates and getters | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
(defmethod opponents ((g game) &optional (player (session-value :player))) | ||
(remove player (players g))) | ||
|
||
(defmethod dead-p ((p player)) | ||
(every #'dead-p (ships p))) | ||
|
||
;;;;;;;;;;;;;;;;;;;; display | ||
;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
(defmethod echo-stats ((p player)) | ||
(html-to-stout | ||
(:div :class "player-ships" | ||
(loop for s in (ships p) | ||
do (str (echo-stats s)))))) | ||
|
||
(defmethod echo-opponent ((p player)) | ||
(html-to-stout | ||
(:h5 :id (instance-to-id p) | ||
:class (when (dead-p p) "dead-player") | ||
"An Opponent") | ||
(:ul (loop for s in (shuffle (ships p)) | ||
do (echo-opponent-ship s))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters