当前位置:网站首页>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
边栏推荐
- Re expression régulière
- 2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
- JS forms the items with the same name in the array object into the same array according to the name
- undefined reference to `Nabo::NearestNeighbourSearch
- Tell the truth of TS
- [UDS unified diagnostic service] IV. typical diagnostic service (6) - input / output control unit (0x2F)
- YOLOv4剪枝【附代码】
- 2022 tea artist (primary) examination simulated 100 questions and simulated examination
- Amount input box, used for recharge and withdrawal
- C1小笔记【任务训练篇二】
猜你喜欢

mysql自动启动设置用Systemctl start mysqld启动

Batch export ArcGIS attribute table

The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time

Halo 开源项目学习(二):实体类与数据表

JS high frequency interview questions

C1小笔记【任务训练篇二】

Detailed deployment of flask project

positioner

An example of linear regression based on tensorflow

Romance in C language
随机推荐
.104History
Uniapp custom search box adaptation applet alignment capsule
MySQL 中的字符串函数
Auto.js 自定义对话框
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Excel opens large CSV format data
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
Install pyshp Library
String function in MySQL
Go的Gin框架学习
Halo 开源项目学习(二):实体类与数据表
Docker 安装 Redis
C#字节数组(byte[])和字符串相互转换
Docker 安装 MySQL
2022 Jiangxi energy storage technology exhibition, China Battery exhibition, power battery exhibition and fuel cell Exhibition
QTableWidget使用讲解
.104History
Use of list - addition, deletion, modification and query
Docker 安裝 Redis
The JS timestamp of wechat applet is converted to / 1000 seconds. After six hours and one day, this Friday option calculates the time