I'm building a game with re-frame and shadowcljs. Here is my code. I want the list of…
- User
I'm building a game with re-frame and shadowcljs. Here is my code. I want the list of words that the player has found to be in a box on the right side of the screen.
(ns spelling-bee.core (:require
[clojure.set :as set] [clojure.string :as str] [re-frame.core :as rf] [reagent.dom :as rdom] [stylefy.core :as stylefy :refer [use-style]] [stylefy.reagent :as stylefy-reagent]))
(def debug? ^boolean goog.DEBUG)
;---------- our app state atom ----------
(def default-db {:name "default" :game-started false :words #{} :common-letter #{} :letters #{} :display-letters [] :found-words #{} :current-input "" :message "" :score 0})
;---------- various functions ----------
;; Later this can be substituted with a database call to pull a list of words. (def word-collection #{"babyproof" "afar" "affray" "afro" "arbor" "array" "arroyo" "barb" "barf" "boar" "boor" "bray" "farro" "fora" "foray" "fray" "parry" "poor" "pray" "proof" "prop" "pyro" "roar" "roof" "ropy"})
(defn get-unique-letter-collection [word-set] (-> word-set vec str/join seq set))
(defn find-common-letter [word-set] (reduce set/intersection (map set (seq word-set))))
(defn word-validity-case [word letters common-letter] (cond (contains? word-collection word) :submit-ok ; first check if the word is in the word-collection (> 4 (count (seq word))) :too-short ; check length, notify if less than 3 letters (not (every? letters (set word))) :invalid ; check if every letter in the word is in letters set (not (contains? (set word) (first common-letter))) :no-common ; if it does not contain the common letter (contains? (set word) (first common-letter)) :not-in-list ; then check if the word at least contains common letter :else :other)) ; generic if it somehow manages to not match one of the above
(defn point-formula [word letters] (cond (= (get-unique-letter-collection word) (set letters)) (+ (count (seq word)) 7) (= (count (seq word)) 4) (int 1) :else (count (seq word))))
;---------- subscriptions to data from app state ----------
(rf/reg-sub ::name (fn [db] (:name db)))
(rf/reg-sub ::game-started (fn [db] (:game-started db)))
(rf/reg-sub ::words (fn [db] (:words db)))
(rf/reg-sub ::found-words (fn [db] (:found-words db)))
(rf/reg-sub ::common-letter (fn [db] (:common-letter db)))
(rf/reg-sub ::letters (fn [db] (:letters db)))
(rf/reg-sub ::display-letters (fn [db] (:display-letters db)))
(rf/reg-sub ::current-input (fn [db] (:current-input db)))
- Assistant
To place a box on the right side of the screen with the list of words that the player has found, you'll need to update your component that renders the main content to separate it into two sections. One section for the game and another for the box with the found words. You can use CSS Flexbox or Grid to achieve this layout.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.