自己写的一个猜拳小游戏(C语言)

#include 
#include 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int menu(void);
int Mode(int); 
//int score(void);
int main(int argc, char *argv[]) {
	
	 menu();
	return 0;
}


int menu(void){
	system("cls");
	int a=0;
	printf("                                  \n");
	printf("**********************************\n");
	printf("                                  \n");
	printf("                                  \n");
	printf("           1.无尽模式             \n");
	printf("           2.五局三胜             \n");
	printf("           3.三局两胜             \n");
	printf("           4.得分记录             \n");
	printf("                                  \n");
	printf("                                  \n");	
	printf("                                  \n");
	printf("           请输入选项:           \n");
	printf("**********************************\n");
	printf("                                  \n");
	
	scanf("%d",&a);
	printf("%d",a);
	switch(a){
		case 1:
			{	
				Mode(1);
				break;
			}
		case 2:Mode(2);break;
		case 3:Mode(3);break;
		default : 
			printf("请输入数字1/2/3\n"); 
			menu();
			break;  
	//	case 4:score(4);break; 
			
	}
	return 0; 
}

int Mode(int mode){
	
	system("cls");
	int i=0;
	int Mode=0;
	int player_2,player_1;
	int win=0,fail=0,count=0;
	char str[3][6]={"剪刀","石头","布"};
	char player1[6]="";
	char player2[6]="";
	if(mode==2)
	{
		Mode=5;
		printf("五局三胜\n\n\n");
	} 
	if(mode==3)
	{
		Mode=3;
		printf("三局两胜\n\n\n");
	} 
	
	//printf("Mode是%d,%d\n",Mode,mode);
	printf("请选择:1.剪刀  2.石头  3.布  0.返回菜单\n\n");
	scanf("%d",&i); 
	//printf("%d",i);
	player_1=i-1;
	player_2=rand()%3;
	//printf("%d",player_2);
	strcpy(player1,str[player_1]);  
	strcpy(player2,str[player_2]);  
	printf("电脑:%s\n",player2);
	printf("自己:%s\n",player1);

	
	while(i!=0){
	
	if(strcmp(player1, player2) == 0)
		{
			printf("平局\n");
			printf("_________________________________\n\n");
			count++;
		}	
	
	if(player_1==0){
		if(player_2==1){
			printf("输了~\n");
			printf("_________________________________\n\n");
			count++;
			fail++;
		}else if(player_2==2){
			count++;
			win++;
			printf("胜利+1\n"); 
			printf("_________________________________\n\n");
		}
	}
	if(player_1==1){
		if(player_2==0){
			printf("胜利+1\n");
			printf("_________________________________\n\n");
			count++;
			win++;
			
		}else if(player_2==2){
			printf("输了~\n");
			printf("_________________________________\n\n");
			count++;
			fail++;
		}
	
	} 
	if(player_1==2){
		if(player_2==0){
			printf("输了~\n");
			printf("_________________________________\n\n");
			count++;
			fail++;
		}else if(player_2==1){
			printf("胜利+1\n");
			printf("_________________________________\n\n");
			count++;
			win++;
		}
	
	} 
	
	if(mode!=1){
		if(count==Mode&&win>fail){
			printf("**********************************\n");
			printf("                                  \n");
			printf("恭喜你赢了!\n");
			printf("你赢了%d局\n电脑赢了%d局\n平局:%d\n",win,fail,Mode-win-fail);
			printf("                                  \n");
			printf("**********************************\n");
			
	
			count=0;
			win=0;
			fail=0;
			 
		}
		if(count==Mode&&win

你可能感兴趣的:(自己写的一个猜拳小游戏(C语言))