W801学习笔记二十三:语文和英语学习应用的代码汇总

前面几章,代码经过重构,可能有点乱。这里给个最终版本,以供参考。

1、应用基类:

IScean.h

enum SceanResult{
	SceanResult_EXIT = 1, 
	SceanResult_Done = 2	
};

class IScean {
	public:
		IScean();
		virtual ~IScean();
		// 纯虚函数
		virtual SceanResult tick(u32 ticks) = 0;
		virtual int scean_init(cJSON* param) {return 0;};
		virtual int scean_resume(void){return 0;};
		virtual int scean_pause(void){return 0;};
	protected:
		map_t iconMap = NULL;
		unsigned char* getImageResource(char* fn);
};

IScean.cpp

int iterate(any_t item, any_t data){
	psram_heap_free((unsigned char *)data);
    return MAP_OK;
}


IScean::IScean(){
	iconMap = hashmap_new();
}

IScean::~IScean(){
	any_t val;
	hashmap_iterate(iconMap, iterate, val);
	hashmap_free(iconMap);
}

unsigned char* IScean::getImageResource(char* fn){
	
	int error;
	unsigned int w,h;
	unsigned char *val;
	error= hashmap_get(iconMap, fn, (void**)(&val));
	
	if(error == MAP_MISSING){
		lodepng_decode32_file(&val, &w, &h, fn);
		hashmap_put(iconMap, fn, val);
	}
	return val;
}

2、学习基类,继承应用基类:

StudyBase.h

class StudyBase : public IScean
{
	public:
		StudyBase(){};
		virtual ~StudyBase(){};
protected:
		u8 gameMode=0;
		u8 winMode=0;
		u8 isFinished=0;
		u16 correntCount =0;
		u16 wrongCount = 0;
		u32 totalTime=0;
		u32 lastTotalTime=0;
   //×○△□
		const char *controlInfo="EXIT: 返回     SELECT: 重新开始";
		const char *answerInfo="× 选择    ○ 选择    □ 选择    △ 选择";

		u16 answerBGColor[4] = {DBLUE, DRED, DGREEN, BROWN }; 
		
		void startPrepare();
		void errorDelay(u8 t);
		u8 checkFinish();
		void showScore();
		void showTime();
		
		u8 answerTitle[4][8] = {
			{0x20,0xA1,0xC1,0x20,0x25,0x73,0x20, 0x0}, // × %s ,
			{0x20,0xA1,0xF0,0x20,0x25,0x73,0x20, 0x0},
			{0x20,0xA1,0xF5,0x20,0x25,0x73,0x20, 0x0},
			{0x20,0xA1,0xF7,0x20,0x25,0x73,0x20, 0x0}}; 
		
private:
		DisplayOption optionScore = {FONT_SIZE_1516, YELLOW, BLACK, 0, 0};
		DisplayOption optionCorrentCount = {FONT_SIZE_1516, GREEN, BLACK, 0, 0};
		DisplayOption optionWrongCount = {FONT_SIZE_1516, RED, BLACK, 0, 0};
		DisplayOption optionTime = {FONT_SIZE_1516, YELLOW, BLACK, 0, 0};
		DisplayOption optionDeCount = {FONT_SIZE_3232, WHITE, DRED, 1, 0};
		
		DisplayOption optionDelay = {FONT_SIZE_2424, WHITE, DRED, 0, 0};
		
		void finish();

};

StudyBase.cpp


#define Prepare_LOC  240, 100


void StudyBase::startPrepare(){
	isFinished =0;
	correntCount =0;
	wrongCount = 0;
	totalTime=0;
	lastTotalTime=0;

	clear_screen();
	optionDeCount.backColor = DRED;
	Display_String(Prepare_LOC, &optionDeCount, "  3  ");
	tls_os_time_delay(1000);
	optionDeCount.backColor = BROWN;
	Display_String(Prepare_LOC, &optionDeCount, "  2  ");
	tls_os_time_delay(1000);
	optionDeCount.backColor = DGREEN;
	Display_String(Prepare_LOC, &optionDeCount, "  1  ");
	tls_os_time_delay(1000);
	Display_Fill_Rectangle(0, 100, 480, 170 ,BLACK);

}

