在这里插入图片描述将代码存到D:\vs项目路径,并下载easyx库后即可试玩
或者加个windows.h玩不带图形版的。
本蒟蒻很菜,如有bug请私信我,本代码没有注释
#include <iostream>
#include <graphics.h>
#include <time.h>
#include <conio.h>
#include<cstdlib>
//#include <windows.h>
using namespace std;
int map[4][4];
int num;
int score=0;
int if_neednew = 0;
IMAGE img[12];
int imgnum[12] = {
0,2,4,8,16,32,64,128,256,512,1024,2048 };
int is_over = 0;
void loadresourse()
{
;
}
void left()
{
int i, j, k;
for (i = 0; i < 4; i++)
{
for (k = 0, j = 1; j < 4; j++)
{
if (map[i][j] > 0)
{
if (map[i][k] == map[i][j])
{
map[i][k] = 2 * map[i][k];
map[i][j] = 0;
if_neednew = 1;
}
else if (map[i][k] == 0)
{
map[i][k] = map[i][j];
map[i][j] = 0;
if_neednew = 1;
}
else
{
map[i][++k] = map[i][j];
}
if (k != j)
{
map[i][j] = 0;
if_neednew = 1;
}
}
}
}
}
void right()
{
int i, j, k;
for (i = 0; i < 4; i++)
{
for (k = 3, j = 2; j >= 0; j--)
{
if (map[i][j] > 0)
{
if (map[i][k] == map[i][j])
{
map[i][k] = 2 * map[i][k];
map[i][j] = 0;
if_neednew = 1;
}
else if (map[i][k] == 0)
{
map[i][k] = map[i][j];
map[i][j] = 0;
if_neednew = 1;
}
else
{
map[i][--k] = map[i][j];
}
if (k != j)
{
map[i][j] = 0;
if_neednew = 1;
}
}
}
}
}
void up()
{
int i, j, k;
for (i = 0; i < 4; i++)
{
for (k = 0, j = 1; j < 4; j++)
{
if (map[j][i] > 0)
{
if (map[k][i] == map[j][i])
{
map[k][i] = 2 * map[k][i];
map[j][i] = 0;
if_neednew