annotate clojure/com/aurellem/gb/badges.clj @ 611:d9f991cddad9

spellcheck
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Nov 2012 11:24:52 -0600
parents edce489c3c21
children
rev   line source
ocsenave@227 1 (ns com.aurellem.gb.badges
ocsenave@227 2 (:use (com.aurellem.gb gb-driver util constants))
ocsenave@227 3 (:import [com.aurellem.gb.gb_driver SaveState]))
ocsenave@227 4
rlm@228 5 (def badges
rlm@228 6 '(:boulder :cascade :thunder :rainbow
rlm@228 7 :soul :marsh :volcano :earth))
ocsenave@227 8
ocsenave@227 9 (defn get-badges
ocsenave@227 10 "Returns a list of the current badges held by the player."
ocsenave@227 11 ([state]
ocsenave@227 12 ((fn this [coll n]
ocsenave@227 13 (cond (zero? n) '()
ocsenave@227 14 (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
rlm@228 15 :else (cons
rlm@228 16 (peek coll)
rlm@228 17 (this (pop coll) (int (/ n 2))))))
ocsenave@227 18 badges
rlm@228 19 (aget (memory state) 0xD355)))
ocsenave@227 20 ([] (get-badges @current-state)))
ocsenave@227 21
ocsenave@227 22 (defn set-badges
rlm@228 23 "Sets the badges held by the player. badge-list may contain
rlm@228 24 :boulder :cascade :thunder :marsh :rainbow :soul :volcano."
ocsenave@227 25 ([state badge-list]
ocsenave@227 26 (let [has-badge (set badge-list)]
ocsenave@227 27 (->>
ocsenave@227 28 ((fn [n coll]
ocsenave@227 29 (cond
ocsenave@227 30 (empty? coll) n
ocsenave@227 31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))
ocsenave@227 32 :else (recur (* 2 n) (pop coll))))
ocsenave@227 33 0
ocsenave@227 34 (vec badges))
ocsenave@227 35 (set-memory state 0xD355))))
ocsenave@227 36 ([badge-list] (set-badges @current-state badge-list)))
ocsenave@227 37
rlm@228 38 (defn give-all-badges
rlm@228 39 ([^SaveState state]
rlm@228 40 (set-badges state badges))
rlm@228 41 ([] (give-all-badges @current-state)))
rlm@228 42