Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fahadbuddy/66ae35133542dec16650 to your computer and use it in GitHub Desktop.
Save fahadbuddy/66ae35133542dec16650 to your computer and use it in GitHub Desktop.
(ns text-adventure.core
(:gen-class))
(def state (atom {:x 0 :y 0}))
(def directions {
:right (fn [m] (assoc m :x (inc (:x m))))
:left (fn [m] (assoc m :x (dec (:x m))))
:up (fn [m] (assoc m :y (inc (:y m))))
:down (fn [m] (assoc m :y (dec (:y m))))
:start identity
:exit identity
})
(def room {{:x 1 :y 1}
"You just stepped on a landmine! You are dead!"
{:x -2 :y -2}
"You found some gold, you are rich and you retire"
{:x 0 :y 0}
"You find yourself in a crystal maze! (how did that happen?!) \n you can go up , down, left or right"
{:x 0 :y 1}
"you find a sign saying 'Beware of the North west'"
})
(defn game-loop [input]
(let [
]
(swap! state (input directions))
(prn @state)
(when-let [roomName (get room @state)]
(prn roomName))
(if (not (= :exit
input))
(game-loop (keyword (read-line)))
(prn "exiting...")
)))
(defn -main [& args]
(game-loop :start))
@fahadbuddy
Copy link
Author

@ernestas , @fahadbuddy authored this beast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment