Reworked Colorize() into TextColor(), TextBackground() and TextEffect(). Readjusted tables. Added support for multiple meaning kanjis.
This commit is contained in:
parent
111b4641b4
commit
7a4df1d03d
|
@ -16,7 +16,7 @@ function GetTerminalSize()
|
|||
io.write("\027[u")
|
||||
end
|
||||
|
||||
COLORMODE = Enum {
|
||||
EFFECT = Enum {
|
||||
"Normal",
|
||||
"Bold",
|
||||
"Dim",
|
||||
|
@ -48,21 +48,13 @@ COLOR = Enum {
|
|||
"White"
|
||||
}
|
||||
|
||||
function Colorize(Text,Color,Background,Colormode)
|
||||
|
||||
if Colormode then
|
||||
lColormode = "\027["..tostring(Colormode-1).."m"
|
||||
else
|
||||
lColormode = ""
|
||||
end
|
||||
|
||||
if Background then
|
||||
lBackground = "\027[48;5;"..tostring(Background-1).."m"
|
||||
else
|
||||
lBackground = ""
|
||||
end
|
||||
|
||||
lColoredText = "\027[38;5;"..tostring(Color-1).."m"..Text
|
||||
|
||||
return lColormode..lBackground..lColoredText.."\027[0;m"
|
||||
function TextEffect(Text, Effect)
|
||||
return "\027["..tostring(Effect-1).."m"..Text.."\027[0;m"
|
||||
end
|
||||
function TextBackground(Text, Color)
|
||||
return "\027[48;5;"..tostring(Color-1).."m"..Text.."\027[0;m"
|
||||
end
|
||||
|
||||
function TextColor(Text, Color)
|
||||
return "\027[38;5;"..tostring(Color-1).."m"..Text.."\027[0;m"
|
||||
end
|
||||
|
|
|
@ -74,19 +74,19 @@ KanjiData = {
|
|||
},
|
||||
{
|
||||
Symbol = "金",
|
||||
Meaning = "Gold, Money",
|
||||
Meaning = {"Gold", "Money"},
|
||||
On = {"キン","コン"},
|
||||
Kun = {"かね","かな-"}
|
||||
},
|
||||
{
|
||||
Symbol = "空",
|
||||
Meaning = "Sky, Empty",
|
||||
Meaning = {"Sky", "Empty"},
|
||||
On = {"クウ"},
|
||||
Kun = {"そら","から","あ(く)","むな(しい)","す(く)","うつ(ろ)","あだ"}
|
||||
},
|
||||
{
|
||||
Symbol = "月",
|
||||
Meaning = "Moon, Month",
|
||||
Meaning = {"Moon", "Month"},
|
||||
On = {"ゲツ","ガツ"},
|
||||
Kun = {"つき"}
|
||||
},
|
||||
|
@ -278,19 +278,19 @@ KanjiData = {
|
|||
},
|
||||
{
|
||||
Symbol = "先",
|
||||
Meaning = "Previous, Tip",
|
||||
Meaning = {"Previous", "Tip"},
|
||||
On = {"セン"},
|
||||
Kun = {"さき"}
|
||||
},
|
||||
{
|
||||
Symbol = "早",
|
||||
Meaning = "Early, Fast",
|
||||
Meaning = {"Early", "Fast"},
|
||||
On = {"ソウ","サッ"},
|
||||
Kun = {"はや(い)"}
|
||||
},
|
||||
{
|
||||
Symbol = "足",
|
||||
Meaning = "Leg, Sufficient",
|
||||
Meaning = {"Leg", "Sufficient"},
|
||||
On = {"ソク"},
|
||||
Kun = {"あし","た(りる)"}
|
||||
},
|
||||
|
@ -356,7 +356,7 @@ KanjiData = {
|
|||
},
|
||||
{
|
||||
Symbol = "日",
|
||||
Meaning = "Sun, Day",
|
||||
Meaning = {"Sun", "Day"},
|
||||
On = {"ニチ","ジツ"},
|
||||
Kun = {"ひ","-か"}
|
||||
},
|
||||
|
@ -410,7 +410,7 @@ KanjiData = {
|
|||
},
|
||||
{
|
||||
Symbol = "出",
|
||||
Meaning = "Exit, Emerge",
|
||||
Meaning = {"Exit", "Emerge"},
|
||||
On = {"シュツ"},
|
||||
Kun = {"で(る)","だ(す)"}
|
||||
},
|
||||
|
|
|
@ -12,56 +12,70 @@ function GetUnrepeatedKanji(lAvoid)
|
|||
return lKanji
|
||||
end
|
||||
|
||||
function AskMeaning()
|
||||
io.write(Colorize("Q: ",COLOR.HighBlue).."What does "..CurrentKanji.Symbol.." mean? \n")
|
||||
function GetOneFrom(Table)
|
||||
if type(Table) == "table" then
|
||||
return Table[math.random(#Table)]
|
||||
elseif type(Table) == "string" then
|
||||
return Table
|
||||
else
|
||||
return "oopsie"
|
||||
end
|
||||
end
|
||||
|
||||
function AskMeaning4Kanji()
|
||||
CurrentKanji = KanjiData[math.random(#KanjiData)]
|
||||
table.insert(AvoidList,CurrentKanji)
|
||||
|
||||
io.write(TextColor("Q: ",COLOR.HighBlue).."What does "..CurrentKanji.Symbol.." mean? \n")
|
||||
io.write("\n")
|
||||
|
||||
for i=1, 4 do
|
||||
if i == Solution then
|
||||
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..CurrentKanji.Meaning)
|
||||
io.write(TextColor(" ("..i..") ",COLOR.HighYellow)..GetOneFrom(CurrentKanji.Meaning))
|
||||
io.write("\n")
|
||||
else
|
||||
lRandomKanji = GetUnrepeatedKanji(AvoidList)
|
||||
table.insert(AvoidList,lRandomKanji)
|
||||
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..lRandomKanji.Meaning)
|
||||
io.write(TextColor(" ("..i..") ",COLOR.HighYellow)..GetOneFrom(lRandomKanji.Meaning))
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function AskKanji()
|
||||
io.write(Colorize("Q: ",COLOR.HighBlue).."Which is the kanji for \""..CurrentKanji.Meaning.."\"? \n")
|
||||
|
||||
function AskKanji4Meaning()
|
||||
CurrentKanji = KanjiData[math.random(#KanjiData)]
|
||||
table.insert(AvoidList,CurrentKanji)
|
||||
|
||||
io.write(TextColor("Q: ",COLOR.HighBlue).."Which is the kanji for \""..GetOneFrom(CurrentKanji.Meaning).."\"? \n")
|
||||
io.write("\n")
|
||||
|
||||
for i=1, 4 do
|
||||
if i == Solution then
|
||||
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..CurrentKanji.Symbol)
|
||||
io.write(TextColor(" ("..i..") ",COLOR.HighYellow)..CurrentKanji.Symbol)
|
||||
io.write("\n")
|
||||
else
|
||||
lRandomKanji = GetUnrepeatedKanji(AvoidList)
|
||||
table.insert(AvoidList,lRandomKanji)
|
||||
io.write(Colorize(" ("..i..") ",COLOR.HighYellow)..lRandomKanji.Symbol)
|
||||
io.write(TextColor(" ("..i..") ",COLOR.HighYellow)..lRandomKanji.Symbol)
|
||||
io.write("\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function Ask(Type)
|
||||
|
||||
function Ask()
|
||||
local Type = math.random(#QuestionType)
|
||||
Solution = math.random(4)
|
||||
|
||||
AvoidList = {}
|
||||
table.insert(AvoidList,CurrentKanji)
|
||||
|
||||
|
||||
if Type == QuestionType.KANJI then
|
||||
AskKanji()
|
||||
AskKanji4Meaning()
|
||||
elseif Type == QuestionType.MEANING then
|
||||
AskMeaning()
|
||||
AskMeaning4Kanji()
|
||||
end
|
||||
|
||||
io.write("\n")
|
||||
io.write(Colorize("A: ",COLOR.HighPurple))
|
||||
io.write(TextColor("A: ",COLOR.HighPurple))
|
||||
end
|
||||
|
||||
function Check(answer)
|
||||
|
@ -71,13 +85,13 @@ function Check(answer)
|
|||
else
|
||||
io.write("\n")
|
||||
if answer == tostring(Solution) then
|
||||
io.write(Colorize("Correct!",COLOR.HighGreen))
|
||||
io.write(Colorize(" [Streak +1]",COLOR.HighCyan,nil,COLORMODE.BlinkFast))
|
||||
io.write(TextColor("Correct!",COLOR.HighGreen))
|
||||
io.write(TextEffect(TextColor(" [Streak +1]",COLOR.HighCyan),EFFECT.BlinkFast))
|
||||
Streak = Streak + 1
|
||||
Correct = Correct + 1
|
||||
else
|
||||
io.write(Colorize("Wrong!",COLOR.HighRed).." Answer is ("..Solution..")")
|
||||
if Streak >= 5 then io.write(Colorize(" ["..Streak.." Streak Lost]",COLOR.Cyan,nil,COLORMODE.BlinkFast)) end
|
||||
io.write(TextColor("Wrong!",COLOR.HighRed).." Answer is ("..Solution..")")
|
||||
if Streak >= 5 then io.write(TextEffect(TextColor(" ["..Streak.." Streak Lost]",COLOR.Cyan),EFFECT.BlinkFast)) end
|
||||
Streak = 0
|
||||
Wrong = Wrong + 1
|
||||
end
|
||||
|
@ -90,21 +104,22 @@ end
|
|||
|
||||
QuestionType = Enum {
|
||||
"KANJI",
|
||||
"MEANING",
|
||||
"ON",
|
||||
"KUN"
|
||||
"MEANING"
|
||||
}
|
||||
|
||||
function ShowProgress()
|
||||
io.write("#"..tostring(Total+1).."\t")
|
||||
io.write("\027[2K#"..tostring(Total+1).."\t")
|
||||
|
||||
io.write("Right: "..Colorize(tostring(Correct),COLOR.HighGreen).."\t")
|
||||
io.write("Wrong: "..Colorize(tostring(Wrong),COLOR.HighRed).."\t")
|
||||
io.write("Right: "..TextColor(tostring(Correct),COLOR.HighGreen).."\t")
|
||||
io.write("Wrong: "..TextColor(tostring(Wrong),COLOR.HighRed).."\t")
|
||||
|
||||
if Streak >= 5 then
|
||||
io.write(Colorize("CURRENT STREAK: ", COLOR.HighCyan,nil,COLORMODE.BlinkFast)..Colorize(Streak,COLOR.White,nil,COLORMODE.BlinkFast))
|
||||
io.write(
|
||||
TextEffect(TextColor("CURRENT STREAK: ", COLOR.HighCyan),EFFECT.BlinkFast)..
|
||||
TextEffect(TextColor(Streak,COLOR.White),EFFECT.BlinkFast)
|
||||
)
|
||||
end
|
||||
io.write(" \n\n")
|
||||
io.write("\n")
|
||||
end
|
||||
|
||||
function UpdateProgress()
|
||||
|
@ -121,16 +136,15 @@ Wrong = 0
|
|||
math.randomseed(os.time())
|
||||
while 1 do
|
||||
os.execute("clear")
|
||||
|
||||
CurrentKanji = KanjiData[math.random(#KanjiData)]
|
||||
|
||||
ShowProgress()
|
||||
|
||||
--Ask(math.random(#QuestionType))
|
||||
Ask(math.random(2))
|
||||
--Ask()
|
||||
Ask()
|
||||
--Ask(QuestionType.KANJI)
|
||||
|
||||
response = io.read()
|
||||
|
||||
Check(response)
|
||||
end
|
||||
os.execute("clear")
|
Loading…
Reference in New Issue