void StudyBase::errorDelay(u8 t){
	for(;t>0;t--){
		Display_String2(400, 50, &optionDelay,"  %d  ",t);
		tls_os_time_delay(1000);
	}
	Display_Fill_Rectangle2(400, 50, 80, 80, BLACK);
}


u8 StudyBase::checkFinish(){
	switch (winMode) {
		case 1:
		if(totalTime > 180000) {
			finish();
			return 1;
		}
		break;
		case 2:
		if(correntCount+ wrongCount == 50) {
			finish();
			return 1;
		}
		break;
		case 3:
		if(wrongCount>0) {
			finish();
			return 1;
		}
		break;
	}
	return 0;
}

void StudyBase::finish(){
	isFinished = 1;
	show_status_info(controlInfo);
	optionDeCount.backColor = DBLUE;
	Display_String(Prepare_LOC, &optionDeCount, "   挑 战 结 束   ");
}


void StudyBase::showScore()
{
	int score = correntCount* 60 - wrongCount * 20;
	if(score<0 ) score =0;
	Display_String2(10, 5, &optionScore, "得分: %06d ", score);
	Display_String2(150, 5, &optionCorrentCount, "正确: %04d ", correntCount);
	Display_String2(270, 5, &optionWrongCount, "错误: %04d ", wrongCount);
}

void StudyBase::showTime()
{
	if(lastTotalTime == totalTime/1000){
		return;
	}
	lastTotalTime = totalTime/1000;
		
	if(winMode == 2)
		Display_String2(400, 5, &optionTime, "%02d:%02d", ((180000- totalTime) / 1000) / 60, ((180000- totalTime) / 1000) % 60);
	else
		Display_String2(400, 5, &optionTime, "%02d:%02d", (totalTime / 1000) / 60, (totalTime / 1000) % 60);	
}

3、语文学习类,继承学习基类:

YuWenTS.h

typedef struct {
	uint16_t question; //问题诗索引
	uint8_t line;  //问题句子所在的行
    u16 answer [4];  // 4个选项对应的行
	uint8_t ans;  //正确选项
	
} TangShiQuestion;

#define TangshiBoxStartX 10
#define TangshiBoxStartY 80
#define TangshiBoxWidth 280
#define TangshiBoxHeight 200
#define TangshiBoxLineHeight 20

class YuWenTS : public StudyBase
{
   public:
      YuWenTS();   
      ~YuWenTS();  
		SceanResult tick(u32 ticks);
		int scean_init(cJSON*  param);
   private:
		void start();
		
		void createTSQuestion();
		void showTSQuetion();
		void showTSAnswer();
		void createSCQuestion();
		void showSCQuetion();
		void showSCAnswer();
		
		void showTangshi();
		void showSongCi();
		
		void correct();
		void wrong();
		TangShiQuestion *currentQuestion;
		
		int offsetY=0;
		u16 boxHeight =0;

		u16 answerX;
		u16 answerY;
		u16 answerIdx;

		DisplayOption optionQuetion = {FONT_SIZE_2424, LIGHTBLUE, BLACK, 0, 1};
		DisplayOption optionZY = {FONT_SIZE_1516, GRAYBLUE, BLACK, 0, 1};
		DisplayOption optionLines = {FONT_SIZE_1516, WHITE, BLACK, 0, 1};
		DisplayOption optionMiss = {FONT_SIZE_1516, RED, DGRAY, 0, 1};
		DisplayOption optionAnswer[4] = {
			{FONT_SIZE_1516, WHITE, answerBGColor[0], 0, 1},
			{FONT_SIZE_1516, WHITE, answerBGColor[1], 0, 1},
			{FONT_SIZE_1516, WHITE, answerBGColor[2], 0, 1},
			{FONT_SIZE_1516, WHITE, answerBGColor[3], 0, 1},
			};  
		
		u16 answerLocX = 300;
		u16 answerLocY[4] = {165, 200, 235, 270};
		
		unsigned char *DataBuff;
		unsigned char *DataBuffIndex;
		
		u16 YuWenCount;
		u16 YuWenItemCount;
		
};

YuWenTS.cpp

#define YUW_Quetion_LOC_A  20, 25
#define YUW_Quetion_LOC_B  170, 55


//读取数据指定行
#define dataLine(idx) ((const char*)DataBuff+((idx) * 64))
//获取索引指定诗所在数据行数
#define dataLineIdx(idx) (((u16*)DataBuffIndex)[(idx)*2+2])
//获取索引指定诗句子总数
#define dataLineCount(idx) (((u16*)DataBuffIndex)[(idx)*2+3])

