Created
January 13, 2010 16:03
-
-
Save tmountain/276310 to your computer and use it in GitHub Desktop.
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
; empty room | |
(def room {:name "the arena", | |
:occupants []}) | |
(def vampire-bat {:hp 17, | |
:name "vampire bat", | |
:alignment "evil", | |
; melee damage 4-2 | |
:melee [4, 2]}) | |
(def thief {:hp 24 | |
:alignment "good", | |
; melee damage 4-3 | |
:melee [4, 3]}) | |
(defn attack-melee [unit] | |
(let [melee (unit :melee) | |
turns (first melee) | |
damage (inc (second melee))] | |
(for [x (range turns)] (rand-int damage)))) | |
(defn add-to-room [room unit] | |
(dosync (alter room assoc :occupants (conj (@room :occupants) unit)))) | |
(defn remove-from-room [room unit] | |
(dosync (alter room assoc :occupants (remove #(= unit %1) (@room :occupants))))) | |
(def arena (ref room)) | |
(def arcadian (ref (assoc thief :name "arcadian"))) | |
(def bat (ref vampire-bat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment