英语背单词是比较常见的学习APP,参考唐诗宋词应用,本章做一个类似的应用。
一、单词数据清洗及格式转换
诗词数据的获取渠道很多,一般可以按照年级来分文件。如一到九年级,四六级,雅思等等。
1、先从网上某某地方下载单词数据。包含英文,中文,音标。
2、相对唐诗数据,这回我们做复杂一点。包含一个文件头:
文件描述用ENGDC表示
3、同样方法,也可以整理短语数据。
短语不需要音标,且英文部分比较长,所以直接把英语部分扩为32字节
文件描述用ENGCZ表示
4、这样,可以通过宏定位数据位置了
#define dataDC(idx) ((const char*)DataBuff+((idx) * 128) + 64)
#define dataZY(idx) ((const char*)DataBuff+((idx) * 128) + 96)
#define dataCN(idx) ((const char*)DataBuff+((idx) * 128) + 128)
二、增加菜单项
[
{
"t": "三分钟限时挑战",
"i": "-",
"d": 0,
"g": {},
"s": [
{
"t": "语文",
"i": "menu/yuwen.png",
"d": 0,
"g": {},
"s": [
{
"t": "唐诗三百首",
"i": "-",
"d": 302,
"g": {"w":1, "m":1},
"s": []
},
{
"t": "宋词三百首",
"i": "-",
"d": 302,
"g": {"w":1, "m":2},
"s": []
}
]
},
{
"t": "英语",
"i": "menu/eng.png",
"d": 0,
"g": {},
"s": [
{
"t": "根据拼写猜词意",
"i": "-",
"d": 301,
"g": {"w":1, "m":1, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "根据词义猜拼写",
"i": "-",
"d": 301,
"g": {"w":1, "m":2, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜拼写完全正确",
"i": "-",
"d": 301,
"g": {"w":1, "m":3, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜短语意思",
"i": "-",
"d": 301,
"g": {"w":1, "m":4, "f":"project/english8cizu.txt"},
"s": []
},
{
"t": "猜短语拼写",
"i": "-",
"d": 301,
"g": {"w":1, "m":5, "f":"project/english8cizu.txt"},
"s": []
}
]
}
]
},
{
"t": "五十题竞速挑战",
"i": "-",
"d": 0,
"g": {},
"s": [
{
"t": "语文",
"i": "menu/yuwen.png",
"d": 0,
"g": {},
"s": [
{
"t": "唐诗三百首",
"i": "-",
"d": 302,
"g": {"w":2, "m":1},
"s": []
},
{
"t": "宋词三百首",
"i": "-",
"d": 302,
"g": {"w":2, "m":2},
"s": []
}
]
},
{
"t": "英语",
"i": "menu/eng.png",
"d": 0,
"g": {},
"s": [
{
"t": "根据拼写猜词意",
"i": "-",
"d": 301,
"g": {"w":2, "m":1, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "根据词义猜拼写",
"i": "-",
"d": 301,
"g": {"w":2, "m":2, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜拼写完全正确",
"i": "-",
"d": 301,
"g": {"w":2, "m":3, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜短语意思",
"i": "-",
"d": 301,
"g": {"w":2, "m":4, "f":"project/english8cizu.txt"},
"s": []
},
{
"t": "猜短语拼写",
"i": "-",
"d": 301,
"g": {"w":2, "m":5, "f":"project/english8cizu.txt"},
"s": []
}
]
}
]
},
{
"t": "零错误闯关挑战",
"i": "-",
"d": 0,
"g": {},
"s": [
{
"t": "语文",
"i": "menu/yuwen.png",
"d": 0,
"g": {},
"s": [
{
"t": "唐诗三百首",
"i": "-",
"d": 302,
"g": {"w":3, "m":1},
"s": []
},
{
"t": "宋词三百首",
"i": "-",
"d": 302,
"g": {"w":3, "m":2},
"s": []
}
]
},
{
"t": "英语",
"i": "menu/eng.png",
"d": 0,
"g": {},
"s": [
{
"t": "根据拼写猜词意",
"i": "-",
"d": 301,
"g": {"w":3, "m":1, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "根据词义猜拼写",
"i": "-",
"d": 301,
"g": {"w":3, "m":2, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜拼写完全正确",
"i": "-",
"d": 301,
"g": {"w":3, "m":3, "f":"project/english8danci.txt"},
"s": []
},
{
"t": "猜短语意思",
"i": "-",
"d": 301,
"g": {"w":3, "m":4, "f":"project/english8cizu.txt"},
"s": []
},
{
"t": "猜短语拼写",
"i": "-",
"d": 301,
"g": {"w":3, "m":5, "f":"project/english8cizu.txt"},
"s": []
}
]
}
]
},
{
"t": "关于",
"i": "menu/test16.png",
"d": 102,
"g": {},
"s": []
}
]
直接在g属性下面添加一个f属性,表示对应的数据文件。
这里没有分年级,如果分的话,需要再添加一级菜单。
三、生成问题选项
通过菜单,可以看到计划做5种答题模式
1、根据拼写猜词意
2、根据词义猜拼写
3、猜拼写完全正确
4、猜短语意思
5、猜短语拼写
其中第3种模式比较特殊。方法为:
i。挑出两个字母,如 a b
ii。四个选项分别为 ab Ab aB AB
上代码:
void YingYu::createQuestion()
{
currentQuestion->question = ran_max(YingYuCount);
currentQuestion->ans = ran_max(4);
for(u8 i=0;i<4;i++){
if(i == currentQuestion->ans){
currentQuestion->answer[i] = currentQuestion->question;
}else{
currentQuestion->answer[i] = ran_max(YingYuCount);
}
}
if(gameMode == 3){
createQuestionMode3();
}
}
void YingYu::createQuestionMode3()
{
uint8_t i,e1,e2;
char ne1,ne2;
u8 len = strlen(dataDC(currentQuestion->question));
for(i=0; i<4; i++) {
memset(errEngWord[i], 0, 40);
memcpy(errEngWord[i], dataDC(currentQuestion->question), len);
}
e1 = ran_max(len);
while(errEngWord[0][e1] < 97 || errEngWord[0][e1] > 122) {
e1 = ran_max(len);
}
e2 = e1;
while(e2 == e1 || errEngWord[0][e2] < 97 || errEngWord[0][e2] > 122) {
e2 = ran_max(len);
}
ne1 = errEngWord[0][e1] - ran_max(25) -1;
if(ne1 < 97) {
ne1 =ne1 + 26;
}
ne2 = errEngWord[0][e2] - ran_max(25) -1;
if(ne2 < 97) {
ne2 =ne2 + 26;
}
errEngWord[(currentQuestion->ans + 1) % 4][e1] = ne1;
errEngWord[(currentQuestion->ans + 2) % 4][e1] = ne1;
errEngWord[(currentQuestion->ans + 2) % 4][e2] = ne2;
errEngWord[(currentQuestion->ans + 3) % 4][e2] = ne2;
}
四、显示问题选项
几种模式的显示内容是不一样的。需要分别处理
void YingYu::showQuetion()
{
u8 i;
for(i=0;i<4;i++)
Display_Fill_Rectangle2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i]-2, 440, 21 ,answerBGColor[i]);
Display_Fill_Rectangle2(0,100, 480, 80, BLACK);
printf("q=%d, a=%d, a1=%d, a2=%d, a3=%d, a4=%d\n",currentQuestion->question,currentQuestion->ans,currentQuestion->answer[0]
,currentQuestion->answer[1]
,currentQuestion->answer[2]
,currentQuestion->answer[3] );
switch (gameMode) {
case 1:
Display_String(Eng_Quetion_LOC_A, &optionQuetion, dataDC(currentQuestion->question));
Display_String2(Eng_Quetion_LOC_B, &optionZY, "[%s]", dataZY(currentQuestion->question));
for(i=0;i<4;i++)
Display_String2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i], &optionAnswer[i], (const char *)answerTitle[i], dataCN(currentQuestion->answer[i]));
break;
case 2:
Display_String(Eng_Quetion_LOC_A, &optionQuetion, dataCN(currentQuestion->question));
Display_String2(Eng_Quetion_LOC_B, &optionZY, "[%s]", dataZY(currentQuestion->question));
for(i=0;i<4;i++)
Display_String2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i], &optionAnswer[i], (const char *)answerTitle[i], dataDC(currentQuestion->answer[i]));
break;
case 3:
Display_String(Eng_Quetion_LOC_A, &optionQuetion, dataCN(currentQuestion->question));
Display_String2(Eng_Quetion_LOC_B, &optionZY, "[%s]", dataZY(currentQuestion->question));
for(i=0;i<4;i++)
Display_String2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i], &optionAnswer[i], (const char *)answerTitle[i], errEngWord[i]);
break;
case 4:
Display_String(Eng_Quetion_LOC_A, &optionQuetion, dataDC(currentQuestion->question));
for(i=0;i<4;i++)
Display_String2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i], &optionAnswer[i], (const char *)answerTitle[i], dataCN(currentQuestion->answer[i]));
break;
case 5:
Display_String(Eng_Quetion_LOC_A, &optionQuetion, dataCN(currentQuestion->question));
for(i=0;i<4;i++)
Display_String2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i], &optionAnswer[i], (const char *)answerTitle[i], dataDC(currentQuestion->answer[i]));
break;
}
}