//获取指定诗指定句子所在行数
#define TangshiLineIdx(x,y)  (dataLineIdx(x)+ y + 2 )
//获取指定诗指定句子所在数据位置
#define TangshiLine(x,y)  (dataLine(dataLineIdx(x)+ y + 2 ))
//获取指定诗标题所在数据位置
#define TangshiLineTitle(x)  (dataLine(dataLineIdx(x)))
//获取指定诗作者所在数据位置
#define TangshiLineAuthor(x)  (dataLine(dataLineIdx(x)+ 1))


YuWenTS::YuWenTS(){
	currentQuestion = new TangShiQuestion();
} 

YuWenTS::~YuWenTS(){
	delete currentQuestion;
	psram_heap_free((void*)DataBuff);
	
}  

int YuWenTS::scean_init(cJSON*  param){
	setKeyAdepterIntervalAll(200);
	setKeyAdepterInterval(KEY_GPIO_A, 65535);
	setKeyAdepterInterval(KEY_GPIO_B, 65535);
	setKeyAdepterInterval(KEY_GPIO_C, 65535);
	setKeyAdepterInterval(KEY_GPIO_D, 65535);
	
	winMode= cJSON_GetObjectItem(param,"w")->valueint;
    gameMode = cJSON_GetObjectItem(param,"m")->valueint;
	
	printf("start chinese. winMode=%d, gameMode=%d.\n", winMode, gameMode);

	switch (gameMode) {
	case 1: // 唐诗300
		fatfs_readFile("project/tangshi300gb.txt", &DataBuff);
		fatfs_readFile("project/tangshi300index.txt", &DataBuffIndex);
		YuWenCount = dataLineIdx(-1);
		YuWenItemCount= dataLineCount(-1);
		break;
	case 2: // 宋词300
		fatfs_readFile("project/songci300gb.txt", &DataBuff);
		fatfs_readFile("project/songci300index.txt", &DataBuffIndex);
		YuWenCount = dataLineIdx(-1);
		YuWenItemCount= dataLineCount(-1);
		break;
	}
	start();
	return 0;
}

SceanResult YuWenTS::tick(u32 ticks){
	if(KEY_EXIT) {
		printf("goto top menu from About.\n");
		return SceanResult_EXIT;
	}
	if(isFinished){
		if(KEY_SEL) {
			start();
			return SceanResult_Done;
		}
	
	}else{
		totalTime+=ticks;
		showTime();

		if(checkFinish()){
			return SceanResult_Done;
		}
		
		if(KEY_A | KEY_B | KEY_C | KEY_D){
			if(KEY_A && currentQuestion->ans == 0){
				correct();
				return SceanResult_Done;
			}
			if(KEY_B && currentQuestion->ans == 1){
				correct();
				return SceanResult_Done;
			}
			if(KEY_C && currentQuestion->ans == 2){
				correct();
				return SceanResult_Done;
			}
			if(KEY_D && currentQuestion->ans == 3){
				correct();
				return SceanResult_Done;
			}
			wrong();
		}

		if(KEY_UP && boxHeight> TangshiBoxHeight){
			int oy = offsetY;
			if(offsetY<0 ){
				offsetY +=TangshiBoxLineHeight;
			}else{
				offsetY =0;
			}
			if(oy !=offsetY )
			showTangshi();
		}
		
		if(KEY_DOWN && boxHeight> TangshiBoxHeight){
			int oy = offsetY;
			if(offsetY > TangshiBoxHeight - boxHeight)	{
				offsetY -=TangshiBoxLineHeight;
			}else{
				offsetY = TangshiBoxHeight - boxHeight;
			}
			if(oy !=offsetY )
			showTangshi();
			
		}
		
		ran_max(10);
	}
	return SceanResult_Done;
}

void YuWenTS::showTSAnswer(){
	Display_String(answerX, answerY, &optionMiss, dataLine(answerIdx));
	for(int i=0;i<4;i++)
	if(currentQuestion->ans !=i)
		Display_Fill_Rectangle2(answerLocX, answerLocY[i]-2, SCREEN_WIDTH - answerLocX, 21 ,BLACK);	
}

