Created
May 2, 2020 21:48
-
-
Save vitalipe/ec5e1a3aa4b31697997df1564a99107e 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
(def player (ref {:health 500 :attack 10 :items #{}})) | |
(def mob1 (ref {:health 100 :attack 2 :items #{"big-banana"}})) | |
(def mob2 (ref {:health 100 :attack 4 :items #{"banana"}})) | |
(defn attack! [attacker enemy] | |
(dosync | |
(let [attacker-value (:attack @attacker) | |
enemy-value (:attack @enemy)] | |
(alter enemy update :health - attacker-value) | |
(alter attacker update :health - (/ enemy-value 2))))) | |
(defn loot! [to from] | |
(dosync | |
(when-let [item (first (:items @from))] | |
(alter to update :items conj item) | |
(alter from update :items disj item)))) | |
(comment | |
(attack! player mob1) | |
(attack! player mob2) | |
(loot! player mob2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment