I'm trying to implement a snake game using om. When the snake bites itself, I write a text saying GAMEOVER and I change the class for the svg rectangles that constitute the snake (to change its color). The problem is that the results I get are very different in the three browsers I use:
- On Safari, all works as intended. - On Chrome, the text is shown but the snake does not change its color. - On Firefox neither the message nor the color change happens. The code for the om componets is but you can access the github repository at https://github.com/jmgimeno/om-snake: (defn cell [[[x y] type] _] (reify om/IRender (render [_] (dom/rect #js {:x (* x size) :y (* y size) :height size :width size :className type})))) (defn world [{:keys [food snake dead]} _] (reify om/IRender (render [_] (let [foodcell [food "food"] snakestyle (if dead "dead" "alive") snakecells (map #(vector % snakestyle) snake) allcells (cons foodcell snakecells)] (apply dom/svg #js {:width (* width size) :height (* height size)} (om/build-all cell allcells)))))) (defn root [state _] (reify om/IWillMount (will-mount [_] (let [keyboard-channel (listen js/window "keydown")] (go (loop [step-channel (timeout plank)] (alt! keyboard-channel ([e c] (when-let [direction (keycode->direction (.-keyCode e))] (om/update! state [:direction] direction)) (recur step-channel)) step-channel ([e c] (when-not (:dead @state) (om/transact! state game-step) (recur (timeout plank))))))))) om/IRender (render [_] (dom/div nil (dom/h1 nil "Welcome to Snake !!") (dom/p nil (str "Snake length: " (count (:snake state)) (when (:dead state) " ENDGAME !!"))) (om/build world state))))) (om/root root app-state {:target (. js/document (getElementById "app"))}) Thanks ! Juan Manuel -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/clojurescript.