void YuWenTS::correct(){
	correntCount++;
	showScore();
	if(checkFinish()==0){
		createTSQuestion();
		showTSQuetion();
		showTangshi();
	}
}

void YuWenTS::wrong(){
	wrongCount++;
	showScore();
	showTSAnswer();
	errorDelay(3);
	if(checkFinish()==0){
		createTSQuestion();
		showTSQuetion();
		showTangshi();	
	}
}

void YuWenTS::start(){
	startPrepare();
	show_status_info(answerInfo);
	showScore();

	createTSQuestion();
	showTSQuetion();
	showTangshi();
}


void YuWenTS::createTSQuestion()
{
	u8 len=0;
	offsetY=0;
	do{
		currentQuestion->question = ran_max(YuWenCount);
		currentQuestion->line = ran_max(dataLineCount(currentQuestion->question));
		len = strlen(TangshiLine(currentQuestion->question, currentQuestion->line));
	}while(len < 15 || len > 25);
	currentQuestion->ans = ran_max(4);

	for(u8 i=0;i<4;i++){
		if(i == currentQuestion->ans){
			currentQuestion->answer[i] = TangshiLineIdx(currentQuestion->question,currentQuestion->line);
		}else{
			do{
				currentQuestion->answer[i] = ran_max(YuWenItemCount);
			}while(len != strlen(dataLine(currentQuestion->answer[i])));
		}
	}
}


void YuWenTS::showTSQuetion(){
	Display_Fill_Rectangle(0,25, 480, 75, BLACK);
	Display_String(YUW_Quetion_LOC_A, &optionQuetion, TangshiLineTitle(currentQuestion->question));
	Display_String(YUW_Quetion_LOC_B, &optionZY, TangshiLineAuthor(currentQuestion->question));
	
	for(u8 i=0;i<4;i++){
		Display_Fill_Rectangle2(answerLocX, answerLocY[i]-2, SCREEN_WIDTH - answerLocX, 21 ,answerBGColor[i]);
		Display_String2(answerLocX, answerLocY[i], &optionAnswer[i], (const char *)answerTitle[i], dataLine(currentQuestion->answer[i]));
	}
}

void YuWenTS::showTangshi(){
	Display_Fill_Rectangle2(TangshiBoxStartX,TangshiBoxStartY, TangshiBoxWidth, TangshiBoxHeight, BLACK);
	u16 offx = 0;
	int offy = offsetY;
	boxHeight=1;
	const char *sl;
	for(u8 i=0;i< dataLineCount(currentQuestion->question) ;i++){
		sl= TangshiLine(currentQuestion->question, i);
		u16 len = strlen(sl);
		if(sl[0] == 'g' ){
			offx = 0;
			offy += 20;
			boxHeight++;
			continue;
		}
		if(offx + len* 8 > TangshiBoxWidth){
			offx = 0;
			offy += 20;
			boxHeight++;
		}

		if(offy <0 || offy>TangshiBoxHeight-TangshiBoxLineHeight ){
			offx += len*8;
			continue;
		}

		if (i== currentQuestion->line){
				answerX=offx + TangshiBoxStartX;
				answerY=offy + TangshiBoxStartY;
				answerIdx = TangshiLineIdx(currentQuestion->question, i);
			for(u8 j=0;j< len; j++){
				Display_String(answerX+ j*8, answerY, &optionMiss, "_") ;
			}
		}else{
			Display_String(offx + TangshiBoxStartX, offy + TangshiBoxStartY, &optionLines, 
				TangshiLine(currentQuestion->question, i));
		}
		offx += len*8;
	}
	boxHeight = boxHeight*TangshiBoxLineHeight;
	
	if(boxHeight > TangshiBoxHeight){
		Display_Fill_Rectangle(TangshiBoxStartX + TangshiBoxWidth - 10, TangshiBoxStartY, 
			TangshiBoxStartX + TangshiBoxWidth -1, TangshiBoxStartY + TangshiBoxHeight, GRAY);


		double a = (double) (-offsetY) / boxHeight * TangshiBoxHeight;
		double b = (double) (-offsetY + TangshiBoxHeight) / boxHeight * TangshiBoxHeight;

		Display_Fill_Rectangle(TangshiBoxStartX + TangshiBoxWidth - 9,
			TangshiBoxStartY + a, 
			TangshiBoxStartX + TangshiBoxWidth -2,
			TangshiBoxStartY + b,
			GREEN);

	}
}

4、英语学习类,继承学习基类:

YingYu.h

typedef struct {
	uint16_t question;
    uint16_t answer[4];
	uint8_t ans;
} EngQuestion;

class YingYu : public StudyBase
{
   public:
      YingYu();   
      ~YingYu();  
		SceanResult tick(u32 ticks);
		int scean_init(cJSON*  param);

private:

   EngQuestion *currentQuestion;
   void start();
   void createQuestion();
   void createQuestionMode3();
   void showQuetion();
   void showAnswer();
   void correct();
   void wrong();

	DisplayOption optionQuetion = {FONT_SIZE_2424, YELLOW, BLACK, 1, 1};
	DisplayOption optionZY = {FONT_SIZE_2424, WHITE, BLACK, 1, 1};
	DisplayOption optionAnswer[4] = {
			{FONT_SIZE_1516, WHITE, answerBGColor[0], 0, 1},
			{FONT_SIZE_1516, WHITE, answerBGColor[1], 0, 1},
			{FONT_SIZE_1516, WHITE, answerBGColor[2], 0, 1}, 
			{FONT_SIZE_1516, WHITE, answerBGColor[3], 0, 1}};

	u16 Eng_Answer_LOC_X=20;

	u16 Eng_Answer_LOC_Y[4] = {195,220,245,270};

   char errEngWord[4][40];
   
	unsigned char *DataBuff;
      
	int YingYuCount;
};

YingYu.cpp


#define Eng_Quetion_LOC_A  240, 100
#define Eng_Quetion_LOC_B  240, 140

typedef struct YingYuWord
{
	const char *en; //32
	const char *sd; //32
	const char *cn; //64
}YingYuWord;

typedef struct YingYuDuanYu
{
	const char *en; //64
	const char *cn; //64
}YingYuDuanYu;

YingYu::YingYu(){
	currentQuestion = new EngQuestion();
} 
YingYu::~YingYu(){
	delete currentQuestion;
	psram_heap_free((void*)DataBuff);
}  

int YingYu::scean_init(cJSON*  param){
	setKeyAdepterIntervalAll(200);
	setKeyAdepterInterval(KEY_GPIO_A, 65535);
	setKeyAdepterInterval(KEY_GPIO_B, 65535);
	setKeyAdepterInterval(KEY_GPIO_C, 65535);
	setKeyAdepterInterval(KEY_GPIO_D, 65535);
	
	winMode= cJSON_GetObjectItem(param,"w")->valueint;
    gameMode = cJSON_GetObjectItem(param,"m")->valueint;
	
	printf("start chinese. winMode=%d, gameMode=%d.\n", winMode, gameMode);
	
	fatfs_readFile(cJSON_GetObjectItem(param,"f")->valuestring, &DataBuff);
	YingYuCount = DataBuff[12] | (DataBuff[13]<<8) | (DataBuff[14]<<16)| (DataBuff[15]<<24);

	start();
	return 0;
}
void YingYu::start(){
	startPrepare();
	show_status_info(answerInfo);
	showScore();
	createQuestion();
	showQuetion();
}

#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)


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;
		
	}
}

void YingYu::showAnswer(){
	for(u8 i=0;i<4;i++)
		if(currentQuestion->ans !=i)	Display_Fill_Rectangle2(Eng_Answer_LOC_X, Eng_Answer_LOC_Y[i]-2, 440, 21 ,BLACK);
}


SceanResult YingYu::tick(u32 ticks){
	if(KEY_EXIT) {
		printf("goto top menu from About.\n");
		return SceanResult_EXIT;
	}
	if(isFinished){
		if(KEY_SEL) {
			start();
			return SceanResult_Done;
		}
	
	}else{
		totalTime+=ticks;
		showTime();

		if(checkFinish()){
			return SceanResult_Done;
		}
		
		if(KEY_A | KEY_B | KEY_C | KEY_D){
			if(KEY_A && currentQuestion->ans == 0){
				correct();
				return SceanResult_Done;
			}
			if(KEY_B && currentQuestion->ans == 1){
				correct();
				return SceanResult_Done;
			}
			if(KEY_C && currentQuestion->ans == 2){
				correct();
				return SceanResult_Done;
			}
			if(KEY_D && currentQuestion->ans == 3){
				correct();
				return SceanResult_Done;
			}
			wrong();
		}
		ran_max(10);
	}
	return SceanResult_Done;
}


void YingYu::correct(){
	correntCount++;
	showScore();
	if(checkFinish()==0){
		createQuestion();
		showQuetion();
	}
}
void YingYu::wrong(){
	wrongCount++;
	showScore();
	showAnswer();
	errorDelay(3);
	if(checkFinish()==0){
		createQuestion();
		showQuetion();
	}
}


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;

}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/603998.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

mysql数据库---操作数据库跟表的命令总结

前言 欢迎来到我的博客 个人主页:北岭敲键盘的荒漠猫-CSDN博客 本文着重整理mysql管理库跟表的指令。 不涉及增删查改等指令 其实本篇主要是我做好笔记格式 用的时候直接复制粘贴的 所以排版大多是为了快速找功能来排的 方便大家快速找目标语法 数据库的简介 一个数据库系…

[Redis] 使用布隆过滤器和分布式锁实现用户注册

布隆过滤器&#xff08;Bloom Filter&#xff09;是一种数据结构&#xff0c;用于快速判断一个元素是否可能存在于一个集合中。它通过使用多个哈希函数和一个位数组来表示一个集合&#xff0c;当一个元素被加入到集合时&#xff0c;通过哈希函数计算出多个哈希值&#xff0c;并…

Hypack 2024 简体中文资源完整翻译汉化已经全部完成

Hypack 2024 简体中文资源完整翻译汉化已经全部完成 Hypack 2024&#xff0c;资源汉化共翻译11065条。毕竟涉及测绘、水文、疏浚等专业术语太多&#xff0c;翻译有很多理解不正确的地方&#xff0c;望各位专业人员指正。 压缩包内包含Hypack 2024、Hypack 2022、Hypack 2021、…

什么样的行业适合做私域?

私域营销适用于各种行业&#xff0c;但以下几个行业尤其适合进行私域营销&#xff1a; 1、零售行业&#xff1a;私域营销可以帮助零售企业建立与顾客的直接联系&#xff0c;提高顾客忠诚度和复购率。通过私域营销&#xff0c;零售企业可以进行个性化推荐、定制化服务&#xff…

JavaWeb--11MySQL(3)-- 多表设计

MySQL&#xff08;3&#xff09;-- 多表设计 1 一对多&#xff08;多对一&#xff09;2 一对一3 多对多 各个表结构之间也存在着各种联系&#xff0c;基本上分为三种&#xff1a; 一对多(多对一)多对多一对一 1 一对多&#xff08;多对一&#xff09; 一对多关系实现&#x…

【Java】IO流:字节流 字符流 缓冲流

接续上文&#xff0c;在这篇文章将继续介绍在Java中关于文件操作的一些内容【Java】文件操作 文章目录 一、“流”的概念1.“流”的分类1.1输入流和输出流1.2字节流和字符流 字节和字符的区别&#xff1f;为什么要有字符流&#xff1f;1.3节点流和处理流 字符流自带缓冲区&…

【Linux——Centos7安装RabbitMQ】 RabbitMQ无法连接

到这一步是基本已经装好了&#xff0c;现在是在开放端口&#xff0c;我这个报错是因为我的防火墙是处于关闭状态&#xff0c;所以在开放端口时会报防火墙为运行&#xff0c;把防火墙打开&#xff0c;在开放端口&#xff0c;就可以访问到了 重启防火墙&#xff1a; systemctl …

【无标题】基于GIS、Python机器学习技术的地质灾害风险评价、易发性分析与信息化建库及灾后重建中的实践技术

理解地质灾害形成机理与成灾模式&#xff1b;从空间数据处理、信息化指标空间数据库构建、致灾因子提取&#xff0c;空间分析、危险性评价与制图分析等方面掌握GIS在灾害危险性评价中的方法&#xff1b;运用地质灾害危险性评价原理和技术方法 原文链接&#xff1a;基于GIS、Py…

DeepSeek API文档:创建对话补全的指南

DeepSeek平台不仅提供了一个用户友好的聊天界面&#xff0c;还为开发者提供了强大的API接口&#xff0c;使他们能够创建和集成智能对话补全功能。以下是关于如何使用DeepSeek API创建对话补全的详细介绍。 DeepSeek API概述 DeepSeek的API允许开发者通过编程方式与DeepSeek的…

