#include<stdio.h>
#include<graphics.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<math.h>
#include<graphics.h>
#include<mmsystem.h>
#pragma comment(lib,"Winmm.lib")
#define PI 3.1415926
int o = 0;
int times = 0;
//int main()
//{
// int arr[4]=
// {
// 0,0,6,9
// };
//
// int i, k;
// for( i = 0 ; i < 3; ++i)
// {
// for( k = i + 1; k < 4; ++k)
// {
// if(arr[i] == 0 && arr[k] > 0)
// {
// arr[i] = arr[k];
// arr[k] = 0;
// break;
// }
// }
// }
// for(i = 0; i < 4; i++)
// {
// printf("%d ",arr[i]);
// }
//}
int main()
{
srand((unsigned int)time(NULL));
//system("color 06");
//system("pause");//暂停一下
PlaySound(L"./从别后.wav", NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
int rani, ranj;
int i, j;
initgraph(960,550);
for(int i=0;i<40;i++)
{
cleardevice();
settextcolor(GREEN);
settextstyle(i, 0, L"宋体");
outtextxy(600,300,L"杨仁凯工作室");
outtextxy(600,350,L"欢迎来到4096Game");
Sleep(30);
}
for(int i=0;i<20;i++)
{
settextcolor(YELLOW);
outtextxy(200-i*10,i*10,L"><");
Sleep(50);
}
int a,b;
for(int i=0,b=20,a=20;i<30&&a>0;i++)
{
if(i>19)
{
outtextxy(200,a*10,L"><");
Sleep(50);
a=a-2;
outtextxy(200,b*10,L"><");
Sleep(50);
b=b+1;
}
outtextxy(i*10,200,L"><");
Sleep(50);
}
for(int i=0,a=0,b=0;i<60;i++)
{
int x1 = 200 - int(90 * sin(PI * 2 * i / 60));
int y1 = 390 - int(90 * cos(PI * 2 * i / 60));
int x = 390 - int(90 * sin(PI * 2 * i / 60));
int y = 200 - int(90 * cos(PI * 2 * i / 60));
settextcolor(BLUE);
outtextxy(x1,y1,L"><");
settextcolor(RED);
outtextxy(x,y,L"><");
if(i>45)
{
settextcolor(BLUE);
a=a+15;
outtextxy(290,390+a,L"><");
}
if(i>30&&i<45)
{
settextcolor(BLUE);
b=b+10;
outtextxy(390,290+b,L"><");
}
Sleep(50);
}
for(int i=0;i<60;i++)
{
int x1 = 480 - int(90 * sin(PI * 2 * i / 60));
int y1 = 440 - int(90 * cos(PI * 2 * i / 60));
outtextxy(x1,y1,L"><");
Sleep(50);
}
settextstyle(20, 0, L"宋体");
outtextxy(0,0,L"请输入enter继续........");
int guan;
guan=getch();
system("cls");
IMAGE ima;
loadimage(&ima,L"代码1.jpg",400,200);
putimage(500,20,&ima);
guan=getch();
closegraph();
int map[4][4] = { {0},{},{},{} };//地图的二维数组
void shang(int map[][4]);
void down(int map[][4]);
void left(int map[][4]);
void right(int map[][4]);
void print(int a[][4]);
void ran(int a[][4]);
void cheat(int a[][4]);
void pass(int a[][4]);
void cheat1(int a[][4]);
void start(int a[][4]);
void zero(int a[][4]);
void color(short x);
ranj = rani = (rand()*rand()) % 4;
map[rani][ranj] = 2;
start(map);
/*键盘输入*/
int input;
int e = 0;
while (1)
{
switch (input = getch())
{
case'w':shang(map);system("cls");ran(map);pass(map);if (map[0][0] == 3 || map[0][0] == 1) { break; }print(map);break;
case's':down(map);system("cls");ran(map);pass(map);if (map[0][0] == 3 || map[0][0] == 1) { break; }print(map);break;
case'a':left(map);system("cls");ran(map);pass(map);if (map[0][0] == 3 || map[0][0] == 1) { break; }print(map);break;
case'd':right(map);system("cls");ran(map);pass(map);if (map[0][0] == 3 || map[0][0] == 1) { break; }print(map);break;
case'q':cheat(map);system("cls");print(map);break;//作弊 直接出2048
case'e':cheat1(map);system("cls");print(map);break;
case'h':system("cls");zero(map);ran(map);print(map);break;
case'j':zero(map);system("cls");e = 1;break;
}
if (e == 1)
{
system("cls");
for (int z = 0;z < 10000;z++)
{
printf("\t\t\t导演:杨仁凯\n");
printf("\t\t\t主演:杨仁凯\n");
printf("\t\t\t制作人:杨仁凯\n");
printf("\t\t\t特别鸣谢:杨仁凯有限公司\n");
}
printf("\t\t\t欢迎下次光临!\n");
break;
}
}
return 0;
}
void shang(int a[4][4])
{
void ran(int a[4][4]);
for (int j = 0;j < 4;j++)
{
for (int i = 0;i < 3;i++)
{
for (int l = 1;l < (4 - i);l++)
{
if (a[i][j] == 0)
{
a[i][j] = a[i + l][j];
a[i + l][j] = 0;
}
else
{
if (a[i + l][j] == a[i][j] || a[i + l][j] == 0)
{
a[i][j] = a[i][j] + a[i + l][j];
a[i + l][j] = 0;
}
else
{
break;
}
}
}
}
}
}
void down(int a[4][4])
{
void ran(int a[4][4]);
for (int j = 0;j < 4;j++)
{
for (int i = 3;i > 0;i--)
{
for (int l = 1;l < i + 1;l++)
{
if (a[i][j] == 0)
{
a[i][j] = a[i - l][j];
a[i - l][j] = 0;
}
else
{
if (a[i - l][j] == a[i][j] || a[i - l][j] == 0)
{
a[i][j] = a[i][j] + a[i - l][j];
a[i - l][j] = 0;
}
else
{
break;
}
}
}
}
}
}
void left(int a[4][4])
{
void ran(int a[4][4]);
for (int i = 0;i < 4;i++)
{
for (int j = 0;j < 3;j++)
{
for (int l = 1;l < (4 - j);l++)
{
if (a[i][j] == 0)
{
a[i][j] = a[i][j + l];
a[i][j + l] = 0;
}
else
{
if (a[i][j + l] == a[i][j] || a[i][j + l] == 0)
{
a[i][j] = a[i][j] + a[i][j + l];
a[i][j + l] = 0;
}
else
{
break;
}
}
}
}
}
}
void right(int a[4][4])
{
void ran(int a[4][4]);
for (int i = 0;i < 4;i++)
{
for (int j = 3;j > 0;j--)
{
for (int l = 1;l < j + 1;l++)
{
if (a[i][j] == 0)
{
a[i][j] = a[i][j - l];
a[i][j - l] = 0;
}
else
{
if (a[i][j - l] == a[i][j] || a[i][j - l] == 0)
{
a[i][j] = a[i][j] + a[i][j - l];
a[i][j - 1] = 0;
}
else
{
break;
}
}
}
}
}
}
//随机出一个二
void end1(int a[][4]);
void ran(int a[4][4])
{
int n = 0;
int rani, ranj;
while (1)
{
rani = (rand()*rand()) % 4;
ranj = (rand()*rand()) % 4;
if (a[rani][ranj] == 0)
{
a[rani][ranj] = 2;
break;
}
else
{
n++;
if (n > 1000)//检查是否结束
{
end1(a);
break;
}
}
}
}
void print(int a[4][4])
{
int i, j;
//printf("\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf("\t\t按(h)重新开始!\t\t\t\t按(j)退出游戏!\n");
printf("\t\t按((e) x x)指定消除数字");
printf("\t\t\t剩余消除次数:%d\n\n", (3 - times));
printf(" 0 1 2 3\n");
printf(" ");
printf("++++++++++++++++++++++++++++++++\n");
for (i = 0;i < 4;i++)
{
for (j = 0;j < 4;j++)
{
if (j == 0)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf(" %d ", i);
}
if (a[i][j] == 0)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf("+ +");
}
else
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a[i][j] * 45);
printf("+%4d +", a[i][j]);
}
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf("\n ");
printf("++++++++++++++++++++++++++++++++\n");
}
o++;
if (0 > 20)
o = 1;
for (int x = 0;x < o;x++)
{
printf(" ");
}
printf("杨仁凯的最快纪录只要四步\n");
for (int x = 0;x < o;x++)
{
printf(" ");
}
printf("你比杨仁凯差很多!\n");
}
/*最弊*/
void cheat(int a[4][4])
{
int rani, ranj;
while (1)
{
rani = (rand()*rand()) % 4;
ranj = (rand()*rand()) % 4;
if (a[rani][ranj] == 0)
{
a[rani][ranj] = 2048;
break;
}
else
continue;
}
}
/*作弊 消除*/
void cheat1(int a[4][4])
{
if (times < 3)
{
int i, j;
scanf("%d%d", &i, &j);
a[i][j] = 0;
times++;
}
}
/*通关*/
void pass(int a[][4])
{
int(*x)[4] = a;
int i, j;
int end = 0;
for (i = 0;i < 4;i++)
{
for (j = 0;j < 4;j++)
{
if (a[i][j] == 4096)
{
printf("\n\n\n\n");
printf(" ******* ****** ****** ******\n");
printf(" ******* ****** ****** ******\n");
printf(" *** ******* ****** ****** ******\n");
printf(" *** ******* ****** ****** ******\n");
printf(" *********************** ************** ****** ******\n");
printf(" ************************ ************** ****** ******\n");
printf(" **** ******* ****** ****** ******\n");
printf(" **** ******* ****** **************** ****************\n");
printf(" ******* ****** **************** ****************\n");
printf(" *********************** ************** ****** ******\n");
printf(" *********************** ************** ****** ******\n");
printf(" ******* ****** ****** ******\n");
printf(" ******* ****** ****** ******\n");
printf(" ******* ****** ****** ******\n");
printf(" ******* ********** **************** ****************\n");
printf(" ******* ********** **************** ****************\n");
a[0][0] = 3;
printf("想重新挑战杨仁凯请按(h)\t想认他做大哥请按(j)\n");
break;
}
}
}
}
void start(int a[][4])
{
printf("\n\n\n\n\n\n\n\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("6666666666 6666666666\n");
printf("6666666666 6666666666\n");
printf("6666666666 6666666666\n");
printf("6666666666 *** *** ************ ************ ************ 6666666666\n");
printf("6666666666 *** *** ************ ************ ************ 6666666666\n");
printf("6666666666 *** *** *** *** *** *** *** 6666666666\n");
printf("6666666666 *** *** *** *** *** *** *** 6666666666\n");
printf("6666666666 *** *** *** *** *** *** *** 6666666666\n");
printf("6666666666 ************ *** *** ************ ************ 6666666666\n");
printf("6666666666 ************ *** *** ************ ************ 6666666666\n");
printf("6666666666 *** *** *** *** *** *** 6666666666\n");
printf("6666666666 *** *** *** *** *** *** 6666666666\n");
printf("6666666666 *** *** *** *** *** *** 6666666666\n");
printf("6666666666 *** ************ ************ ************ 6666666666\n");
printf("6666666666 *** ************ ************ ************ 6666666666\n");
printf("6666666666 6666666666\n");
printf("6666666666 6666666666\n");
printf("6666666666 6666666666\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666\n");
printf("\t\t请做出选择:\n\t\t如果想愉快的玩耍请按1~~\t\t如果不想玩请按2!");
int iput;
switch (iput = getch())
{
case'1':system("cls");printf("开始你愉快的玩耍!\n");print(a);break;
case'2':system("cls");printf("你不玩也得玩!\n");print(a);break;
}
}
/*清零*/
void zero(int a[][4])
{
for (int i = 0;i < 4;i++)
for (int j = 0;j < 4;j++)
a[i][j] = 0;
times = 0;
}
void color(short x)
{
if (x >= 0 && x <= 15)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
else
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}
/*输了*/
void end1(int a[][4])
{
int flag = 0;
for (int i = 1;i < 3;i++)
for (int j = 1;j < 3;j++)
{
if (a[i][j] == a[i][j + 1] || a[i][j] == a[i][j - 1] || a[i][j] == a[i - 1][j] || a[i][j] == a[i + 1][j])
flag = 1;
}
if (a[0][0] == a[0][1] || a[0][0] == a[1][0] || a[3][3] == a[3][2] || a[3][3] == a[2][3] || a[3][0] == a[3][1] || a[3][0] == a[2][0])
flag = 1;
if (a[0][3] == a[0][2] || a[0][3] == a[1][3])
flag = 1;
if (flag == 0)
{
printf("************ ************ **************** ************\n");
printf("************ ************ **************** ************\n");
printf("*** *** *** **************** *** ***\n");
printf("*** *** *** ** ** ** *** ***\n");
printf("*** *** *** ** ** ** *** ***\n");
printf("*** ****** ************ ** ** ** ************\n");
printf("*** ****** ************ ** ** ** ************\n");
printf("*** *** *** *** ** ** ** *** \n");
printf("*** *** *** *** ** ** ** *** \n");
printf("************ *** *** ** ** ** ************\n");
printf("************ *** *** ** ** ** ************\n");
a[0][0] = 1;
printf("想重新挑战杨仁凯请按(h)\t想认他做大哥请按(j)\n");
}
}