wat
author |
Steve Losh <steve@stevelosh.com> |
date |
Wed, 11 Jul 2012 00:52:51 -0400 |
parents |
0e18cc5ab726 |
children |
a208f6298145 |
(ns caves.core
(:use [caves.ui.core :only [->UI]]
[caves.ui.drawing :only [draw-game]]
[caves.ui.input :only [get-input process-input]])
(:require [lanterna.screen :as s]))
; Data Structures -------------------------------------------------------------
(defrecord Game [world uis input])
; Main ------------------------------------------------------------------------
(defn run-game [game screen]
(loop [{:keys [input uis] :as game} game]
(when-not (empty? uis)
(draw-game game screen)
(if (nil? input)
(recur (get-input game screen))
(recur (process-input (dissoc game :input) input))))))
(defn new-game []
(->Game nil [(->UI :start)] nil))
(defn main
([screen-type] (main screen-type false))
([screen-type block?]
(letfn [(go []
(let [screen (s/get-screen screen-type)]
(s/in-screen screen
(run-game (new-game) screen))))]
(if block?
(go)
(future (go))))))
(defn -main [& args]
(let [args (set args)
screen-type (cond
(args ":swing") :swing
(args ":text") :text
:else :auto)]
(main screen-type true)))