三字棋(可选难度)

使用c语言实现三字棋
第一步:显示

void menu(){
	printf("##############################\n");
	printf("## 欢迎来到我的三子棋游戏室 ##\n");
	printf("##############################\n");
	printf("## 1.Paly            2.Exit ##\n");
	printf("##############################\n");
	printf("Please Enter Select:>");
}
void menu2(){
	printf("##############################\n");
	printf("## 请选择初级电脑or高级电脑 ##\n");
	printf("##############################\n");
	printf("## 1.初级电脑    2.中级电脑 ##\n");
	printf("##########3.高级电脑##########\n");
	printf("##############################\n");
	printf("Please Enter Select:>");
}

提供基础的界面显示
第二步:选择难度
难度分为初级,中级,高级
//初级难度直接随机下即可,无脑
int i = rand() % row; // 0-2之间
int j = rand() % col; // 0-2之间
中级难度会防守,但有赢得希望

for (int i = 0; i < 3; i++){
		if (board[i][0] == BLACK_PIECE && board[i][1] == BLACK_PIECE){
			if (board[i][2] == ' '){
				board[i][2] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[i][0] == BLACK_PIECE && board[i][2] == BLACK_PIECE){
			if (board[i][1] == ' '){
				board[i][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[i][1] == BLACK_PIECE && board[i][2] == BLACK_PIECE){
			if (board[i][0] == ' '){
				board[i][0] = WHITE_PIECE;
				return 1;
			}
		}
	}

	//判断列
	for (int i = 0; i < 3; i++){
		if (board[0][i] == BLACK_PIECE && board[1][i] == BLACK_PIECE){
			if (board[2][i] == ' '){
				board[2][i] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][i] == BLACK_PIECE && board[2][i] == BLACK_PIECE){
			if (board[1][i] == ' '){
				board[1][i] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[1][i] == BLACK_PIECE && board[2][i] == BLACK_PIECE){
			if (board[0][i] == ' '){
				board[0][i] = WHITE_PIECE;
				return 1;
			}
		}
	}

	//判断对角线
	if (board[0][0] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[2][2] == ' '){
			board[2][2] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[0][0] == BLACK_PIECE&&board[2][2] == BLACK_PIECE){
		if (board[1][1] == ' '){
			board[1][1] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[1][1] == BLACK_PIECE&&board[2][2] == BLACK_PIECE){
		if (board[0][0] == ' '){
			board[0][0] = WHITE_PIECE;
			return 1;
		}
	}
	//判断对角线
	if (board[0][2] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[2][0] == ' '){
			board[2][0] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[0][2] == BLACK_PIECE&&board[2][0] == BLACK_PIECE){
		if (board[1][1] == ' '){
			board[1][1] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[2][0] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[0][2] == ' '){
			board[0][2] = WHITE_PIECE;
			return 1;

//高级难度电脑不败。先判断赢,不行就守,再次随机。。因为三子棋机制的缘故,只需第一颗棋下入四角,就不会败
//第一颗子

else if (choose == 3){
			//高级电脑走一步
			if (count == 1){
				//高级电脑第一步要占领四个角其中一个
				if (board[0][0] == ' '){
					board[0][0] = WHITE_PIECE;
					count++;
				}
				else if (board[0][2] == ' '){
					board[0][2] = WHITE_PIECE;
					count++;
				}
				else if (board[2][0] == ' '){
					board[2][0] = WHITE_PIECE;
					count++;
				}
				else{
					board[2][2] = WHITE_PIECE;
					count++;
				}
			}
			else{
				seniorComputerMove(board, ROW, COL);
			}
		}

//赢的算法,守等同中级,随机等同初级

for (int i = 0; i < 3; i++){
			if (board[i][0] == WHITE_PIECE && board[i][1] == WHITE_PIECE){
				if (board[i][2] == ' '){
					board[i][2] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[i][0] == WHITE_PIECE && board[i][2] == WHITE_PIECE){
				if (board[i][1] == ' '){
					board[i][1] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[i][1] == WHITE_PIECE && board[i][2] == WHITE_PIECE){
				if (board[i][0] == ' '){
					board[i][0] = WHITE_PIECE;
					return 1;
				}
			}
		}

		//判断列
		for (int i = 0; i < 3; i++){
			if (board[0][i] == WHITE_PIECE && board[1][i] == WHITE_PIECE){
				if (board[2][i] == ' '){
					board[2][i] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[0][i] == WHITE_PIECE && board[2][i] == WHITE_PIECE){
				if (board[1][i] == ' '){
					board[1][i] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[1][i] == WHITE_PIECE && board[2][i] == WHITE_PIECE){
				if (board[0][i] == ' '){
					board[0][i] = WHITE_PIECE;
					return 1;
				}
			}
		}

		//判断对角线
		if (board[0][0] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[2][2] == ' '){
				board[2][2] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][0] == WHITE_PIECE&&board[2][2] == WHITE_PIECE){
			if (board[1][1] == ' '){
				board[1][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[1][1] == WHITE_PIECE&&board[2][2] == WHITE_PIECE){
			if (board[0][0] == ' '){
				board[0][0] = WHITE_PIECE;
				return 1;
			}
		}
		//判断对角线
		if (board[0][2] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[2][0] == ' '){
				board[2][0] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][2] == WHITE_PIECE&&board[2][0] == WHITE_PIECE){
			if (board[1][1] == ' '){
				board[1][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[2][0] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[0][2] == ' '){
				board[0][2] = WHITE_PIECE;
				return 1;
			}
		}
	}

//第三步,棋盘初始化,及展示判定

void InitBoard(char board[][COL], int row, int col){
	for (int i = 0; i < row; i++){
		for (int j = 0; j < col; j++){
			board[i][j] = ' ';
		}
	}
}
void showBoard(char board[][COL], int row, int col){
	printf("   | 1 | 2 | 3 |\n");
	for (int i=1; i<=row; i++){
		printf("----------------\n");
		printf(" %d | %c | %c | %c |\n", i, board[i-1][0], board[i-1][1], board[i-1][2]);
	}
	printf("----------------\n");
}

//用户赢了	BLACK_PIECE	'×'
//电脑赢了	WHITE_PIECE	'○'
//平局	'E'
//都没赢,继续	'N'
char JudgeResult(char board[][COL], int row, int col){
	//判断行是否相等
	for (int i = 0; i < row; i++){
		if (board[i][0]!=' ' && board[i][0] == board[i][1] && board[i][1] == board[i][2]){
			return board[i][0];
		}
	}

	//判断列是否相等
	for (int i = 0; i < col; i++){
		if (board[0][i] != ' ' && board[0][i] == board[1][i] && board[1][i] == board[2][i]){
			return board[0][i];
		}
	}

	//判断对角线是否相等
	if (board[0][0] != ' ' && board[0][0] == board[1][1] && board[1][1] == board[2][2]){
		return board[0][0];
	}
	if (board[0][2] != ' ' && board[0][2] == board[1][1] && board[1][1] == board[2][0]){
		return board[0][2];
	}

	//判断是否没有结果
	for (int i = 0; i < row; i++){
		for (int j = 0; j < col; j++){
			if (board[i][j] == ' '){
				return 'N';
			}
		}
	}

	return 'E';
}

//第四步,人走

int playerMove(char board[][COL], int row, int col){
	int x = 0;
	int y = 0;
	printf("Pllease Enter Your Pos<x, y># ");
	scanf("%d %d", &x, &y);
	if (x >= 1 && x <= 3 && y >= 1 && y <= 3){
		if (board[x - 1][y - 1] != ' '){
			return 2;	//用户坐标被占了
		}
		board[x - 1][y - 1] = BLACK_PIECE;	//把旗子添加到棋盘中
		return 0;
	}
	return 1;	//用户输入坐标有误
}

//第五步,电脑走

void game(int choose){
	int count = 1;	//让电脑第一步占领4个角其中一个,那样困难电脑攻无不克
	char board[ROW][COL];
	InitBoard(board,ROW,COL);	//初始化棋盘

	char result = 'N';	//判断是否有人胜利
	srand((unsigned long)time(NULL));	//随机数种子

	while (1){
		showBoard(board, ROW, COL);	//给玩家看到面板
		//人走一步
		int type=playerMove(board, ROW, COL);	
		if (1 == type){
			printf("您输入的坐标有误,请重新输入!\n");
			continue;
		}
		else if(2==type){
			printf("您输入的坐标已经被占用了,请重新输入!\n");
			continue;
		}
		else{
			printf("Player ... Done!\n");
		}

		result = JudgeResult(board, ROW, COL);//判定结果
		if (result != 'N'){
			break;
		}

		//根据玩家选择的难度,电脑分别走出一步
		if (choose == 1){
			//初级电脑走一步
			ComputerMove(board, ROW, COL);
		}
		else if (choose == 2){
			//中级电脑走一步
			middleComputerMove(board, ROW, COL);
		}
		else if (choose == 3){
			//高级电脑走一步
			if (count == 1){
				//高级电脑第一步要占领四个角其中一个
				if (board[0][0] == ' '){
					board[0][0] = WHITE_PIECE;
					count++;
				}
				else if (board[0][2] == ' '){
					board[0][2] = WHITE_PIECE;
					count++;
				}
				else if (board[2][0] == ' '){
					board[2][0] = WHITE_PIECE;
					count++;
				}
				else{
					board[2][2] = WHITE_PIECE;
					count++;
				}
			}
			else{
				seniorComputerMove(board, ROW, COL);
			}
		}
		else{
			printf("buf");	//出现bug
		}

		result = JudgeResult(board, ROW, COL);//判定结果
		if (result != 'N'){
			break;
		}
	}

//循环即可完成难度分层的三子棋小游戏
//以下是代码,有错误请指正

//源文件 (预处理命令,头文件,宏定义及函数声明)
#ifndef _CHESS_H_
#define _CHESS_H_

#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<time.h>

#pragma warning(disable:4996)

#define ROW 3	//行
#define COL 3	//列

#define BLACK_PIECE 'X'	//黑旗
#define WHITE_PIECE 'O'	//白棋


void game(int choose);	/oose来判断玩家选择难度
void InitBoard(char board[][COL],int row,int col);	//初始化棋盘
void showBoard(char board[][COL], int row, int col);	//给玩家看到面板
int playerMove(char board[][COL], int row, int col);	//人走一步
void ComputerMove(char board[][COL], int row, int col);	//初级电脑走一步
void seniorComputerMove(char board[][COL], int row, int col);//高级电脑走一步
int algorithm(char board[][COL], int row, int col);//算法判断
char JudgeResult(char board[][COL], int row, int col);	//判断有没有胜利

#endif


//源文件对应的头文件(函数实现)
#include "chess.h"

//初始化棋盘
void InitBoard(char board[][COL], int row, int col){
	for (int i = 0; i < row; i++){
		for (int j = 0; j < col; j++){
			board[i][j] = ' ';
		}
	}
}

//人走一步
int playerMove(char board[][COL], int row, int col){
	int x = 0;
	int y = 0;
	printf("Pllease Enter Your Pos<x, y># ");
	scanf("%d %d", &x, &y);
	if (x >= 1 && x <= 3 && y >= 1 && y <= 3){
		if (board[x - 1][y - 1] != ' '){
			return 2;	//用户坐标被占了
		}
		board[x - 1][y - 1] = BLACK_PIECE;	//把旗子添加到棋盘中
		return 0;
	}
	return 1;	//用户输入坐标有误
}

//显示棋盘面板
void showBoard(char board[][COL], int row, int col){
	printf("   | 1 | 2 | 3 |\n");
	for (int i=1; i<=row; i++){
		printf("----------------\n");
		printf(" %d | %c | %c | %c |\n", i, board[i-1][0], board[i-1][1], board[i-1][2]);
	}
	printf("----------------\n");
}

//用户赢了	BLACK_PIECE	'×'
//电脑赢了	WHITE_PIECE	'○'
//平局	'E'
//都没赢,继续	'N'
char JudgeResult(char board[][COL], int row, int col){
	//判断行是否相等
	for (int i = 0; i < row; i++){
		if (board[i][0]!=' ' && board[i][0] == board[i][1] && board[i][1] == board[i][2]){
			return board[i][0];
		}
	}

	//判断列是否相等
	for (int i = 0; i < col; i++){
		if (board[0][i] != ' ' && board[0][i] == board[1][i] && board[1][i] == board[2][i]){
			return board[0][i];
		}
	}

	//判断对角线是否相等
	if (board[0][0] != ' ' && board[0][0] == board[1][1] && board[1][1] == board[2][2]){
		return board[0][0];
	}
	if (board[0][2] != ' ' && board[0][2] == board[1][1] && board[1][1] == board[2][0]){
		return board[0][2];
	}

	//判断是否没有结果
	for (int i = 0; i < row; i++){
		for (int j = 0; j < col; j++){
			if (board[i][j] == ' '){
				return 'N';
			}
		}
	}

	return 'E';
}

//初级电脑走一步
void ComputerMove(char board[][COL], int row, int col){
	while (1){
		int i = rand() % row;	// 0-2之间
		int j = rand() % col;	// 0-2之间

		if (board[i][j] == ' '){
			board[i][j] = WHITE_PIECE;
			break;
		}
	}
	printf("Computer ... Done\n");
	Sleep(1000);
}



//算法判断
//difference区分中级和高级电脑
int algorithm(char board[][COL], int row, int col, int difference){
	if (difference){
		//先要判断自己能否获胜
		//判断行
		for (int i = 0; i < 3; i++){
			if (board[i][0] == WHITE_PIECE && board[i][1] == WHITE_PIECE){
				if (board[i][2] == ' '){
					board[i][2] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[i][0] == WHITE_PIECE && board[i][2] == WHITE_PIECE){
				if (board[i][1] == ' '){
					board[i][1] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[i][1] == WHITE_PIECE && board[i][2] == WHITE_PIECE){
				if (board[i][0] == ' '){
					board[i][0] = WHITE_PIECE;
					return 1;
				}
			}
		}

		//判断列
		for (int i = 0; i < 3; i++){
			if (board[0][i] == WHITE_PIECE && board[1][i] == WHITE_PIECE){
				if (board[2][i] == ' '){
					board[2][i] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[0][i] == WHITE_PIECE && board[2][i] == WHITE_PIECE){
				if (board[1][i] == ' '){
					board[1][i] = WHITE_PIECE;
					return 1;
				}
			}
			else if (board[1][i] == WHITE_PIECE && board[2][i] == WHITE_PIECE){
				if (board[0][i] == ' '){
					board[0][i] = WHITE_PIECE;
					return 1;
				}
			}
		}

		//判断对角线
		if (board[0][0] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[2][2] == ' '){
				board[2][2] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][0] == WHITE_PIECE&&board[2][2] == WHITE_PIECE){
			if (board[1][1] == ' '){
				board[1][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[1][1] == WHITE_PIECE&&board[2][2] == WHITE_PIECE){
			if (board[0][0] == ' '){
				board[0][0] = WHITE_PIECE;
				return 1;
			}
		}
		//判断对角线
		if (board[0][2] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[2][0] == ' '){
				board[2][0] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][2] == WHITE_PIECE&&board[2][0] == WHITE_PIECE){
			if (board[1][1] == ' '){
				board[1][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[2][0] == WHITE_PIECE&&board[1][1] == WHITE_PIECE){
			if (board[0][2] == ' '){
				board[0][2] = WHITE_PIECE;
				return 1;
			}
		}
	}

//高级难度,判断自己不能获胜后,再判断自己是否需要堵住玩家
	//判断行
	for (int i = 0; i < 3; i++){
		if (board[i][0] == BLACK_PIECE && board[i][1] == BLACK_PIECE){
			if (board[i][2] == ' '){
				board[i][2] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[i][0] == BLACK_PIECE && board[i][2] == BLACK_PIECE){
			if (board[i][1] == ' '){
				board[i][1] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[i][1] == BLACK_PIECE && board[i][2] == BLACK_PIECE){
			if (board[i][0] == ' '){
				board[i][0] = WHITE_PIECE;
				return 1;
			}
		}
	}

	//判断列
	for (int i = 0; i < 3; i++){
		if (board[0][i] == BLACK_PIECE && board[1][i] == BLACK_PIECE){
			if (board[2][i] == ' '){
				board[2][i] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[0][i] == BLACK_PIECE && board[2][i] == BLACK_PIECE){
			if (board[1][i] == ' '){
				board[1][i] = WHITE_PIECE;
				return 1;
			}
		}
		else if (board[1][i] == BLACK_PIECE && board[2][i] == BLACK_PIECE){
			if (board[0][i] == ' '){
				board[0][i] = WHITE_PIECE;
				return 1;
			}
		}
	}

	//判断对角线
	if (board[0][0] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[2][2] == ' '){
			board[2][2] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[0][0] == BLACK_PIECE&&board[2][2] == BLACK_PIECE){
		if (board[1][1] == ' '){
			board[1][1] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[1][1] == BLACK_PIECE&&board[2][2] == BLACK_PIECE){
		if (board[0][0] == ' '){
			board[0][0] = WHITE_PIECE;
			return 1;
		}
	}
	//判断对角线
	if (board[0][2] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[2][0] == ' '){
			board[2][0] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[0][2] == BLACK_PIECE&&board[2][0] == BLACK_PIECE){
		if (board[1][1] == ' '){
			board[1][1] = WHITE_PIECE;
			return 1;
		}
	}
	else if (board[2][0] == BLACK_PIECE&&board[1][1] == BLACK_PIECE){
		if (board[0][2] == ' '){
			board[0][2] = WHITE_PIECE;
			return 1;
		}
	}

	//如果行列对角线都不满足,返回0,就随机找值
	return 0;
}

//中级电脑走一步
void middleComputerMove(char board[][COL], int row, int col){
	//算法判断,如果要堵住玩家,立即堵住玩家,返回1,如果不需要,就随机放一颗
	int flag = algorithm(board, ROW, COL,0);

	//先让电脑判断,有没有哪一行或列或对角线是有两颗BLACK_PIECE,如果有,返回1,如果没有,就返回0。
	while (!flag){
		int i = rand() % row;	//0-2之间
		int j = rand() % col;	//0-2之间

		

		if (board[i][j] == ' '){
			board[i][j] = WHITE_PIECE;
			break;
		}
	}
	printf("Computer ... Done\n");
	Sleep(1000);
}

//高级电脑走一步
void seniorComputerMove(char board[][COL], int row, int col){
	//算法判断,先判断自己能否获胜,再判断是否需要堵住玩家,立即堵住玩家,返回1,如果不需要,就随机放一颗
	int flag = algorithm(board, ROW, COL, 1);

	//先让电脑判断,有没有哪一行或列或对角线是有两颗BLACK_PIECE,如果有,返回1,如果没有,就返回0。
	

	while (!flag){
		int i = rand() % row;	//0-2之间
		int j = rand() % col;	//0-2之间



		if (board[i][j] == ' '){
			board[i][j] = WHITE_PIECE;
			break;
		}
	}
	printf("Computer ... Done\n");
	Sleep(1000);
}

void game(int choose){
	int count = 1;	//让电脑第一步占领4个角其中一个,那样困难电脑攻无不克
	char board[ROW][COL];
	InitBoard(board,ROW,COL);	//初始化棋盘

	char result = 'N';	//判断是否有人胜利
	srand((unsigned long)time(NULL));	//随机数种子

	while (1){
		showBoard(board, ROW, COL);	//给玩家看到面板
		//人走一步
		int type=playerMove(board, ROW, COL);	
		if (1 == type){
			printf("您输入的坐标有误,请重新输入!\n");
			continue;
		}
		else if(2==type){
			printf("您输入的坐标已经被占用了,请重新输入!\n");
			continue;
		}
		else{
			printf("Player ... Done!\n");
		}

		result = JudgeResult(board, ROW, COL);//判定结果
		if (result != 'N'){
			break;
		}

		//根据玩家选择的难度,电脑分别走出一步
		if (choose == 1){
			//初级电脑走一步
			ComputerMove(board, ROW, COL);
		}
		else if (choose == 2){
			//中级电脑走一步
			middleComputerMove(board, ROW, COL);
		}
		else if (choose == 3){
			//高级电脑走一步
			if (count == 1){
				//高级电脑第一步要占领四个角其中一个
				if (board[0][0] == ' '){
					board[0][0] = WHITE_PIECE;
					count++;
				}
				else if (board[0][2] == ' '){
					board[0][2] = WHITE_PIECE;
					count++;
				}
				else if (board[2][0] == ' '){
					board[2][0] = WHITE_PIECE;
					count++;
				}
				else{
					board[2][2] = WHITE_PIECE;
					count++;
				}
			}
			else{
				seniorComputerMove(board, ROW, COL);
			}
		}
		else{
			printf("buf");	//出现bug
		}

		result = JudgeResult(board, ROW, COL);//判定结果
		if (result != 'N'){
			break;
		}
	}

	showBoard(board, ROW, COL);	//给玩家看到面板
	//赢了or输了or平局
	switch (result){
	case 'E':
		printf("恭喜你,你和电脑打了一个平手!\n");
		break;
	case BLACK_PIECE:
		printf("恭喜你,你赢了!\n");
		break;
	case WHITE_PIECE:
		printf("You Lost,电脑赢了!\n");
		break;
	default:
		printf("出现bug\n");
		/g!
		break;
	}
	//printf("%c\n", result);
}


//主函数
#include "chess.h"

void menu(){
	printf("##############################\n");
	printf("## 欢迎来到我的三子棋游戏室 ##\n");
	printf("##############################\n");
	printf("## 1.Paly            2.Exit ##\n");
	printf("##############################\n");
	printf("Please Enter Select:>");
}
void menu2(){
	printf("##############################\n");
	printf("## 请选择初级电脑or高级电脑 ##\n");
	printf("##############################\n");
	printf("## 1.初级电脑    2.中级电脑 ##\n");
	printf("##########3.高级电脑##########\n");
	printf("##############################\n");
	printf("Please Enter Select:>");
}
int main(){
	int quit = 0;
	while (!quit){
		int select = 0;
		menu();
		scanf("%d", &select);

		switch (select){//选择是否玩游戏
		case 1:
			system("cls");//清屏操作
			while (1){	 //循环里面,只有选择正确了,才会break。
				menu2();
				int choose = 0;//选择高级or初级电脑
				scanf("%d", &choose);
				if (choose == 1 || choose == 2||choose==3){	//判断玩家是否选择正确,如果不正确重新选择
					game(choose);
					break;
				}
				else{
					system("cls");
					printf("您输入有误,请重新输入!!!\n");
					Sleep(1000);
				}
			}
			break;
		case 2:	
			quit = 1;
			break;
		default:
			system("cls");
			printf("Enter Error!\n");
			//printf("请重新选择!!!!!\n");
			break;
		}
	}

	system("pause");
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值