Last active
August 29, 2015 14:14
-
-
Save Zolomon/f18666ff373e895be5e2 to your computer and use it in GitHub Desktop.
Russian Language Quiz Data File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns quiz.colour.colour) | |
(defn clear-screen | |
([] "\033c") | |
([text] (str "\033c" text))) | |
(defn bold | |
([] "\\e[1m") | |
([text] (str "\\e[1m" text))) | |
;; (defn dim | |
;; ([] "\e[2m" ) | |
;; ( [text] (str "\e[2m" text))) | |
;; (defn underlined | |
;; ([] "\e[4m") | |
;; ([text] (str "\e[4m" text))) | |
;; (defn blink | |
;; ([] "\e[5m") | |
;; ([text] (str "\e[5m" text))) | |
;; (defn reverse | |
;; ([] "\e[7m") | |
;; ([text] (str "\e[7m" text))) | |
;; (defn hidden | |
;; ([] "\e[8m") | |
;; ([text] (str "\e[8m" text))) | |
;; (defn fg-default | |
;; ([] "\e[39m") | |
;; ([text] (str "\e[39m"))) | |
;; (defn fg-red | |
;; ([] "\e[31m") | |
;; ([text] (str "\e[31m"))) | |
;; (defn fg-blue | |
;; ([] "\e[34m") | |
;; ([text] (str "\e[34m"))) | |
;; (defn fg-green | |
;; ([] "\e[33m") | |
;; ([text] (str "\e[33m"))) | |
;; (defn fg-magenta | |
;; ([] "\e[35m") | |
;; ([text] (str "\e[35m"))) | |
;; (defn fg-cyan | |
;; ([] "\e[36m") | |
;; ([text] (str "\e[36m"))) | |
;; (defn fg-light-gray | |
;; ([] "\e[37m") | |
;; ([text] (str "\e[37m"))) | |
;; (defn fg-dark-gray | |
;; ([] "\e[90m") | |
;; ([text] (str "\e[90m"))) | |
;; (defn fg-light-red | |
;; ([] "\e[91m") | |
;; ([text] (str "\e[91m"))) | |
;; (defn fg-light-green | |
;; ([] "\e[92m") | |
;; ([text] (str "\e[92m"))) | |
;; (defn fg-light-yellow | |
;; ([] "\e[93m") | |
;; ([text] (str "\e[93m"))) | |
;; (defn fg-light-blue | |
;; ([] "e[94m") | |
;; ([text] (str "e[94m"))) | |
;; (defn fg-light-magenta | |
;; ([] "e[95m") | |
;; ([text] (str "e[95m"))) | |
;; (defn fg-light-cyan | |
;; ([] "e[96m") | |
;; ([text] (str "e[96m"))) | |
;; (defn fg-light-white | |
;; ([] "e[977m") | |
;; ([text] (str "e[977m"))) | |
;; (defn bg-red | |
;; ([] "e[31m") | |
;; ([text] (str "e[31m"))) | |
;; (defn bg-blue | |
;; ([] "e[34m") | |
;; ([text] (str "e[34m"))) | |
;; (defn bg-green | |
;; ([] "e[33m") | |
;; ([text] (str "e[33m"))) | |
;; (defn bg-magenta | |
;; ([] "e[35m") | |
;; ([text] (str "e[35m"))) | |
;; (defn bg-cyan | |
;; ([] "e[36m") | |
;; ([text] (str "e[36m"))) | |
;; (defn bg-light-gray | |
;; ([] "e[37m") | |
;; ([text] (str "e[37m"))) | |
;; (defn bg-dark-gray | |
;; ([] "e[90m") | |
;; ([text] (str "e[90m"))) | |
;; (defn bg-light-red | |
;; ([] "e[91m") | |
;; ([text] (str "e[91m"))) | |
;; (defn bg-light-green | |
;; ([] "e[92m") | |
;; ([text] (str "e[92m"))) | |
;; (defn bg-light-yellow | |
;; ([] "e[93m") | |
;; ([text] (str "e[93m"))) | |
;; (defn bg-light-blue | |
;; ([] "e[94m") | |
;; ([text] (str "e[94m"))) | |
;; (defn bg-light-magenta | |
;; ([] "e[95m") | |
;; ([text] (str "e[95m"))) | |
;; (defn bg-light-cyan | |
;; ([] "e[96m") | |
;; ([text] (str "e[96m"))) | |
;; (defn bg-light-white | |
;; ([] "e[977m") | |
;; ([text] (str "e[977m"))) | |
;; (defn reset | |
;; ([] "\e[0m") | |
;; ([text] (str "\e[0m"))) | |
;; (defn reset-bold-bright | |
;; ([] "\e[1m") | |
;; ([text] (str "\e[1m"))) | |
;; (defn reset-dim | |
;; ([] "\e[2m") | |
;; ([text] (str "\e[0m"))) | |
;; (defn reset-underlined [text] (str "\e[0m")) | |
;; (defn reset-blink | |
;; ([] "\e[0m") | |
;; ([text] (str "\e[0m"))) | |
;; (defn reset-reverse | |
;; ([] "\e[0m") | |
;; ([text] (str "\e[0m"))) | |
;; (defn reset-hidden | |
;; ([] "\e[0m") | |
;; ([text] (str "\e[0m"))) | |
;; (defn reset [text] (str "\e[0m")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns quiz.core | |
(require [clojure.data.json :as json] | |
[clojure.core.match :refer [match]] | |
) | |
(:gen-class)) | |
(require 'quiz.colour.colour) | |
(def quiz (json/read-json (slurp "./resources/json/russian.json"))) | |
(defn quiz-pack? | |
"Checks whether the specified language-pack exists" | |
[name] | |
(some #(= (clojure.string/lower-case %) (clojure.string/lower-case name)) | |
(map #(clojure.string/lower-case (:title %)) (:packages quiz)))) | |
(defn get-question-nbr | |
[nbr] | |
(get quiz nbr)) | |
(defn get-random-question | |
"Retrieves a random question from the supplied package data." | |
[data] | |
(get data (rand-int (count data)))) | |
(defn get-pack-title | |
"Returns the title of the current quiz package." | |
[pack] | |
(str "\t * " (clojure.string/lower-case (get pack :title)))) | |
(defn get-language-title | |
"Gets the name of the current language. | |
Example: \"Russian Language Quiz\"" | |
[] | |
(:name quiz)) | |
(defn get-package | |
"Gets the asked for package, or ()." | |
[package] | |
(filter #(= (clojure.string/lower-case (:title %)) | |
(clojure.string/lower-case package)) | |
(:packages quiz))) | |
(defn get-package-data | |
[package] | |
(get-in (get-package package) [:data 0])) | |
(defn get-questions | |
[package] | |
(let [data (get-in (first (get-package package)) [:questions 0 :data]), | |
descriptions (first data), | |
questions (drop 1 data)] | |
{:data data :descriptions descriptions :questions questions})) | |
(defn start-game-session | |
[package] | |
(loop [state :start-game questions (shuffle (:data (get-questions package)))] | |
(println (str "Count is now: " (count questions))) | |
(match [state] | |
[:start-game] (do (clear-screen) | |
(println questions) | |
(println (str "New question: " (get-in questions [0]))) | |
(println (str "Question: " (get-in questions [0 (keyword "russian small letter")]))) | |
(println (str "Answer: " (get-in questions [0 (keyword "english letter")]))) | |
(println "Please enter your answer: ") | |
(let [answer (read-line)] | |
(println (str "You wrote: " answer)) | |
(cond | |
(= answer (get-in questions [0 (keyword "english letter")])) | |
(do (println "Correct!") | |
(recur :start-game (drop 1 questions))) | |
:else (recur :start-game questions))))))) | |
(defn play-quiz | |
[package] | |
(loop [package package] | |
(clear-screen) | |
(start-game-session package))) | |
(def menu | |
(apply concat [[(get-language-title) | |
"" | |
"Available packs: "] | |
(into [] (map get-pack-title (:packages quiz))) | |
["Please choose a package: "]])) | |
(defn main-loop | |
[state prevState] | |
(loop [state state prevState prevState] | |
(match [state] | |
[:menu] (do (clear-screen) | |
(doall (map println menu)) | |
(recur :menu-select :menu)) | |
[:menu-select] (do | |
(let [x (read-line)] | |
(if (quiz-pack? (clojure.string/lower-case x)) | |
(do (println (str "You chose: " x)) | |
(play-quiz x) | |
(recur :menu :menu-select))))) | |
:else (do (println "ERROR, wrong approach") | |
(recur :state prevState))))) | |
(defn -main | |
"Run the quiz!" | |
[& args] | |
(println "Quiz v0.0.0") | |
(main-loop :menu :menu) | |
(println "Goodbye!")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name":"Russian Language Quiz", | |
"packages":[ | |
{ | |
"title": "Vocabulary", | |
"questions": [ | |
{ | |
"description": [ | |
"english word", | |
"russian word" | |
], | |
"data": [ | |
{ | |
"english word": "five", | |
"russian word": "Пять" | |
} | |
] | |
} | |
] | |
} | |
{ | |
"title":"Alphabet", | |
"questions":[ | |
{ | |
"description":[ | |
"phonetics", | |
"russian small letter", | |
"russian large letter", | |
"english letter" | |
], | |
"data":[ | |
{ | |
"phonetics":"a", | |
"russian small letter":"а", | |
"russian large letter":"А", | |
"english letter":"a" | |
}, | |
{ | |
"phonetics":"b", | |
"russian small letter":"б", | |
"russian large letter":"Б", | |
"english letter":"b" | |
}, | |
{ | |
"phonetics":"v", | |
"russian small letter":"в", | |
"russian large letter":"В", | |
"english letter":"v" | |
}, | |
{ | |
"phonetics":"g", | |
"russian small letter":"г", | |
"russian large letter":"Г", | |
"english letter":"g" | |
}, | |
{ | |
"phonetics":"d", | |
"russian small letter":"д", | |
"russian large letter":"Д", | |
"english letter":"d" | |
}, | |
{ | |
"phonetics":"je", | |
"russian small letter":"е", | |
"russian large letter":"Е", | |
"english letter":"je" | |
}, | |
{ | |
"phonetics":"jo", | |
"russian small letter":"ё", | |
"russian large letter":"Ё", | |
"english letter":"jo" | |
}, | |
{ | |
"phonetics":"ʐ", | |
"russian small letter":"ж", | |
"russian large letter":"Ж", | |
"english letter":"zh" | |
}, | |
{ | |
"phonetics":"z", | |
"russian small letter":"з", | |
"russian large letter":"З", | |
"english letter":"z" | |
}, | |
{ | |
"phonetics":"i", | |
"russian small letter":"и", | |
"russian large letter":"И", | |
"english letter":"i" | |
}, | |
{ | |
"phonetics":"j", | |
"russian small letter":"й", | |
"russian large letter":"Й", | |
"english letter":"j" | |
}, | |
{ | |
"phonetics":"k", | |
"russian small letter":"к", | |
"russian large letter":"К", | |
"english letter":"k" | |
}, | |
{ | |
"phonetics":"l", | |
"russian small letter":"л", | |
"russian large letter":"Л", | |
"english letter":"l" | |
}, | |
{ | |
"phonetics":"m", | |
"russian small letter":"м", | |
"russian large letter":"М", | |
"english letter":"m" | |
}, | |
{ | |
"phonetics":"n", | |
"russian small letter":"н", | |
"russian large letter":"Н", | |
"english letter":"n" | |
}, | |
{ | |
"phonetics":"o", | |
"russian small letter":"о", | |
"russian large letter":"О", | |
"english letter":"o" | |
}, | |
{ | |
"phonetics":"p", | |
"russian small letter":"п", | |
"russian large letter":"П", | |
"english letter":"p" | |
}, | |
{ | |
"phonetics":"r", | |
"russian small letter":"р", | |
"russian large letter":"Р", | |
"english letter":"r" | |
}, | |
{ | |
"phonetics":"s", | |
"russian small letter":"с", | |
"russian large letter":"С", | |
"english letter":"s" | |
}, | |
{ | |
"phonetics":"t", | |
"russian small letter":"т", | |
"russian large letter":"Т", | |
"english letter":"t" | |
}, | |
{ | |
"phonetics":"u", | |
"russian small letter":"у", | |
"russian large letter":"У", | |
"english letter":"u" | |
}, | |
{ | |
"phonetics":"f", | |
"russian small letter":"ф", | |
"russian large letter":"Ф", | |
"english letter":"f" | |
}, | |
{ | |
"phonetics":"x", | |
"russian small letter":"х", | |
"russian large letter":"Х", | |
"english letter":"x" | |
}, | |
{ | |
"phonetics":"ts", | |
"russian small letter":"ц", | |
"russian large letter":"Ц", | |
"english letter":"ts" | |
}, | |
{ | |
"phonetics":"tɕ", | |
"russian small letter":"ч", | |
"russian large letter":"Ч", | |
"english letter":"ch" | |
}, | |
{ | |
"phonetics":"ʂ", | |
"russian small letter":"ш", | |
"russian large letter":"Ш", | |
"english letter":"sh" | |
}, | |
{ | |
"phonetics":"ɕː", | |
"russian small letter":"щ", | |
"russian large letter":"Щ", | |
"english letter":"shch" | |
}, | |
{ | |
"phonetics":"-", | |
"russian small letter":"ъ", | |
"russian large letter":"Ъ", | |
"english letter":"\"" | |
}, | |
{ | |
"phonetics":"ɨ", | |
"russian small letter":"ы", | |
"russian large letter":"Ы", | |
"english letter":"y" | |
}, | |
{ | |
"phonetics":"ʲ", | |
"russian small letter":"ь", | |
"russian large letter":"Ь", | |
"english letter":"'" | |
}, | |
{ | |
"phonetics":"e", | |
"russian small letter":"э", | |
"russian large letter":"Э", | |
"english letter":"e" | |
}, | |
{ | |
"phonetics":"ju", | |
"russian small letter":"ю", | |
"russian large letter":"Ю", | |
"english letter":"ju" | |
}, | |
{ | |
"phonetics":"ja", | |
"russian small letter":"я", | |
"russian large letter":"Я", | |
"english letter":"ja" | |
} | |
] | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment