Created
September 29, 2015 20:00
-
-
Save fahadbuddy/66ae35133542dec16650 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
(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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ernestas , @fahadbuddy authored this beast!