当前位置:网站首页>C language to achieve 2048 small game direction merging logic
C language to achieve 2048 small game direction merging logic
2022-04-23 18:02:00 【OceanKeeper1215】
void up(void)// Up
{
for(int y=0; y<4; y++)
{
int end = 0;
for(int x=1; x<4; x++)
{
for(int i=x; i>end; i--)
{
if(view[i][y])
{
if(0 == view[i-1][y])
{
// Move
view[i-1][y] = view[i][y];
view[i][y] = 0;
flag = true;
}
else if(view[i][y] == view[i-1][y])
{
// Merge
view[i-1][y] *= 2;
view[i][y] = 0;
end = i;
flag = true;
}
}
}
}
}
}
void down(void)
{
for(int y=0; y<4; y++)
{
int end = 4;
for(int x=3; x>0; x--)
{
for(int i=x; i<end; i++)
{
if(view[i-1][y])
{
if(0 == view[i][y])
{
// Move
view[i][y] = view[i-1][y];
view[i-1][y] = 0;
flag = true;
}
else if(view[i-1][y] == view[i][y])
{
// Merge
view[i][y] *= 2;
view[i-1][y] = 0;
end = i-1;
score +=view[i][y];
flag = true;
}
}
}
}
}
}
void right(void)
{
for(int x=0; x<4; x++)
{
int end = 4;
for(int y=3; y>0; y--)
{
for(int i=y; i<end; i++)
{
if(view[x][i-1])
{
if(0 == view[x][i])
{
// Move
view[x][i] = view[x][i-1];
view[x][i-1] = 0;
flag = true;
}
else if(view[x][i-1] == view[x][i])
{
// Merge
view[x][i] *= 2;
view[x][i-1] = 0;
end = i-1;
score +=view[x][i];
flag = true;
}
}
}
}
}
}
void left(void)
{
for(int x=0; x<4; x++)
{
int end = 0;
for(int y=1; y<4; y++)
{
for(int i=y; i>end; i--)
{
if(view[x][i])
{
if(0 == view[x][i-1])
{
// Move
view[x][i-1] = view[x][i];
view[x][i] = 0;
flag = true;
}
else if(view[x][i] == view[x][i-1])
{
// Merge
view[x][i-1] *= 2;
view[x][i] = 0;
end = i;
score +=view[x][i-1];
flag = true;
}
}
}
}
}
}
版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545105213.html
边栏推荐
- Install pyshp Library
- Pyppeter crawler
- 2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition
- Random number generation of C #
- Use of list - addition, deletion, modification and query
- Re regular expression
- C# 网络相关操作
- GDAL + ogr learning
- xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
- Map basemap Library
猜你喜欢
Using files to save data (C language)
MySQL_01_简单数据检索
Fashion classification case based on keras
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
C network related operations
Implementation of k8s redis one master multi slave dynamic capacity expansion
C# 的数据流加密与解密
Cross domain settings of Chrome browser -- including new and old versions
Eigen learning summary
Detailed deployment of flask project
随机推荐
Queue solving Joseph problem
C language array processing batch data
Crawling mobile game website game details and comments (MQ + multithreading)
JS high frequency interview questions
_ FindText error
Thirteen documents in software engineering
Process management command
Transfer learning of five categories of pictures based on VGg
Docker 安装 MySQL
解决允许在postman中写入注释请求接口方法
Amount input box, used for recharge and withdrawal
Special effects case collection: mouse planet small tail
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
Generate verification code
Crawl the product data of Xiaomi Youpin app
xlsxwriter. exceptions. Filecreateerror: [errno 13] permission denied
C# 网络相关操作
极致体验,揭晓抖音背后的音视频技术
String function in MySQL
Svn simple operation command