c语言实现的小学生心算抢答系统

小学生心算抢答系统

本系统用c语言以及c++色彩描述实现的一个心算抢答系统,用大约一周的时间去实现的,过程很简单不复杂,适合刚学c语言的初学者学习制作的小项目。
下面就上图了
c语言实现的小学生心算抢答系统_第1张图片
c语言实现的小学生心算抢答系统_第2张图片
c语言实现的小学生心算抢答系统_第3张图片
c语言实现的小学生心算抢答系统_第4张图片
c语言实现的小学生心算抢答系统_第5张图片
代码不多,记得一定要好好学习呀

#include
#include
#include
#include 
#define N1 3
struct Team
	{
		char name;
		int score;
	}team[N1];

int color[7] = {31, 32, 33, 34, 35, 36, 37};
	
void gotoxy(int x, int y) 
{
	printf("\033[%d;%dH ",y+1, x+1);
}

int sim()
{
	int s,num1,num2,stpy;
	srand((unsigned)time(NULL));
	num1 = rand()%10;
	num2 = rand()%10;
	stpy = rand()%4 +1;
	switch(stpy)
	{
		case 1: 
		{
			s = num1 + num2;
			printf("\033[1;%dm%d\033[0m", color[0], num1);
		    printf("\033[1;%dm + \033[0m", color[1]);
		    printf("\033[1;%dm%d\033[0m", color[2],num2);
		    printf("\033[1;%dm =\033[0m", color[4]);
		    printf("\033[1;%dm ?\033[0m", color[2]);
		    break;
		 } 
		 case 2:if(num1 >= num2)
		 	{
		 		s = num1 - num2;
		 	printf("\033[1;%dm%d\033[0m", color[3], num1);
		    printf("\033[1;%dm - \033[0m", color[4]);
		    printf("\033[1;%dm%d\033[0m", color[5],num2);
		    printf("\033[1;%dm =\033[0m", color[6]);
		    printf("\033[1;%dm ?\033[0m", color[1]);
		     
		    break;
			}
			 case 3:
		 	{
		 		s = num1 * num2;
		 		printf("\033[1;%dm%d\033[0m", color[6], num1);
		        printf("\033[1;%dm * \033[0m", color[2]);
		        printf("\033[1;%dm%d\033[0m", color[4],num2);
		        printf("\033[1;%dm =\033[0m", color[1]);
		        printf("\033[1;%dm ?\033[0m", color[3]);
		        break;
			 }
			 case 4:
		 	{
		 		s = num1 / num2;
		 		printf("\033[1;%dm%d\033[0m", color[5], num1);
		        printf("\033[1;%dm ÷ \033[0m", color[1]);
		        printf("\033[1;%dm%d\033[0m", color[3],num2);
		        printf("\033[1;%dm =\033[0m", color[2]);
		        printf("\033[1;%dm ?\033[0m", color[4]);
			 }
			 
		}
		 return(s); 
			 
		 
 }
 
 int mix()
 {
 	int t, num1, num2, num3, stpy, num4;
 	srand((unsigned)time(NULL));
 	num1 = rand()%10;
	num2 = rand()%10;
	num3 = rand()%10;
	num4 = rand()%10;
	stpy = rand()%4 + 1;
	switch(stpy)
	{
		case 1: 
		{
			t = (num1 + num2) * (num3 + num4);
			printf("("); 
		    printf("\033[1;%dm%d\033[0m", color[3], num1);
		    printf("\033[1;%dm + \033[0m", color[4]);
		    printf("\033[1;%dm%d\033[0m", color[5],num2);
		    printf(")");
		    printf("\033[1;%dm * \033[0m", color[2]);
		    printf("("); 
		    printf("\033[1;%dm%d\033[0m", color[6], num3);
		    printf("\033[1;%dm + \033[0m", color[2]);
		    printf("\033[1;%dm%d\033[0m", color[4],num4);
		    printf(")");
		    printf("\033[1;%dm =\033[0m", color[6]);
		    printf("\033[1;%dm ?\033[0m", color[1]);
			break;
		}
		case 2:if(num1 >= num2)
		{
			t = (num1 - num2) * (num3 + num4);
			printf("(");
			printf("\033[1;%dm%d\033[0m", color[3], num1);
		    printf("\033[1;%dm - \033[0m", color[4]);
		    printf("\033[1;%dm%d\033[0m", color[5],num2);
		    printf(")");
		    printf("\033[1;%dm * \033[0m", color[1]);
		    printf("(");
		    printf("\033[1;%dm%d\033[0m", color[0], num3);
		    printf("\033[1;%dm + \033[0m", color[1]);
		    printf("\033[1;%dm%d\033[0m", color[2],num4);
		    printf(")");
		    printf("\033[1;%dm =\033[0m", color[6]);
		    printf("\033[1;%dm ?\033[0m", color[1]);
			break;
		}
		case 3:if(num1>num3&&num2>num4)
			{
				t = num1 * num2 - num3 * num4;
				
				printf("\033[1;%dm%d\033[0m", color[6], num1);
		        printf("\033[1;%dm * \033[0m", color[2]);
		        printf("\033[1;%dm%d\033[0m", color[4],num2);
		        
		        printf("\033[1;%dm - \033[0m", color[4]);
		        
		        printf("\033[1;%dm%d\033[0m", color[6], num3);
		        printf("\033[1;%dm * \033[0m", color[2]);
		        printf("\033[1;%dm%d\033[0m", color[4],num4);
		        printf("\033[1;%dm =\033[0m", color[1]);
		        printf("\033[1;%dm ?\033[0m", color[3]);
				break;	
			}
		case 4:if(num1+num2-num3 > 0)
			{
				t = ( num1 + num2 - num3) * num4;
				printf("(");
				printf("\033[1;%dm%d\033[0m", color[3], num1);
		        printf("\033[1;%dm + \033[0m", color[4]);
		        printf("\033[1;%dm%d\033[0m", color[5],num2);
		        printf("\033[1;%dm - \033[0m", color[4]);
		        printf("\033[1;%dm%d\033[0m", color[0], num3);
		        printf(")");
		        printf("\033[1;%dm * \033[0m", color[1]);
		        printf("\033[1;%dm%d\033[0m", color[2],num4);
		        printf("\033[1;%dm =\033[0m", color[4]);
		        printf("\033[1;%dm ?\033[0m", color[2]);
		        break;
			}
	 } 
	 
	 return(t);
 }
 
 int block[20][20] ;
 void init_block()		//初始化墙,四边是1
{
	int i;
	for(i = 0; i < 20; i++)
	{
		block[0][i] = 1;	//让数组中相应位置是墙,后面会描画
		block[19][i] = 1;
		block[i][0] = 1;
		block[i][19] = 1;
	}
}

void draw_block()		//将墙画出来记录分数的墙 
{
	int i, j;
	for(i = 0; i < 20; i++)
	{
		gotoxy(76, 20+i);
		for(j = 0; j < 20; j++)
		{
			if(block[i][j] == 1)
				printf("\033[1;34m□\033[0m");
			else
				printf("  ");		//能实现擦除功能
		}
		printf("\r\n");
	}

}

int competition_wall[20][40] ;//比赛边框 
void init_competition_wall()		//初始化墙,四边是1
{
	int i;
	for(i = 0; i < 20; i++)//让数组中相应位置是墙,后面会描画
	{
	     
		competition_wall[i][0] = 1;
		competition_wall[i][39] = 1;
		competition_wall[i][19] = 1;
	}
	for(i = 0; i < 40; i++)//让数组中相应位置是墙,后面会描画
	{
		competition_wall[19][i] = 1;
		competition_wall[0][i] = 1;
	}
}

void draw_competition_wall()		//将墙画出来记录分数的墙 
{
	int i, j;
	for(i = 0; i < 20; i++)
	{
		gotoxy(0, 9+i);
		for(j = 0; j < 40; j++)
		{
			if(competition_wall[i][j] == 1)
				printf("\033[1;34m□\033[0m");
			else
				printf("  ");		//能实现擦除功能
		}
		printf("\n");
	}
	
   
}
 
 
 void ranking_print()//输出每次比赛之后的成绩 
 {
 	int i,t;
 	t = 1;
 	gotoxy(80,16);
 	printf("\033[1;36m第%d轮比拼之后每位选手的成绩如下\033[0m",t);
 	for(i = 0; i < N1; i++)
    {
		 gotoxy(80,20+i*2); 
		 printf("\033[1;36m ☆☆☆☆\033[0m");
		 printf(" %c %4d ",team[i].name,team[i].score);
		 printf("\033[1;36m☆☆☆☆\033[0m\n");
	}
	
		 
 }
 
