更改了下连接:
<http://pan.baidu.com/s/1hsiFCv6>
by lzr20040310 @ 2016-12-03 22:45:41
如果你懒得开网盘,且你有c++的话......
源程序:
```cpp
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<conio.h>
using namespace std;
int x[4+10][4+10];
char c;
char operation[6+10]={0,'w','s','a','d','g','y'};
int dp[16+10][2+10],dpn;
int up( ){
int i,j,k,s=0;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
if(x[i][j]!=0)
for(k=i-1;k>0;k--){
if(x[k][j]==0){
x[k][j]=x[k+1][j];
x[k+1][j]=0;
}
else if(x[k][j]==x[k+1][j]){
x[k][j]*=2;
s+=x[k][j];
x[k+1][j]=0;
}
else
break;
}
return s;
}
int down( ){
int i,j,k,s=0;
for(i=4;i>0;i--)
for(j=1;j<5;j++)
if(x[i][j]!=0)
for(k=i+1;k<5;k++){
if(x[k][j]==0){
x[k][j]=x[k-1][j];
x[k-1][j]=0;
}
else if(x[k][j]==x[k-1][j]){
x[k][j]*=2;
s+=x[k][j];
x[k-1][j]=0;
}
else
break;
}
return s;
}
int left( ){
int i,j,k,s=0;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
if(x[i][j]!=0)
for(k=j-1;k>0;k--){
if(x[i][k]==0){
x[i][k]=x[i][k+1];
x[i][k+1]=0;
}
else if(x[i][k]==x[i][k+1]){
x[i][k]*=2;
s+=x[i][k];
x[i][k+1]=0;
}
else
break;
}
return s;
}
int right( ){
int i,j,k,s=0;
for(i=1;i<5;i++)
for(j=4;j>0;j--)
if(x[i][j]!=0)
for(k=j+1;k<5;k++){
if(x[i][k]==0){
x[i][k]=x[i][k-1];
x[i][k-1]=0;
}
else if(x[i][k]==x[i][k-1]){
x[i][k]*=2;
s+=x[i][k];
x[i][k-1]=0;
}
else
break;
}
return s;
}
int game( ){
srand((unsigned)time(NULL));
int i,j,n,m,s=0,v;
bool p,q,u,d,l,r;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
x[i][j]=0;
n=rand( )%4+1;
m=rand( )%4+1;
x[n][m]=(rand( )%2)*2+2;
while(1){
n=rand( )%4+1;
m=rand( )%4+1;
if(x[n][m]==0){
x[n][m]=(rand( )%2)*2+2;
break;
}
}
for(i=1;i<5;i++){
for(j=1;j<5;j++)
printf("%d ",x[i][j]);
putchar('\n');
}
while(1){
u=false;
d=false;
l=false;
r=false;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
if(x[i][j]!=0){
if((!u) && i>1 && (x[i-1][j]==0 || x[i-1][j]==x[i][j]))
u=true;
if((!d) && i<4 && (x[i+1][j]==0 || x[i+1][j]==x[i][j]))
d=true;
if((!l) && j>1 && (x[i][j-1]==0 || x[i][j-1]==x[i][j]))
l=true;
if((!r) && j<4 && (x[i][j+1]==0 || x[i][j+1]==x[i][j]))
r=true;
}
if(!(u || d || l || r)){
system("cls");
printf("Game Over!\nThe Score is %d\nDo You Play Again?\n",s);
c=getch( );
if(c==operation[6])
game( );
return 0;
}
c=getch( );
if((c==operation[1] && u) || (c==operation[2] && d) || (c==operation[3] && l) || (c==operation[4] && r)){
system("cls");
if(c==operation[1] && u)
s+=up( );
else if(c==operation[2] && d)
s+=down( );
else if(c==operation[3] && l)
s+=left( );
else if(c==operation[4] && r)
s+=right( );
dpn=0;
for(i=1;i<5;i++)
for(j=1;j<5;j++)
if(x[i][j]==0){
dpn++;
dp[dpn][1]=i;
dp[dpn][2]=j;
}
n=rand( )%(dpn+1)+1;
x[dp[n][1]][dp[n][2]]=(rand( )%2)*2+2;
for(i=1;i<5;i++){
for(j=1;j<5;j++)
printf("%4d ",x[i][j]);
putchar('\n');
}
printf("The Score is %d\n",s);
}
else if(c==operation[5]){
system("cls");
printf("Game Over!\nThe Score is %d\nDo You Play Again?\n",s);
c=getch();
if(c==operation[6])
game( );
return 0;
}
}
return 0;
}
int main( ){
system("color 70");
game( );
return 0;
}
```
by lzr20040310 @ 2016-12-03 22:48:24
下次极有可能是扫雷(注意是"极有可能")
by lzr20040310 @ 2016-12-03 22:49:16
有BUG~~233~~
比如:
8 4 2 2 -> 16 0 0 0
by huhao @ 2016-12-04 08:27:28
请不要叫做BUG,要的就是这个效果
by lzr20040310 @ 2016-12-04 11:05:22
怎么玩? @lzr20040310
by Red_w1nE @ 2016-12-04 14:51:48
wsad,不用按回车
@[Red\_w1nE](/space/show?uid=23845)
by lzr20040310 @ 2016-12-05 18:11:41
md
我都有了!
by Shan_Xian @ 2016-12-06 20:37:40
@[lzr20040310](/space/show?uid=18182)
--------开始编译--------
bye-bye.cpp:5:18: fatal error: conio.h: No such file or directory
compilation terminated.
编译结束但存在 1 警告
by LiBai @ 2016-12-09 12:12:30
Sorry
并不是所有的Dev-cpp都有conio.h的库
如果需要,我可以给你,只是需要时间
by lzr20040310 @ 2016-12-09 20:29:07