应用软件安全保证措施方案书

系统安全保证措施方案—word原件 软件全套资料进主页获取或者本文末个人名片直接获取。

【文章转载】ChatGPT 提示词十级技巧: 从新手到专家

学习了微博网友宝玉xp老师《ChatGPT 提示词十级技巧: 从新手到专家》 个人学习要点&#xff1a; 1、关于提示中避免使用否定句&#xff0c;播主说&#xff1a;“没有人能准确解释为什么&#xff0c;但大语言模型在你告诉它去做某事时&#xff0c;表现似乎比你让它不做某事时更…

识货小程序逆向

声明 本文章中所有内容仅供学习交流使用&#xff0c;不用于其他任何目的&#xff0c;抓包内容、敏感网址、数据接口等均已做脱敏处理&#xff0c;严禁用于商业用途和非法用途&#xff0c;否则由此产生的一切后果均与作者无关&#xff01;wx a15018601872&#xff0c;x30184483x…

Java进阶07集合(续)

Java进阶07 集合&#xff08;续&#xff09; 一、数据结构&#xff08;树&#xff09; 1、关于树 1.1 相关概念 节点&#xff1a;树中每个单独的分支 节点的度&#xff1a;每个节点的子节点数量 树高&#xff1a;树的总层数 根节点&#xff1a;最顶层节点 左子节点&…

6层板学习笔记2

说明:笔记基于6层全志H3消费电子0.65MM间距BGA 67、多层板的电源建议直接大面积铺铜,不建议走线,铺铜充分满足其载流能力 68、凡亿推荐表层1OZ的铜厚线宽20MIL能承载1A的电流,内层0.5OZ的铜厚线宽为40MIL能承载1A的电流,过孔直径20MIL(0.5MM)能承载1A左右的电流,实际设…

typescript的入门到吐槽:看了typescript,发现前端真的卷,

typescript TypeScript 是一种由微软开发的自由和开源的编程语言。它是 JavaScript 的一个超集&#xff0c;而且本质上向这个语言添加了可选的静态类型和基于类的面向对象编程。 TypeScript 与 JavaScript 的区别 其实就是对JavaScript的封装&#xff0c;把一个弱类型语言封…

remmina无法连接远程桌面,Remmina无法连接远程桌面的原因与解决办法

在解决Remmina无法连接远程桌面的问题时&#xff0c;我们需要考虑多种可能的原因&#xff0c;并采取相应的解决办法。以下是一些常见的原因及其对应的解决方案&#xff1a; 1、网络问题 原因&#xff1a;不稳定的网络连接或中断可能导致无法建立远程桌面连接。 解决办法&#x…

MySQL数据库---增删查改汇总

前言 欢迎来到我的博客 个人主页:北岭敲键盘的荒漠猫-CSDN博客 本文着重整理MySQL数据库增删查改功能 主要是整理语法 争取做到要用什么语法 可以快速找到复制粘贴 增添语法 INSERT into tab(列名,列名,列名) values(内容,内容,内容); 插入一行数据 INSERT into tab(列名,…

Kubernetes最小单元Pod介绍及配置

1.1 Pod介绍 Pod是Kubernetes中的一个基本构建块&#xff0c;它是一个逻辑主机&#xff0c;用于托管一个或多个容器。 Pod中的容器共享网络和存储资源&#xff0c;并且通常作为一个单元一起调度和管理。 Pod为容器提供了一个共享的环境&#xff0c;使得容器之间可以方便地通信…

Android进阶之路 - 静态会员进度条

年后这个新版本加入了VIP模块&#xff0c;有幸正好由我来负责&#xff0c;可以再积累一下这方面的知识。 那段时间看了一本书&#xff0c;书中说到初级码农的特性之一就是完全集中于某些功能&#xff0c;忽略了了很多成长机会&#xff0c;所以重复性劳作带来的成长值有限&#…

基于51单片机的智能台灯proteus仿真设计( proteus仿真+程序+原理图+报告+讲解视频)

基于51单片机的红外光敏检测智能台灯控制系统仿真( proteus仿真程序原理图报告讲解视频&#xff09; 1.主要功能&#xff1a; 基于51单片机的红外检测光照检测智能台灯仿真设计 1、检测光照强度并显示在数码管上。 2、具备红外检测人体功能。 3、灯光控制模式分为自动模式…