Skip to content

Commit

Permalink
Split Chapter 17 file: (svg-dsl, new-text-game-adventure)
Browse files Browse the repository at this point in the history
This keep the things more simple because the new text game adventure
need executes your runtime at CL-USER package, but, in another hand, :svg
is a package isolated.
  • Loading branch information
ryukinix committed Mar 17, 2017
1 parent e2d57e1 commit 873f529
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 51 deletions.
60 changes: 9 additions & 51 deletions land-of-lisp/cap17-domain-specific-languages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
;; Remember SVG (Scalable Vector Graphics) are XML-like,


(load "cap5-building-a-text-game-engine")
(defpackage :svg
(:use :cl)
(:export :svg :html
:body :tag
:brightness :svg-style
:polygon :circle))

(in-package :svg)


;; Would be better avoid copy-paste functions,
;; but the chapter 16 has several re-definitions
Expand Down Expand Up @@ -128,53 +136,3 @@
;; svg finished

;; starts extension of the wizard_game from chapter 5-6

(defun have (object)
(member object (inventory)))

(defparameter *chain-welded* nil)

(defun weld (subject object)
(if (and (eq *location* 'attic)
(eq subject 'chain)
(eq object 'bucket)
(have 'chain)
(have 'bucket)
(not *chain-welded*))
(progn (setf *chain-welded* t)
'(the chain is now securely welded to the bucket.))
'(you cannot weld like that.)))

(pushnew 'weld *allowed-commands*)
(defparameter *bucket-filled* nil)

(defun dunk (subject object)
(if (and (eq *location* 'garden)
(eq subject 'bucket)
(eq object 'well)
(have 'bucket)
*chain-welded*)
(progn (setf *bucket-filled* t)
'(the bucket is now full of water))
'(you cannot dunk like that)))
(pushnew 'dunk *allowed-commands*)


;; super cool macro to avoid replication like the commands above
(defmacro game-action (command subj obj place &body body)
`(progn (defun ,command (subject object)
(if (and (eq *location* ',place)
(eq subject ',subj)
(eq object ',obj)
(have ',subj))
,@body
'(i cant ,command like that.)))
(pushnew ',command *allowed-commands*)))

(game-action splash bucket wizard living-room
(cond ((not *bucket-filled*) '(the bucket has nothing in it.))
((have 'frog) '(the wizard awakens and sees that you stole his frog.
he is so upset he banishes you to the netherworlds-
you lose! the end.))
(t '(the wizard awakens from his slumber and greets your warmly.
he hands you the magic low-carb donut- you win! the end.))))
55 changes: 55 additions & 0 deletions land-of-lisp/cap17-text-game-adventure-v2.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
;; Common Lisp Script
;; Manoel Vilela

(load "cap5-building-a-text-game-engine")


(defun have (object)
(member object (inventory)))

(defparameter *chain-welded* nil)

(defun weld (subject object)
(if (and (eq *location* 'attic)
(eq subject 'chain)
(eq object 'bucket)
(have 'chain)
(have 'bucket)
(not *chain-welded*))
(progn (setf *chain-welded* t)
'(the chain is now securely welded to the bucket.))
'(you cannot weld like that.)))

(pushnew 'weld *allowed-commands*)
(defparameter *bucket-filled* nil)

(defun dunk (subject object)
(if (and (eq *location* 'garden)
(eq subject 'bucket)
(eq object 'well)
(have 'bucket)
*chain-welded*)
(progn (setf *bucket-filled* t)
'(the bucket is now full of water))
'(you cannot dunk like that)))
(pushnew 'dunk *allowed-commands*)


;; super cool macro to avoid replication like the commands above
(defmacro game-action (command subj obj place &body body)
`(progn (defun ,command (subject object)
(if (and (eq *location* ',place)
(eq subject ',subj)
(eq object ',obj)
(have ',subj))
,@body
'(i cant ,command like that.)))
(pushnew ',command *allowed-commands*)))

(game-action splash bucket wizard living-room
(cond ((not *bucket-filled*) '(the bucket has nothing in it.))
((have 'frog) '(the wizard awakens and sees that you stole his frog.
he is so upset he banishes you to the netherworlds-
you lose! the end.))
(t '(the wizard awakens from his slumber and greets your warmly.
he hands you the magic low-carb donut- you win! the end.))))

0 comments on commit 873f529

Please sign in to comment.