C++小游戏(原创)——数独(sudoku)

 C++小游戏(原创)——数独(sudoku)_第1张图片

C++小游戏(原创)——数独(sudoku)_第2张图片

C++小游戏(原创)——数独(sudoku)_第3张图片

#include 
#include 
#include 
#include 
#include
using namespace std;
int a[15][15],ans_pre,ans[15][15],b[15][15];
bool square[10][10],lie[10][10],hang[10][10],flag[15][15];
bool check;
bool f[15];
int c[15]; 
int difficult;

void SetColor(unsigned short ForeColor=7,unsigned short BackGroundColor=0)
{
	HANDLE hCon=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);
}
int ge(int x,int y)
{
    return(((x-1)/3)*3+(y-1)/3+1);
}

int print(){
	SetColor(15);
	printf("╔━━━┳━━━┳━━━");
	SetColor(9);
	printf("┳");
	SetColor(15);
	printf("━━━┳━━━┳━━━");
	SetColor(9);
	printf("┳");
	SetColor(15);
	printf("━━━┳━━━┳━━━┓\n");
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
        	if(a[i][j]==0) 
			{
				if(j==4||j==7) SetColor(9);
					cout<<"┃   ";
				SetColor(15);
				if (j==9)  cout<<"┃";
			}else 
			{
				if(j==4||j==7) SetColor(9);
				cout<<"┃ ";
				SetColor(15);
				if(b[i][j]==0) SetColor(4);
				cout<3||difficult<1) cin>>difficult;
}
void run(){
	int sum=0;
	switch(difficult){
		case 1:sum=20;
				break;
		case 2:sum=40;
				break;
		case 3:sum=60;
				break;
		
	}
	int i=1;
	while(i<=sum)
	{
		int x,y;
		x=rand()%9+1;
		y=rand()%9+1;
		while(a[x][y]==0) 
		{
			x=rand()%9+1;
			y=rand()%9+1;
		}
		a[x][y]=0;
		i++;
	}
}
int main()
{
	init();
	run();
	system("cls");
	memcpy(b,a,sizeof(a));
	print();
	int xx,yy,zz;


/*	for(int i=1;i<=9;i++)
	{
		for(int j=1;j<=9;j++)
			cout<>xx>>yy>>zz)
	{
		if(xx==0&&yy==0&&zz==0)
		{
			system("cls");
			print_y();
			break;
		}
		if(b[xx][yy]==0) a[xx][yy]=zz;
		system("cls");
		print();
		cout<<"Please Keydown the Standard Input Like 'x y z' Which Means that You Will Fill the Square(x,y) in Num 'z'\n\n";
		cout<<"You can Keydown x y 0 to Clean The Square(x,y)\n\n";
		cout<<"You can Keydown 0 0 0 to Get the Right Answer\n\n";
		if(b[xx][yy]!=0)
		{
			SetColor(4);
			cout<<"The Square You Fill in is Filled.\n";
			SetColor(15);
		}
	}
	
	
	system("pause");
    return 0;
}

 

你可能感兴趣的:(c++小游戏)