好久之前写的2048了
  • 板块灌水区
  • 楼主Archy_
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/8/7 14:18
  • 上次更新2024/8/7 15:12:20
查看原帖
好久之前写的2048了
895312
Archy_楼主2024/8/7 14:18

应该有点小bug,但是我现在看不懂我之前写的啥了,不想修了。

#include<iostream>
#include<cmath>
#include<Windows.h>
#include<conio.h>
#include<ctime>
#include<string>
using namespace std;

int mp[10][10], shuaxin=1, winpd = 2048, povpd = 4, scorec = 0, twin = 0, sjpd = 1 ,sjpd_2 = 0;
unsigned long long scoreh = 1, sscore = 0, score = 0;
int last1 = 4, last2 = 1, last2_2 = 0, last3 = 2048 , last4 = 1 , last4_2 = 0; 

void ShowCursor(bool visible) { 
	CONSOLE_CURSOR_INFO cursor_info = { 20, visible };
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

void color(int x , int y) {//染色 字体颜色 背景颜色 
	if(y==1)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15); 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x); 
}

void load() {//加载动画 
	cout << "L"; Sleep(150);
	cout << "o"; Sleep(150);
	cout << "a"; Sleep(150);
	cout << "d"; Sleep(150);
	cout << "i"; Sleep(150);
	cout << "n"; Sleep(150);
	cout << "g"; Sleep(150);
	cout << "."; Sleep(150);
	cout << "."; Sleep(150);
	cout << "."; Sleep(150);
}

void win() {//胜利动画 
	system("color 04"); cout << "Y"; Sleep(100);
	system("color 06"); cout << "O"; Sleep(100);
	system("color 0e"); cout << "U"; Sleep(100);
	system("color 02"); cout << " "; Sleep(100);
	system("color 09"); cout << "W"; Sleep(100);
	system("color 01"); cout << "I"; Sleep(100);
	system("color 05"); cout << "N"; Sleep(100);
	system("color 04"); cout << "!"; Sleep(100);
	system("color 06"); cout << "!"; Sleep(100);
	system("color 0e"); cout << "!"; Sleep(100);
	system("color 04"); cout << "T"; Sleep(100);
	system("color 06"); cout << "H"; Sleep(100);
	system("color 0e"); cout << "A"; Sleep(100);
	system("color 02"); cout << "N"; Sleep(100);
	system("color 09"); cout << "K"; Sleep(100);
	system("color 01"); cout << " "; Sleep(100);
	system("color 05"); cout << "Y"; Sleep(100);
	system("color 04"); cout << "O"; Sleep(100);
	system("color 06"); cout << "U"; Sleep(100);
	system("color 0e"); cout << " "; Sleep(100);
	system("color 09"); cout << "F"; Sleep(100);
	system("color 01"); cout << "O"; Sleep(100);
	system("color 05"); cout << "R"; Sleep(100);
	system("color 04"); cout << " "; Sleep(100);
	system("color 06"); cout << "P"; Sleep(100);
	system("color 0e"); cout << "L"; Sleep(100);
	system("color 04"); cout << "A"; Sleep(100);
	system("color 06"); cout << "Y"; Sleep(100);
	system("color 0e"); cout << "I"; Sleep(100);
	system("color 02"); cout << "N"; Sleep(100);
	system("color 09"); cout << "G"; Sleep(100);
	system("color 01"); cout << "!"; Sleep(100);
}

void start() {//主界面 
	system("cls");
	cout << "                  ______________________ " << endl;
	cout << "                 |  ver2.0 made by hyf  |" << endl;
	cout << "                 |  总分:" << sscore << "              |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      2048小游戏      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      1.开始游戏      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      2.游戏规则      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      3.游戏设置      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      0.退出游戏      |" << endl;
	cout << "                 |______________________|" << endl;
	cout << "                 请输入数字进行操作...   " << endl;
	cout << "                 ";
	//17空格 

}

void rule() {//游戏规则与玩法
	system("cls");
	cout << "              ________________________________" << endl;
	cout << "             |                                |" << endl;
	cout << "             |         游戏规则与玩法         |" << endl;
	cout << "             |                                |" << endl;
	cout << "             |  游戏由一个a*a的窗口组成,16个  |" << endl;
	cout << "             |  数字由2^n(整数)组成(11>n>0).  |" << endl;
	cout << "             |  通过按动wasd(WASD)键控制,数   |" << endl;
	cout << "             |  字会按照固定方向移动,如行或   |" << endl;
	cout << "             |  列有相邻且相等数字,则合并。   |" << endl;
	cout << "             |________________________________|" << endl;
	cout << "             输入1返回..." << endl;
	cout << "             ";
	//13空格 
}

void set() {//设置界面 
	system("cls");
	cout << "                  ______________________ " << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |       游戏设置       |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      1.游戏界面      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      2.分数加减      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      3.胜利判定      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      4.随机判定      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      5.一键默认      |" << endl;
	cout << "                 |                      |" << endl;
	cout << "                 |      6.返回上级      |" << endl;
	cout << "                 |______________________|" << endl;
	cout << "              1中默认大小为4,2中加分默认相加." << endl;
	cout << "              3中默认为2048.部分操作需要enter" << endl;
	cout << "              请输入数字操作,请用英文输入法" << endl;
	cout << "              ";
}

void dy(int n) {
	if (n == 0)cout << "#";
	if (n == 2) {
		color(8,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 4) {
		color(2,1);
		cout<< n;
		color(-1,1);
	}
    if (n == 8) {
    	color(3,1);
		cout<< n;
		color(-1,1);
    }
    if (n == 16) {
    	color(4,1);
		cout<< n;
		color(-1,1);
	}
    if (n == 32) {
    	color(5,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 64) {
    	color(6,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 128) {
    	color(13,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 256) {
    	color(1,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 512) {
    	color(9,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 1024) {
    	color(10,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 2048) {
    	color(11,1);
		cout<< n;
		color(-1,1);
	}
	if (n == 4096) {
    	color(12,1);
		cout<< n;
		color(-1,1);
	}
	if (n > 4096) {
    	color(14,1);
		cout<< n;
		color(-1,1);
	}
}

void gmot() {//游戏主界面 
	system("cls");
	cout << "       ";
	for (int i = 1; i <= (9 - povpd) * 2; i++) cout << " ";
	cout << " scores:" ;
	color(11,1);
	cout<< score << endl;
	color(-1,1);
	cout << "       ";
	for (int i = 1; i <= (9 - povpd) * 2; i++) cout << " ";
	cout << " ____";
	for (int i = 1; i <= povpd; i++) cout << "_";
	for (int i = 1; i <= povpd - 1; i++) cout << "___";
	cout << endl;
	for (int i = 1; i <= povpd; i++) {
		cout << "       ";
		for (int k = 1; k <= (9 - povpd) * 2; k++) cout << " ";
		cout << "|";
		cout << "    ";
		for (int k = 1; k <= povpd; k++) cout << " ";
		for (int k = 1; k <= povpd - 1; k++) cout << "   ";
		cout << "|" << endl;
		cout << "       ";
		for (int k = 1; k <= (9 - povpd) * 2; k++) cout << " ";
		cout << "|  ";
		for (int j = 1; j <= povpd - 1; j++) { dy(mp[i][j]); cout << "   "; }
		dy(mp[i][povpd]);
		cout << "  |" << endl;
	}
	cout << "       ";
	for (int k = 1; k <= (9 - povpd) * 2; k++) cout << " ";
	cout << "|";
	cout << "____";
	for (int i = 1; i <= povpd; i++) cout << "_";
	for (int i = 1; i <= povpd - 1; i++) cout << "___";
	cout << "|" << endl;
	cout << "请输入w(上),a(左),s(下),d(右),/(返回),0(刷新)操作..." << endl;
}

bool check_move(int x){//方向判断 
    int ckpd1=0,ckpd2=0;
	if (x == 1) {//w 
		for(int j=1;j<=povpd;j++)
			for(int i=1;i<=povpd;i++){
				if(mp[i][j]==0){
					for(int k=i-1;k>=1;k--)
						if(mp[k][j]!=0)ckpd1=mp[k][j];
				    for(int m=i+1;m<=povpd;m++)
						if(mp[m][j]!=0)ckpd2=mp[m][j];
					if(ckpd1!=0&&ckpd2!=0||ckpd1==0){return true;break;}	
				}
				if(mp[i][j]==mp[i+1][j]&&mp[i][j]!=0){return true;break;}
			}
	}
	else if (x == 2) {//a 
		for(int i=1;i<=povpd;i++)
			for(int j=1;j<=povpd;j++){
				if(mp[i][j]==0){
					for(int k=j-1;k>=1;k--)
						if(mp[i][k]!=0)ckpd1=mp[i][k];
				    for(int m=j+1;m<=povpd;m++)
						if(mp[i][m]!=0)ckpd2=mp[i][m];
					if(ckpd1!=0&&ckpd2!=0||ckpd1==0){return true;break;}	
				}
				if(mp[i][j]==mp[i][j+1]&&mp[i][j]!=0){return true;break;}
			}
	}
	else if(x == 3) {//s
		for(int j=1;j<=povpd;j++)
			for(int i=povpd;i>=1;i--){
				if(mp[i][j]==0){
					for(int k=i-1;k>=1;k--)
						if(mp[k][j]!=0)ckpd1=mp[k][j];
				    for(int m=i+1;m<=povpd;m++)
						if(mp[m][j]!=0)ckpd2=mp[m][j];
					if(ckpd1!=0&&ckpd2!=0||ckpd2==0){return true;break;}	
				}
				if(mp[i][j]==mp[i-1][j]&&mp[i][j]!=0){return true;break;}
			}
	}
	else if (x == 4) {//d 
		for(int j=povpd;j>=1;j--)
			for(int i=1;i<=povpd;i++){
				if(mp[i][j]==0){
					for(int k=j-1;k>=1;k--)
						if(mp[i][k]!=0)ckpd1=mp[i][k];
				    for(int m=j+1;m<=povpd;m++)
						if(mp[i][m]!=0)ckpd2=mp[i][m];
					if(ckpd1!=0&&ckpd2!=0||ckpd2==0){return true;break;}	
				}
				if(mp[i][j]==mp[i][j-1]&&mp[i][j]!=0){return true;break;}
			}
	}
	return false;
}

void exit() {//退出动画 
	system("cls");
	cout << "                       ___________" << endl;
	cout << "                      |           |" << endl;
	cout << "                      |  ";
	system("color 04"); cout << "E"; Sleep(400);
	system("color 06"); cout << "x"; Sleep(400);
	system("color 0e"); cout << "i"; Sleep(400);
	system("color 02"); cout << "t"; Sleep(400);
	system("color 09"); cout << "."; Sleep(400);
	system("color 01"); cout << "."; Sleep(400);
	system("color 05"); cout << "."; Sleep(400);
	cout << "  |" << endl;
	cout << "                      |___________|" << endl;
	Sleep(400);
	//22空格 
}

int main() {//主函数
	ShowCursor(false); 
	system("mode con cols=60 lines=31");
	system("title YOU ARE PLAYING 2048 IN C++!");
	system("color 0f");
	srand(time(0));
loop:
	while (true) {
		start();
		string st;
		st = getch();
		if (st == "1") { start(); load(); break; }
		if (st == "2") {
			while (true) {
				rule();
				string rule;
				rule = getch();
				if (rule == "1")break;
				else {
					cout << "输入有误!" << endl << "             ";
					Sleep(300);
					system("cls");
					continue;
				}
			}
		}
		if (st == "3") {
		looop:
			while (true) {
				set();
				string set;
				set = getch();
				if (set == "1") {
					while (true) {
						cout << "请输入界面大小n*n(2<n<10),目前是" << povpd << "." << endl << "              ";
						povpd = getch();
						povpd -= 48;
						if (povpd > 2 && povpd < 13) {
							cout << "设置成功!";
							last1 = povpd;
							for(int i=1;i<=povpd;i++)
								for(int j=1;j<=povpd;j++)
									mp[i][j]=0;
							shuaxin++;		
							Sleep(400);
							goto looop;
						}
						else {
							povpd = last1;
							cout << "设置失败!";
							Sleep(400);
							goto looop;
						}
					}
				}
				if (set == "2") {
					while (true) {
						cout << "每加分是默认的n(n>0)倍.目前是" << scoreh << "倍." << endl << "              ";
						cin >> scoreh;
						if (scoreh > 0) {
							cout << "              设置成功!";
							last2 = scoreh;
							Sleep(400);
							cout << endl << "              启用减分? 1(是) 0(否).目前";
							if (scorec == 1)cout << "已启用." << endl << "              ";
							else cout << "未启用." << endl << "              ";
							scorec = getch();
							scorec -= 48;
							if (scorec == 1 || scorec == 0) {
								cout << "设置成功!";
								last2_2 = scorec;
								Sleep(400);
								goto looop;
							}
							else {
								scorec = last2_2;
								cout << "设置失败!";
								Sleep(400);
								goto looop;
							}
						}
						else {
							scoreh = last2;
							cout << "设置失败!";
							Sleep(400);
							goto looop;
						}
					}
				}
				if (set == "3") {
					while (true) {
						cout << "当出现n(n>32)时游戏胜利.目前是" << winpd << "." << endl << "              ";
						cin >> winpd;
						if (winpd == 64 || winpd == 128 || winpd == 256 || winpd == 512 || winpd == 1024 || winpd == 2048 || winpd == 4096) {
							cout << "              设置成功!";
							last3 = winpd;
							for(int i=1;i<=povpd;i++)
								for(int j=1;j<=povpd;j++)
									mp[i][j]=0;
							shuaxin++;		
							Sleep(400);
							goto looop;
						}
						else {
							winpd = last3;
							cout << "              设置失败!";
							Sleep(400);
							goto looop;
						}
					}
				}
				if (set == "5") {
					while (true) {
						cout << "确定? 1(是) 其他(否)" << endl << "              ";
						string resetmr;
						resetmr = getch();
						if (resetmr == "1") {
							cout << "设置成功!";
							winpd = 2048; povpd = 4; scoreh = 1; scorec = 0 , sjpd = 1 , sjpd_2 = 0;
							last1 = 4; last2 = 1; last2_2 = 0; last3 = 2048; last4 = 1; last4_2 = 0;
							for(int i=1;i<=povpd;i++)
								for(int j=1;j<=povpd;j++)
									mp[i][j]=0;
							shuaxin++;		
							Sleep(400);
							goto looop;
						}
						else {
							cout << "已取消!";
							Sleep(400);
							goto looop;
						}
					}
				}
				if (set == "4") {
					while(true){
						cout << "游戏随机生成n(0<n<4)个数.目前生成:" << sjpd << "." << endl << "              ";
						sjpd = getch();
						sjpd-=48;
						if (sjpd == 1 || sjpd == 2 || sjpd == 3 || sjpd == 4 ){
							cout << "设置成功!"<<endl;
							last4 = sjpd ; 
							Sleep(400);
							cout<< "              是否生成数随机(2~8)?1(是) 其他(否),目前:";
							if(sjpd_2 == 1)cout<<"是."<<endl;
							else cout<<"否."<<endl;
							sjpd_2 = getch();
							sjpd_2 -= 48;
							if(sjpd_2 == 1){
								cout << "              设置成功!"<<endl;
								last4_2 = sjpd_2 ; 
								Sleep(400);
								goto looop;
							}
							else {
								cout << "              已取消!" ;
								sjpd_2 = last4_2;
								Sleep(400);
								goto looop;
							}
						}
						else {
							cout << "设置失败!" ;
							sjpd = last4;
							Sleep(400);
							goto looop;
						} 
					} 
				}
				if (set == "6") { goto loop; }
				if (set != "5" && set != "1" && set != "2" && set != "3" && set != "4" && set != "6") {
					cout << "输入错误!";
					Sleep(400);
					goto looop;
				}
			}
		}
		if (st == "0") { exit(); return 0; }
		if (st != "0" && st != "1" && st != "2" && st != "3") {
			cout << "输入有误!" << endl << "                 ";
			Sleep(300);
			system("cls");
			continue;
		}
	}
lop:
	score = 0;//初始化!
	while (true) {
		for (int i = 1; i <= povpd; i++) {
			for (int j = 1; j <= povpd; j++) {
				if (mp[i][j] == int(pow(2, povpd * povpd - 5)) || mp[i][j] == winpd) {//WIN 
					gmot(); win(); sscore += score; system("color 0f");
					cout << "YOU GOT " << score << " scores." << endl;
					cout << "AGAIN? 1(是) 2(返回) 0(退出)" << endl;
					while (true) {
						string again;
						cin >> again;
						if (again == "1") {
							for (int i = 1; i <= povpd; i++) 
								for (int j = 1; j <= povpd; j++)
									mp[i][j] = 0;
							goto lop;
						}
						else if (again == "2") {
							for (int i = 1; i <= povpd; i++)
								for (int j = 1; j <= povpd; j++)
									mp[i][j] = 0;
							goto loop;
						}
						else if (again == "0") { exit(); return 0; }
						else {
							cout << "输入有误!" << endl;
							Sleep(300);
							system("cls");
							gmot();
							cout << "YOU WIN!THANK YOU FOR PLAYING!" << "YOU GOT " << score << " scores." << endl;
							cout << "AGAIN? 1(是) 2(返回) 0(退出)" << endl;
							continue;
						}
					}
				}
			}
		}
		int pdg=0;
		if(mp[1][1]!=mp[2][1]&&mp[1][1]!=mp[1][2])pdg++;
		if(mp[povpd][povpd]!=mp[povpd-1][povpd]&&mp[povpd][povpd]!=mp[povpd][povpd-1])pdg++;
		if(mp[1][povpd]!=mp[1][povpd-1]&&mp[1][povpd]!=mp[2][povpd])pdg++;
		if(mp[povpd][1]!=mp[povpd][2]&&mp[povpd][1]!=mp[povpd-1][1])pdg++;
		for(int i=2;i<=povpd-1;i++){
			if(mp[1][i]!=mp[1][i-1]&&mp[1][i]!=mp[1][i+1]&&
			   mp[1][i]!=mp[2][i])pdg++;
			if(mp[povpd][i]!=mp[povpd][i+1]&&mp[povpd][i]!=mp[povpd][i-1]&&
			   mp[povpd][i]!=mp[povpd-1][i])pdg++;
			if(mp[i][1]!=mp[i-1][1]&&mp[i][1]!=mp[i+1][1]&&
			   mp[i][1]!=mp[i][2])pdg++;
			if(mp[i][povpd]!=mp[i-1][povpd]&&mp[i][povpd]!=mp[i+1][povpd]&&
			   mp[i][povpd]!=mp[i][povpd-1])pdg++;      
		}
		for(int i=2;i<=povpd-1;i++)
			for(int j=2;j<=povpd-1;j++)
				if(mp[i][j]!=mp[i+1][j]&&mp[i][j]!=mp[i-1][j]&&
			       mp[i][j]!=mp[i][j+1]&&mp[i][j]!=mp[i][j-1])pdg++;  
		if (pdg == povpd * povpd) {
			cout << "GAME OVER!THANK FOR PLAYING!" << endl;
			cout << "YOU GOT " << score << " scores.AGAIN? 1(是) 2(返回) 0(退出)" << endl;
			while (true) {
				string again;
				cin >> again;
				if (again == "1") {
					for (int i = 1; i <= povpd; i++)
						for (int j = 1; j <= povpd; j++)
							mp[i][j] = 0;
					goto lop;
				}
				else if (again == "2") {
					for (int i = 1; i <= povpd; i++)
						for (int j = 1; j <= povpd; j++)
							mp[i][j] = 0;
					goto loop;
				}
				else if (again == "0") { exit(); return 0; }
				else {
					cout << "输入有误!" << endl;
					Sleep(300);
					system("cls");
					gmot();
					cout << "GAME OVER!THANK FOR PLAYING!" << endl;
					cout << "YOU GOT " << score << " scores.AGAIN? 1(是) 2(返回) 0(退出)" << endl;
					continue;
				}
			}
		}
		while (shuaxin) {//随机生成数字
			if(sjpd == 0){sjpd = last4; break;}
		    int cnt=0;
		    for(int i=1;i<=povpd;i++){
		    	for(int j=1;j<=povpd;j++){
		    	    if(mp[i][j]!=0)cnt++;
		    	}
		    }
		    if(cnt==povpd*povpd)break; 	    
			int x = 0, y = 0;
			x = rand() % povpd + 1;//a~b=(b-a+1)+a
			y = rand() % povpd + 1;
			int z = rand() % 3 + 1;
			if (mp[x][y] != 0)continue;
			else { 
			 	mp[x][y] = 2; 
				if(sjpd_2 == 1) mp[x][y] = pow(2,z);
				sjpd--; 
			}
		}
		shuaxin++;
		while (true) {
			gmot();
			string move;
			move = getch();
			if (move == "w" || move == "W") {
				if(!check_move(1)){
					color(11,1);
					cout<<"换个方向试试."<<endl;
					color(-1,1);
					if(scorec)score=score/8*7; 
					Sleep(400);
					system("cls");
					continue;
				}
				for (int j = 1; j <= povpd; j++)
					for (int i = 1; i <= povpd - 1; i++)
						if (mp[i][j] == 0)
							for (int k = i + 1; k <= povpd; k++)
								if (mp[k][j] != 0) {
									mp[i][j] = mp[k][j];
									mp[k][j] = 0;
									break;
								}
				for (int j = 1; j <= povpd; j++)
					for (int i = 1; i <= povpd - 1; i++)
						if (mp[i][j] == mp[i + 1][j] && mp[i][j] != 0) {
							mp[i][j] *= 2;
							score += mp[i + 1][j] * scoreh;
							mp[i + 1][j] = 0;
						}
				for (int j = 1; j <= povpd; j++)
					for (int i = 1; i <= povpd - 1; i++)
						if (mp[i][j] == 0)
							for (int k = i + 1; k <= povpd; k++)
								if (mp[k][j] != 0) {
									mp[i][j] = mp[k][j];
									mp[k][j] = 0;
									break;
								}
				break;
			}
			else if (move == "a" || move == "A" ) {
				if(!check_move(2)){
					color(11,1);
					cout<<"换个方向试试."<<endl;
					color(-1,1);
					if(scorec)score=score/8*7; 
					Sleep(400);
					system("cls");
					continue;
				}
				for (int i = 1; i <= povpd; i++)
					for (int j = 1; j <= povpd - 1; j++)
						if (mp[i][j] == 0)
							for (int k = j + 1; k <= povpd; k++)
								if (mp[i][k] != 0) {
									mp[i][j] = mp[i][k];
									mp[i][k] = 0;
									break;
								}
				for (int i = 1; i <= povpd; i++)
					for (int j = 1; j <= povpd - 1; j++)
						if (mp[i][j] == mp[i][j + 1] && mp[i][j] != 0) {
							mp[i][j] *= 2;
							score += mp[i][j + 1] * scoreh;
							mp[i][j + 1] = 0;
						}
				for (int i = 1; i <= povpd; i++)
					for (int j = 1; j <= povpd - 1; j++)
						if (mp[i][j] == 0)
							for (int k = j + 1; k <= povpd; k++)
								if (mp[i][k] != 0) {
									mp[i][j] = mp[i][k];
									mp[i][k] = 0;
									break;
								}
				break;
			}
			else if (move == "s" || move == "S") {
				if(!check_move(3)){
					color(11,1);
					cout<<"换个方向试试."<<endl;
					color(-1,1);
					if(scorec)score=score/8*7; 
					Sleep(400);
					system("cls");
					continue;
				}
				for (int j = 1; j <= povpd; j++)
					for (int i = povpd; i >= 2; i--)
						if (mp[i][j] == 0)
							for (int k = i - 1; k >= 1; k--)
								if (mp[k][j] != 0) {
									mp[i][j] = mp[k][j];
									mp[k][j] = 0;
									break;
								}
				for (int j = 1; j <= povpd; j++)
					for (int i = povpd; i >= 2; i--)
						if (mp[i][j] == mp[i - 1][j] && mp[i][j] != 0) {
							mp[i][j] *= 2;
							score += mp[i - 1][j] * scoreh;
							mp[i - 1][j] = 0;
						}
				for (int j = 1; j <= povpd; j++)
					for (int i = povpd; i >= 2; i--)
						if (mp[i][j] == 0)
							for (int k = i - 1; k >= 1; k--)
								if (mp[k][j] != 0) {
									mp[i][j] = mp[k][j];
									mp[k][j] = 0;
									break;
								}
				break;
			}
			else if (move == "d" || move == "D") {
				if(!check_move(4)){
					color(11,1);
					cout<<"换个方向试试."<<endl;
					color(-1,1);
					if(scorec)score=score/10*9; 
					Sleep(400);
					system("cls");
					continue;
				}
				for (int i = 1; i <= povpd; i++)
					for (int j = povpd; j >= 2; j--)
						if (mp[i][j] == 0)
							for (int k = j - 1; k >= 1; k--)
								if (mp[i][k] != 0) {
									mp[i][j] = mp[i][k];
									mp[i][k] = 0;
									break;
								}
				for (int i = 1; i <= povpd; i++)
					for (int j = povpd; j >= 2; j--)
						if (mp[i][j] == mp[i][j - 1] && mp[i][j] != 0) {
							mp[i][j] *= 2;
							score += mp[i][j] * scoreh;
							mp[i][j - 1] = 0;
						}
				for (int i = 1; i <= povpd; i++)
					for (int j = povpd; j >= 2; j--)
						if (mp[i][j] == 0)
							for (int k = j - 1; k >= 1; k--)
								if (mp[i][k] != 0) {
									mp[i][j] = mp[i][k];
									mp[i][k] = 0;
									break;
								}
				break;
			}
			else if (move == "/") { shuaxin=0; goto loop; }
			else if (move == "0") {
				for(int i=1;i<=povpd;i++)
					for(int j=1;j<=povpd;j++)
						mp[i][j]=0;
				color(11,1);		
				cout<<"刷新成功!";
				color(-1,1); 
				Sleep(700);		
				goto lop; 
			} 
			else {
				color(11,1);
				cout << "输入有误!" << endl;
				color(-1,1);
				Sleep(300);
				system("cls");
				gmot();
			}
		} 
		for (int i = 1; i <= povpd; i++) {
			for (int j = 1; j <= povpd; j++) {
				if (mp[i][j] == int(pow(2, povpd * povpd - 5)) || mp[i][j] == winpd) {//WIN 
					gmot(); win(); sscore += score; system("color 0f");
					cout << "YOU GOT " << score << " scores." << endl;
					cout << "AGAIN? 1(是) 2(返回) 0(退出)" << endl;
					while (true) {
						string again;
						cin >> again;
						if (again == "1") {
							for (int i = 1; i <= povpd; i++) 
								for (int j = 1; j <= povpd; j++)
									mp[i][j] = 0;
							goto lop;
						}
						else if (again == "2") {
							for (int i = 1; i <= povpd; i++)
								for (int j = 1; j <= povpd; j++)
									mp[i][j] = 0;
							goto loop;
						}
						else if (again == "0") { exit(); return 0; }
						else {
							cout << "输入有误!" << endl;
							Sleep(300);
							system("cls");
							gmot();
							cout << "YOU WIN!THANK YOU FOR PLAYING!" << "YOU GOT " << score << " scores." << endl;
							cout << "AGAIN? 1(是) 2(返回) 0(退出)" << endl;
							continue;
						}
					}
				}
			}
		}
	}
	return 0;
}
2024/8/7 14:18
加载中...