void firsttest()
{
	int p, k, t, i, n,count=0;
	int result1, answer1;
	char ch1;
	
	gotoxy(15,5);
	printf("\033[1;35m各位选手请注意第一轮的总题目个数是:\033[0m");
	scanf("%d",&n);
	gotoxy(16,7);
	printf("\033[1;31m第一轮四则简单运算比赛开始!\033[0m");
    printf("\n\n");
    gotoxy(4,15);
	printf("请选手认真看题: →→→→→→");
	
	for(p = 0; p < n; p++)
	{
		gotoxy(4,15);
	    printf("请选手认真看题: →→→→→→");
		gotoxy(55,15);
		result1 = sim();//调用此函数进行简单出四则运算的题目 
		gotoxy(4,17+p);
		printf("\033[5;36m*******\033[0m\n");
		printf("\n");
		gotoxy(4,19+p);
		printf("请输入你的参赛号码(ABC):");
		getchar();
		scanf("%c",&ch1); 
		gotoxy(50,18+p);
		printf("请输入你的回答:");
		scanf("%d", &answer1);
		for(k = 0;k < N1; k++)
		{
			t = k;
			if(ch1 == team[k].name)//查询是哪个队伍回答的并且进行分数加减 
			{ 
			  	if(result1 == answer1)
			   		{
			    	printf("\n\n"); 
					gotoxy(82,12);
					printf("\033[1;36m恭喜 %c 回答正确! \033[0m\n",ch1);
					gotoxy(82,14);
					printf("%c能获得5分 \n",ch1);
					team[t].score += 5;
			   		}
			  	else
					{
						gotoxy(82,12);
						printf("\033[1;36m遗憾你的回答错误\033[0m\n\n");
						gotoxy(82,14);
						printf("正确答案是%d\n",result1);
						team[t].score -= 5; 
					}
			} 
		} 
		 ranking_print();//调用函数输出选手分数
		 draw_competition_wall(); 
		
	 } 
	 
}
int secondtest()
{
	int p, i, m,k,t,count;
	int result2, answer2;
	char ch2;
	
    gotoxy(15,5);
	printf("\033[1;33m各位选手请注意第二轮的总题目个数共有:\033[0m");
	scanf("%d",&m);
	gotoxy(17,7);
	printf("\033[1;33m第二轮四则混合运算比赛开始!\033[0m");
	printf("\n\n");

	for(p = 0; p < m; p++)
	{
		gotoxy(4,15);
	    printf("请选手认真看题: →→→→→→");
		gotoxy(50,15);
	 	result2 = mix();
	 	gotoxy(4,17+p);
		printf("\033[5;33m*******\033[0m\n");
		printf("\n");
		gotoxy(4,19+p);
		printf("请输入你的参赛号码(ABC): ");
		getchar();
		scanf("%c",&ch2);
		gotoxy(50,18);
		printf("请输入你的回答:");
		scanf("%d",&answer2);
		for(k = 0;k < N1; k++)//查询是哪个队伍回答的并且进行分数加减 
		{
			t = k;
			if(ch2 == team[k].name)
			{ 
			  	if(result2 == answer2)
			   		{
			    	printf("\n\n"); 
					gotoxy(82,12);
					printf("\033[1;36m恭喜 %c 回答正确!\033[0m\n",ch2);
					gotoxy(82,14);
					printf("%c能获得10分 \n",ch2);
					team[t].score += 10;
			   		}
			  	else
					{
						gotoxy(82,12);
						printf("\033[1;36m遗憾你的回答错误\033[0m\n\n");
						gotoxy(82,14);
						printf("正确答案是%d\n",result2);
						team[t].score -= 10; 
					}
			} 
		} 
		 ranking_print();//调用函数输出选手分数
		draw_competition_wall();//清空答题信息 
	} 
	
}



void queue()//比赛最终排名 
{
	struct Team temp;
	int i ,j;

	for(i = 0; i < N1-1; i++)
	  for(j = 0; j < N1-1; j++)
	  if(team[j].score <team[j+1].score)
	  {
	  	temp = team[j];
	  	team[j] = team[j+1];
	  	team[j+1] = temp;
	  }//进行选手的成绩排序
	  gotoxy(27,32);
	  printf("\033[1;36m最终比赛排名是:\033[0m\n");
	  for(i = 0; i < N1; i++)
    {
		 gotoxy(25,40+i*2); 
		 printf("\033[1;36m ☆☆☆☆\033[0m");
		 printf(" %c %4d ",team[i].name,team[i].score);
		 printf("\033[1;36m☆☆☆☆\033[0m\n");
	}
}
void start()
{
	gotoxy(40,0);
    printf("\033[1;34m※※※※※※※※※※※※※※※※\033[0m\n");
    gotoxy(40,1);
	printf("\033[1;34m※                            ※\033[0m\n");
	gotoxy(40,2);
	printf("\033[1;34m※                            ※\033[0m\n");
	gotoxy(40,3);
	printf("\033[1;34m※                            ※\033[0m");
	gotoxy(46,3) ;
	printf("\033[1;31m欢迎来到心算抢答系统\033[0m\n");
	gotoxy(40,4);
	printf("\033[1;34m※                            ※\033[0m\n");
	gotoxy(40,5);
	printf("\033[1;34m※                            ※\033[0m\n");
	gotoxy(40,6);
	printf("\033[1;34m※※※※※※※※※※※※※※※※\033[0m\n");
}
void game_rule()
{
	printf("\n");
	gotoxy(90, 8); 
	printf("\033[1;50m    比赛规则    \033[0m\n");
	gotoxy(75, 9);
	printf("\033[1;50m比赛总共分为两个阶段:第一阶段:\033[0m");
	gotoxy(106,9);
	printf("\033[1;31m简单四则运算\033[0m\n");
	gotoxy(75, 10);
	printf("\033[1;50m第二阶段:\033[0m");
	printf("\033[1;31m混合四则运算 \033[0m");
	printf("\033[1;50m第一阶段每答对一题可得\033[0m");
	gotoxy(75,11);
	printf("\033[1;31m5分\033[0m"); 
	printf("\033[1;50m,第二阶段每答对一题可得\033[0m");
	printf("\033[1;31m10分\033[0m");
	printf("\033[1;50m每轮比赛答错不\033[0m");
	gotoxy(75,12); 
	printf("\033[1;50m扣分,每位选手的起始分数都是\033[0m");
	printf("\033[1;31m100分\033[0m\n"); 
	
	
}
int main()
{
	int i,j;
	for(i = 0, j=65; i <N1; i++, j++)
	{
		team[i].name = j;
		team[i].score = 100;//依次给每个选手进行号码编号和成绩付初值 
	}
	system("cls");
    start();
    game_rule();
    init_block();
    init_competition_wall();
    draw_block();
	draw_competition_wall();
    firsttest(); 
    secondtest();
    queue();
	  printf("**********************\n");
	  printf("**     游戏结束    **\n");
	  printf("**     谢谢使用    **\n");
	  printf("**********************\n");
	  return(0);
}

你可能感兴趣的:(c#,c++,个人开发)