-
-
Save rightfold/ebea814abfdd82634c8c 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 gemu.core | |
(:require [clojure.java.shell :refer [sh]]) | |
(:gen-class)) | |
(defn read-char | |
"Reads a character from stdin without echoing it." | |
[] | |
(sh "sh" "-c" "stty -icanon -echo < /dev/tty") | |
(try (char (.read System/in)) | |
(finally (sh "sh" "-c" "stty icanon echo < /dev/tty")))) | |
(defn navigate [state direction] | |
(assoc state :direction direction)) | |
(defn decide-action [key] | |
(case key | |
\w #(navigate % :north) | |
\s #(navigate % :south) | |
\a #(navigate % :west) | |
\d #(navigate % :east) | |
identity)) | |
(defn game [state] | |
(println state) | |
(-> (read-char) decide-action (apply [state]) recur)) | |
(defn -main [& args] | |
(game {})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment