Skip to content

Instantly share code, notes, and snippets.

@maruks
Created December 18, 2017 19:40
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 maruks/a5359ade5af71bc47dcf2dbc5c487203 to your computer and use it in GitHub Desktop.
Save maruks/a5359ade5af71bc47dcf2dbc5c487203 to your computer and use it in GitHub Desktop.
(ns prison.core
(:require [gniazdo.core :as ws]
[clojure.data.json :as json]))
(defn parse [str]
(json/read-str str :key-fn keyword))
(def msg-atom (atom nil))
(defn handle [msg]
(reset! msg-atom msg)
(ws/send-msg socket (json/write-str {:tag "SetColor" :contents "#0000ff"}))
(ws/send-msg socket (json/write-str {:tag "MakeChoice" :contents ["Betray" "North"]}))
(ws/send-msg socket (json/write-str {:tag "MakeChoice" :contents ["Betray" "South"]}))
(ws/send-msg socket (json/write-str {:tag "MakeChoice" :contents ["Betray" "West"]}))
(ws/send-msg socket (json/write-str {:tag "MakeChoice" :contents ["Betray" "East"]})))
(defonce socket
(ws/connect
"ws://game.clearercode.com:8000"
:on-receive #(handle (parse %))))
#_(
(ws/send-msg socket "hello")
(ws/close socket)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment