2048小游戏编程
/*By Reason*/
#include
#include
#include
#include #include
#include //为了读取方向键
#include
using namespace std; //srand( (unsigned)time( NULL ) ); //随机数种子 不能用在这里
int pane[4][4]; //棋盘
int N=1; //2的n次方
void showpane() //显示棋盘
{
cout<
cout<
for(int i=0;i<=3;i++)
{
cout<
for(int j=0;j<=3;j++)
{
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED); cout<
if(j==3)
{
cout<
cout<
}
}
}
}
void newgame() //开始游戏
{
N=1;
for(int i=0;i<=3;i++) //初始化棋盘
for(int j=0;j<=3;j++)
pane[i][j]=0;
srand( (unsigned)time( NULL ) );
int m=rand()%4;
int n=rand()%4;
int p=rand()%4;
int q=rand()%4;
pane[m][n]=pane[p][q]=2;