Skip to content

Instantly share code, notes, and snippets.

Created December 23, 2011 23:22
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 anonymous/1515646 to your computer and use it in GitHub Desktop.
Save anonymous/1515646 to your computer and use it in GitHub Desktop.
(defn make-map-console [gamemap]
"Makes a map console, which redraws the map every time it is repainted,
and has a default black background."
(doto (proxy [JPanel] []
(paintComponent [g]
(proxy-super paintComponent g)
(doto g
(.setFont *font*)
(.setColor Color/white)
(.darwString "bla" 10 10))))
(.setBackground Color/black)))
(defn make-main-window []
"Makes the main window for the aplication.
Closing this window will end the game"
(doto (JFrame. *title*)
(.setSize *window-heigth* *window-width*)
;(.setResizable false)
(.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
(.setVisible true)
(.pack)))
(defn setup-UI [map]
"Creates the main window and the console on which the map is drawn,
then adds the console to the main window.
A watch is added to the map which makes the console redraw the map
every time it changes"
(let [main-window (make-main-window)
console (make-map-console map)
input (atom nil)]
(.add main-window console)
(add-watch map ::redraw-on-map-change (fn [_ _ _ _] (.repaint console)))
(set-key-bindings main-window input)
(.repaint console)
input))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment