当前位置:网站首页>C语言实现2048小游戏方向合并逻辑
C语言实现2048小游戏方向合并逻辑
2022-04-23 05:46:00 【OceanKeeper1215】
void up(void)//向上
{
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])
{
// 移动
view[i-1][y] = view[i][y];
view[i][y] = 0;
flag = true;
}
else if(view[i][y] == view[i-1][y])
{
// 合并
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])
{
// 移动
view[i][y] = view[i-1][y];
view[i-1][y] = 0;
flag = true;
}
else if(view[i-1][y] == view[i][y])
{
// 合并
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])
{
// 移动
view[x][i] = view[x][i-1];
view[x][i-1] = 0;
flag = true;
}
else if(view[x][i-1] == view[x][i])
{
// 合并
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])
{
// 移动
view[x][i-1] = view[x][i];
view[x][i] = 0;
flag = true;
}
else if(view[x][i] == view[x][i-1])
{
// 合并
view[x][i-1] *= 2;
view[x][i] = 0;
end = i;
score +=view[x][i-1];
flag = true;
}
}
}
}
}
}
版权声明
本文为[OceanKeeper1215]所创,转载请带上原文链接,感谢
https://blog.csdn.net/OceanKeeper1215/article/details/119615539
边栏推荐
- 如何安装jsonpath包
- -- SQL query and return limit rows
- Mysql database foundation
- Miscellaneous 1
- [transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
- Export the articles written in CSDN to PDF format
- Plane semi intersecting plate
- [leetcode 228] summary interval
- Rust:在线程池中共享变量
- Robocode教程4——Robocode的游戏物理
猜你喜欢
随机推荐
安全授信
SQL sorts according to the specified content
Easy to use data set and open source network comparison website
NVIDIA Jetson: GStreamer 和 openMAX(gst-omx) 插件
Basic knowledge of network in cloud computing
Generation of verification code
1007 go running (hdu6808) in the fourth game of 2020 Hangzhou Electric Multi school competition
Usage scenario of copyonwritearraylist
安装pyshp库
Use of multithreaded executors
12. Monkeys climb mountains
Guaba and Computational Geometry
[leetcode 228] summary interval
Linux 用rpm的方式安装mysql(超简单)
日志
Option的正确打开方式
[leetcode 6] zigzag transformation
Record the installation and configuration of gestermer on TX2, and then use GST RTSP server
scikit-learn sklearn 0.18 官方文档中文版
Troubleshooting of data deleted and reappeared problems