Skip to content

Instantly share code, notes, and snippets.

@rightfold
Created November 4, 2014 17:52
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 rightfold/ebea814abfdd82634c8c to your computer and use it in GitHub Desktop.
Save rightfold/ebea814abfdd82634c8c to your computer and use it in GitHub Desktop.
(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