当前位置:网站首页>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
边栏推荐
- Advanced operation of idea debug
- Failure to deliver XID in Seata distributed transaction project
- [leetcode217] there are duplicate elements
- Use of multithreaded executors
- NVIDIA Jetson: GStreamer 和 openMAX(gst-omx) 插件
- [leetcode 150] evaluation of inverse Polish expression
- 基于pygame库编写的五子棋游戏
- 爬取手游网站游戏详情和评论(MQ+多线程)
- 检测技术与原理
- 基于Sentinel+Nacos 对Feign Client 动态添加默认熔断规则
猜你喜欢
电机与拖动(戚金清版)学习整理
几行代码教你爬取LOL皮肤图片
[leetcode 401] binary Watch
Rust的闭包类型(Fn, FnMut, FnOne的区别)
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
Export the articles written in CSDN to PDF format
St table template
Motor and drive (Qi Jinqing Edition)
定位器
[leetcode 19] delete the penultimate node of the linked list
随机推荐
Generation of verification code
Code neat way to learn
MySQL table constraints and table design
Integration and induction of knowledge points of automatic control principle (Han min version)
Sakura substring thinking
Type conversion in C #
安装pyshp库
Problems and solutions of database migration
Record the installation and configuration of gestermer on TX2, and then use GST RTSP server
渔网道路密度计算
Best practices for MySQL storage time
Rust 的多线程安全引用 Arc
Techniques et principes de détection
[leetcode 59] spiral matrix II
Motor and drive (Qi Jinqing Edition)
Import of data
基于Sentinel+Nacos 对Feign Client 动态添加默认熔断规则
Export of data
NVIDIA Jetson: GStreamer 和 openMAX(gst-omx) 插件
Excel打开超大csv格式数据