跳到正文

剪贴板

剪贴板 5jnp2avf

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int now,t1,t2,r,n=3,m=3,x=1,y=1,step;
int a[105][105];
char c,s[4]= {' ',' ',' '};
time_t t;
void wait(string s){
	int v=0;
	for(int i=1;i<=100;i+=rand()%5+1){
		cout<<i<<'%'<<endl<<"正在"<<s<<"中";
		v++;
		if(v==6)cout<<'.';
		if(v==12)cout<<"..";
		if(v==18){cout<<"...";v=0;}
		system("cls");
	}
	cout<<s<<"成功";
	Sleep(1000);
	system("cls");

}
void mulu(int a=0){
	cout<<"主页";
	if(a==2)cout<<">教程";
	if(a==1)cout<<">经典游戏";
	if(a==3)cout<<">自定义";
	if(a==21)cout<<">自定义>方形";
	if(a==22)cout<<">自定义>矩阵";
	cout<<endl<<endl;
}
void print(int p){
	system("cls");
	mulu(p+r);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			cout<<(a[i][j]?"亮":"暗")<<(((i==x)&&(j==y))?'<':' ');
		cout<<endl;
	}
}
void dfs(){
	a[x][y]=!a[x][y];
	a[x+1][y]=!a[x+1][y];
	a[x-1][y]=!a[x-1][y];
	a[x][y+1]=!a[x][y+1];
	a[x][y-1]=!a[x][y-1];
}
bool chek(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(!a[i][j])
				return 0;
	return 1;
}
void win(){
	t2=time(0);
	system("cls");
	cout<<"恭喜你赢了!"<<endl;
	cout<<"总共用时:"<<t2-t1<<endl;
	cout<<"总共步数:"<<step<<endl;
	system("pause");
}
void game(int p=1){
	memset(a,0,sizeof a);
	system("cls");
	if(p==20){
		mulu(3);
		cout<<"您是要正方形还是长方形呢?"<<endl<<"1正方形,2长方形";
		r=getch();
		system("cls");
		mulu(3);
		cout<<"请输入长:(>=2,<=100)"<<endl;cin>>n;
		while(1){
			system("cls");
			mulu(3);
			if(n<2||n>100)cout<<"你输入的长太大/太小了!请重新输入:"<<endl;
			else break;
			cin>>n;
		}m=n;
		if(r!=1){
			r=2;
			cout<<"请输入宽:(>=2,<=100)"<<endl;cin>>m;
			while(1){
				system("cls");
				mulu(3);
				if(m<2||m>100)cout<<"你输入的宽太大/太小了!请重新输入:"<<endl;
				else break;
				cin>>m;
			}
		}
	}
	wait("加载");
	wait("建模");
	print(p);
	t1=time(0);
	while(1){
		c=getch();
		step++;
		switch (c) {
			case 'w':
				if(--x<1)x=n;
				break;
			case 's':
				if(++x>n)x=1;
				break;
			case 'a':
				if(--y<1)y=m;
				break;
			case 'd':
				if(++y>m)y=1;
				break;
			case 'j':
				dfs();
				break;
			case 'n':
				return;
				break;
		}
        if(chek()){
			win();
			return;
		}
		print(p);
	}
}
void begin(){
	cout<<"                           ----欢迎您来到水箱----";
	Sleep(2500);
	system("cls");
	wait("加载");
	while(1) {
		system("cls");
		s[now]='<';
		mulu();
		cout<<"自定义游戏 "<<s[0]<<endl;
		cout<<"经典游戏 "<<s[1]<<endl;
		cout<<"游戏教程 "<<s[2]<<endl;
		cout<<"退出 "<<s[3]<<endl<<endl;
		cout<<"wsad上下控制,j确定";
		c=getch();
		system("cls");
		switch(c) {
			case 'w': {
				s[now]=' ';
				if(--now<0)now=3;
				break;
			}
			case 's': {
				s[now]=' ';
				if(++now>3)now=0;
				break;
			}
			case 'j': {
				if(now==0)game(20);
				if(now==1)game();
				if(now==2){
					system("cls");
					mulu(2);
					cout<<"wasd控制选中的单元格"<<endl;
					cout<<"j选定,k表示测验是否赢,n退出"<<endl<<endl;
					cout<<"每次选定,将周围四个方向与自己改变状态"<<endl<<endl;
					cout<<"当所有格子亮了就赢了"<<endl<<endl;
					system("pause");
					system("cls");
				}
				if (now==3)
					return;
				break;
			}
		}
	}
}
int main(){
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO CursorInfo;
	GetConsoleCursorInfo(handle,&CursorInfo);
	CursorInfo.bVisible = false;
	SetConsoleCursorInfo(handle, &CursorInfo);
	srand((unsigned)time(&t));
	begin();
	return 0;
}