## 2048/简易/欢迎提出建议

2048/简易/欢迎提出建议

天下无双·工作室(学而思网校编程社区的学生自创工作室) 出品
本产品仅为实验版本,并不代表最终品质
版本号:20190404 1.0.00
作品代码:由本工作室提供,若想采取,请加微信:19948681215 并通过同意
预计点赞人数:1200人 观看人数:≤10000人
本作品是NOIP班级同学自愿编写,若有兴趣,请加微信咨询
出品人:张晏阳 张琦 陈徐诺言等
若有版权问题,请尽快联系
*如有雷同 纯属巧合
产品代言人:陈刚老师、李扬老师、康静静老师
请点赞,谢谢!
代码由本人编写
https://code.xueersi.com/home/project/detail?lang=code&pid=948888&version=2.0&form=cpp(点赞地址)

#include<bits/stdc++.h>
#include <unistd.h>
using namespace std;
int a[5][5],b[5][5];
int random1tox(int x)
{
	return rand()%x+1;
}
void newgame()
{
	system("cls");
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	return;
}
void juzhong(int n)
{
	if(n==0)
		printf("      ");
	else if(n>0 && n<10)
		printf("  %d   ",n);
	else if(n>9 && n<100)
		printf("  %d  ",n);
	else if(n>100 && n<10000)
		printf(" %d  ",n);
	return;
}
void left()
{
	memset(b,0,sizeof(b));
	int i;
	int j,k;
	for(k=1;k<=4;k++)
	{
		for(i=1;i<=4;i++)
		{
			for(j=2;j<=4;j++)
			{
				if(a[i][j-1]==0 && j-1>=1)
				{
					a[i][j-1]=a[i][j];
					a[i][j]=0;
					b[i][j-1]=b[i][j];
					b[i][j]=0;
				}
				else if(a[i][j-1]==a[i][j] && j-1>=1 && b[i][j]==0 && b[i][j-1]==0)
				{
					a[i][j-1]=a[i][j]*2;
					a[i][j]=0;
					b[i][j-1]=1;
				}
			}
		}
	}
	return;
}
void right()
{
	memset(b,0,sizeof(b));
	int i;
	int j,k;
	for(k=1;k<=4;k++)
	{
		for(i=1;i<=4;i++)
		{
			for(j=3;j>=1;j--)
			{
				if(a[i][j+1]==0 && j+1<=4)
				{
					a[i][j+1]=a[i][j];
					a[i][j]=0;
					b[i][j+1]=b[i][j];
					b[i][j]=0;
				}
				else if(a[i][j+1]==a[i][j] && j+1<=4 && b[i][j]==0 && b[i][j+1]==0)
				{
					a[i][j+1]=a[i][j]*2;
					a[i][j]=0;
					b[i][j+1]=1;
				}
			}
		}
	}
	return;
}
void up()
{
	memset(b,0,sizeof(b));
	int i;
	int j,k;
	for(k=1;k<=4;k++)
	{
		for(i=1;i<=4;i++)
		{
			for(j=4;j>=2;j--)
			{
				if(a[j-1][i]==0 && j-1>=1)
				{
					a[j-1][i]=a[j][i];
					a[j][i]=0;
					b[j-1][i]=b[j][i];
					b[j][i]=0;
				}
				else if(a[j-1][i]==a[j][i] && j-1>=1 && b[j][i]==0 && b[j-1][i]==0)
				{
					a[j-1][i]=a[j][i]*2;
					a[j][i]=0;
					b[j-1][i]=1;
				}
			}
		}
	}
	return;
}
void down()
{
	memset(b,0,sizeof(b));
	int i;
	int j,k;
	for(k=1;k<=4;k++)
	{
		for(i=1;i<=4;i++)
		{
			for(j=3;j>=1;j--)
			{
				if(a[j+1][i]==0 && j+1<=4)
				{
					a[j+1][i]=a[j][i];
					a[j][i]=0;
					b[j+1][i]=b[j][i];
					b[j][i]=0;
				}
				else if(a[j+1][i]==a[j][i] && j+1<=4 && b[j][i]==0 && b[j+1][i]==0)
				{
					a[j+1][i]=a[j][i]*2;
					a[j][i]=0;
					b[j+1][i]=1;
				}
			}
		}
	}
	return;
}
int main()
{
    system("export TERM=xterm && clear");
    cout << "\033[042m" << endl;
    system("export TERM=xterm && clear");
    for(int a = 1; a <= 11; a++)
    {
        cout << endl;
    }
    cout << " 请按下z即可开机" << endl;
    char a_1;
    cout << ' '; cin >> a_1;
    if(a_1 == 'z')
    {
        sleep(1);
        cout << "\033[043m" <<  endl;
        cout << " ------------------------------准备开机------------------------------" << endl;
        cout << "\033[044m" << endl;
        sleep(2);
        system("export TERM=xterm && clear");
        for(int a = 1; a <= 11; a++)
        {
            cout << endl;
        }
        cout << " 开机中..." ;
        sleep(1);
        cout << ".";
        sleep(1);
        cout << ".";
        sleep(1);
        cout << ".";
        sleep(1);
        cout << ".";
        sleep(1);
        cout << ".";
        sleep(1);
        cout << "  ⚡"<< endl;
        sleep(1);
        system("export TERM=xterm && clear");
        cout << "\033[047m" << endl;
        cout << "\033[030m" << endl;
        system("export TERM=xterm && clear");
        cout << endl;
        cout << " 开机已成功!" << endl;
        cout << "\033[036m"<<endl;
        cout << " 天下无双·工作室出品电脑!请谨慎使用!" << endl;
        cout << " 请输入您本人的姓名,以便实名认证,谢谢!" << endl;
        cout << endl;
        cout << " 请输入您的姓名:";
        string c;
        cin >> c;
        cout << " 正在实名认证中。。。" << endl;
        sleep(2);
        system("export TERM=xterm && clear");
        cout << endl;
        cout << " 根据上面的认证,你的名字是:" << c << "  请设置密码:";
        string d;
        cin >> d;
        cout << endl;
        cout << " 谢谢配合!" << endl;
        sleep(2);
        cout << "\033[041m"<<endl;
        cout << "\033[037m"<<endl;
        system("export TERM=xterm && clear");
        cout << "\033[003m" << endl;
        srand(time(0));     
        cout << "每日一句~" << endl;
        cout << endl;
        int i_1;
        i_1 = rand() % 4;
        if(i_1 == 0)
        {
            cout << "待到山花烂漫时,她在丛中笑。---###" << endl;
        }
        if(i_1 == 1)
        {
            cout << "六盘山上高峰,红旗漫卷西风。---###"<< endl ;
        }
        if(i_1 == 2)
        {
            cout << "北国风光,千里冰封,万里雪飘。---###"<< endl ;
        }
        if(i_1 == 3)
        {
            cout << "恰同学少年,风华正茂;书生意气,挥斥方遒。---###"<< endl ;
        }
        for(int a = 1; a <= 11; a++)
        {
            cout << endl;
        }
        cout << "\033[000m" << endl;
        cout << "\033[041m"<<endl;
        cout << "用户名:";
        string e;
        cin >> e;
        if(e == c)
        {
            cout << "请输入密码:";
            string f;
            cin >> f;
            if(f == d)
            {
                cout << endl;
                cout << "恭喜你,登陆成功!" << endl;
                sleep(2);
            }
            else
            {
                cout << "\033[041m" << endl;
                cout << "x" << endl; 
                return 0;
            }
            system("export TERM=xterm && clear");
            cout << "\033[047m" << endl;
            cout << "\033[036m" << endl;
            system("export TERM=xterm && clear");
            cout << endl;
            cout << "你知道什么是2048吗?让我们来看看" << endl;
            sleep(2);
            cout << endl;
            cout << "2048游戏共有16个格子,初始时初始数字由2或者4构成。 1.手指向一个方向滑动,所有格子会向那个方向运动。 2.相同数字的两个格子,相撞时数字会相加。 3.每次滑动时,空白处会随机刷新出一个数字的格子。 4.当界面不可运动时(当界面全部被数字填满时),游戏结束;当界面中最大数字是2048时,游戏胜利。" << endl;
            sleep(5);
            system("export TERM=xterm && clear");
            cout << "\033[047m" << endl;
            cout << "\033[036m" << endl;
            system("export TERM=xterm && clear");
            char c='0';
	int x,y,n,e=0,d=0;
	while (1)
	{
		system("cls");
		printf("\t\t\t  2048\n1.开始游戏\n0.退出\n");
		cin>>c;
		if(c=='1')
		{
			newgame();
			while (1)
			{
				int flag=0;
				for(int i=1;i<=4;i++)
				{
					for(int j=1;j<=3;j++)
						if(a[i][j]==0 || a[i][j+1]==0 || a[i][j]==a[i][j+1])
						{
							flag=1;
							break;
						}
					if(flag)
						break;
				}
				if(!flag)
				{
					for(int i=1;i<=4;i++)
					{
						for(int j=1;j<=3;j++)
							if(a[j][i]==0 || a[j+1][i]==0 || a[j][i]==a[j+1][i])
							{
								flag=1;
								break;
							}
						if(flag)
							break;
					}
				}
				if(!flag)
				{ 
					system("cls");
					printf("你输了!\n1.重来\n0.退出");
					cin>>c;
					if(c==0)
						return 0; 
					else
						continue;
				}
				e=1;
				d=1;
				x=random1tox(4);
				y=random1tox(4);
				while(1)
				{
					if(a[x][y]==0)
						break;
					else
					{
						x=random1tox(4);
						y=random1tox(4);
					}
				}
				n=random1tox(2)*2;
				a[x][y]=n;
				system("cls");
				printf("╔════════════════════════╗\n");
				for(int i=1;i<=12;i++)
				{
					int flag=0;
					printf("║");
					for(int j=1;j<=24;j++)
					{
						if(i%3!=2 || e<1 || d<1)
							printf(" ");
						else if(i%3==2)
						{
							juzhong(a[e][1]);
							juzhong(a[e][2]);
							juzhong(a[e][3]);
							juzhong(a[e][4]);
							break;
						}
					}
					if(i%3==2)
						e++;
					else
						flag=1;
					printf("║\n");
				}
				printf("╚════════════════════════╝\n");
				char tmp[10];
				gets(tmp);
				cin>>c;
				switch (c)
				{
					case 'a':left();break;
					case 'd':right();break;
					case 'w':up();break;
					case 's':down();break;
				}	
				system("export TERM=xterm && clear");
			}			
		}
		else
			return 0;
		
		cout << "准备关机" << endl;
		for(int a = 1; a <= 4; a++)
		{
		    sleep(1);
		    cout << "." << endl;
		}
	}
        }
        else
        {
            cout << "\033[041m" << endl;
            cout << "x" << endl; 
            return 0;
        }
    }
    
    else
    {
        cout << "\033[041m" << endl;
        cout << "x" << endl; 
        return 0;
    }
	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值