Commits

Steve Losh  committed bd8d3a1

Refactorings, and add farms.

  • Participants
  • Parent commits 61a2626

Comments (0)

Files changed (4)

File src/ruin/buildings.clj

-(ns ruin.buildings)
+(ns ruin.buildings
+  (:use [ruin.util :only [colorize]]))
 
 
 (defonce bid (atom 1))
   (swap! bid inc))
 
 
+(defmulti get-building-sheet :type)
+
+(defmethod get-building-sheet :house [building]
+  (colorize :red ["/`\\"
+                  "|_|"]))
+
+(defmethod get-building-sheet :farm [building]
+  (colorize :yellow ["~~~~~"
+                     "~~~~~"
+                     "~~~~~"]))
+
+(defmethod get-building-sheet :silo [building]
+  (let [middle (if (zero? (:contents building))
+                 \space
+                 \≈)]
+    ["+-+"
+     [\|
+      [middle {:fg :yellow}]
+      \|]
+     "+-+"]))
+
+
 (defn make-house []
   (agent {:id (get-building-id)
           :capacity 4
           :type :house
           :location [(rand-int 50) (rand-int 30)]
-          :size [3 2]
-          :get-sheet (fn [house]
-                       ["/`\\"
-                        "|_|"])}))
+          :size [3 2]}))
 
 (defn make-silo
   ([] (make-silo 0))
            :capacity 50
            :location [(rand-int 50) (rand-int 30)]
            :size [3 3]
-           :get-sheet (fn [silo]
-                        ["+-+"
-                         [\| [(if (zero? (:contents silo))
-                                \space
-                                \≈)
-                              {:fg :yellow}] \|]
-                         "+-+"])
-           :color :yellow
            :type :silo})))
 
+(defn make-farm []
+  (agent {:id (get-building-id)
+          :location [(rand-int 50) (rand-int 30)]
+          :size [5 3]
+          :type :farm}))
+
 
 (defn start-building [b]
   nil)

File src/ruin/core.clj

 (ns ruin.core
   (:use [ruin.state :only [game]]
         [ruin.entities :only [make-person]]
-        [ruin.buildings :only [make-house make-silo]]
+        [ruin.buildings :only [make-house make-silo make-farm]]
         [ruin.ui :only [->UI]]
         [ruin.drawing :only [draw-ui]]
         [ruin.input :only [process-input]])
 (defn create-initial-buildings []
   (into {}
         (concat (gen-things 4 make-house)
+                (gen-things 1 make-farm)
                 (gen-things 2 #(make-silo 25)))))
 
 
   []
   (dosync
     (let [scr (s/get-screen :swing {:cols 120
-                                    :rows 45
+                                    :rows 35
                                     :font "Menlo"
                                     :font-size 16})]
       (ref-set game {:screen scr

File src/ruin/drawing.clj

 (ns ruin.drawing
-  (:use [ruin.state :only [game]])
+  (:use [ruin.state :only [game]]
+        [ruin.buildings :only [get-building-sheet]])
   (:require [lanterna.screen :as s]))
 
 (def SIDEBAR-WIDTH 35)
         map-height rows
         map-width (- cols (inc SIDEBAR-WIDTH))]
     (doseq [building (vals @(:buildings @game))]
-      (let [{:keys [location size get-sheet]} @building
+      (let [{:keys [location size]} @building
             [x y] location
             [width height] size
             vx (- x ox)
                    (<= 0 vx')
                    (< vy map-height)
                    (< vx map-width))
-          (s/put-sheet screen vx vy (get-sheet @building)))))))
+          (s/put-sheet screen vx vy (get-building-sheet @building)))))))
 
 (defn draw-map []
   (let [screen (:screen @game)

File src/ruin/util.clj

 (ns ruin.util)
 
+
+(defn colorize [fg sheet]
+  (map #(for [ch %]
+          [ch {:fg fg}])
+       sheet))
+
 (defn dir-to-offset [dir]
   (case dir
     :w [-1 0]