#include "project.h"
//测试
unsigned int *mem_p;
void game2(P_PDI p_pdi){
int i, j, ret, win, first, count1, count2, countkill;
int data[N][N] = {0}; //游戏数组
int olddata[N][N] = {0}; //备份数组
int array[10] = {0}; //猜测数组, 用来表示难度
initarray(array, array_len); //(2)初始化猜测数组
initGame(data, array, array_len); //(3)初始化游戏·界面
if(initbmp() == -1) //(4)打开图片
{
printf("initbmp fail\n");
uninitbmp();
return;
}
ret = checkstart(p_pdi);
if(ret == 1)
{
printf("获取坐标成功");
}
if(ret == -1)
{
sleep(3);
return;
}
clearscreen(p_pdi);
printf("游戏开始\n");
first = 1;
count1 = 0;
count2 = 0;
countkill = 0;
while(1)
{
show(data); //14显示游戏界面
if(ret != 0) //单纯点击时,不改变控制台的游戏界面
{
showGame(data,p_pdi);
}
win = check(data); //16.检查能否继续游戏
if(win == 0 || ret == 16) //游戏结束
{
printf("游戏结束\n");
showlose(p_pdi);
sleep(1);
break;
}
if(win == 2)
{
printf("恭喜你,胜利了\n");
showwin();
sleep(1);
break;
}
ret = paddle_ts(p_pdi); //获取触摸屏情况
switch (ret)
{
case 1: //左划
copyData(data, olddata);
mergeLeft(data, &first, &count1, &count2, &countkill);
produceXY(data, array, array_len);
break;
case 2: //右划
copyData(data, olddata);
mergeRight(data, &first, &count1, &count2, &countkill);
produceXY(data, array, array_len);
break;
case 3: //上划
copyData(data, olddata);
mergeUp(data, &first, &count1, &count2, &countkill);
produceXY(data, array, array_len);
break;
case 4: //下划
copyData(data, olddata);
mergeDown(data, &first, &count1, &count2, &countkill);
produceXY(data, array, array_len);
break;
case 13: //重新开始游戏
copyData(data, olddata);
for(i = 0; i<N; i++)
{
for(j = 0; j<N; j++)
{
data[i][j] = 0;
}
}
produceXY(data, array, array_len);
produceXY(data, array, array_len);
break;
case 14: //清空最大的数字
copyData(data, olddata); //备份数据来方便撤销动作
produceXY(data, array, array_len);
break;
}
system("clear"); //清空控制台屏幕
}
return;
}
//28.显示游戏结束
void showlose(P_PDI p_pdi)
{
int lose = open(bmp_lose, O_RDONLY);
if(lose == -1)
{
printf("open bmp_lose fail\n");
return ;
}
close(lose);
sleep(2);
int defeat = open(bmp_defeat, O_RDONLY);
if(defeat == -1)
{
printf("open bmp_feat fail\n");
return ;
}
close(defeat);
sleep(2);
int end = open(bmp_end, O_RDONLY);
if(end == -1)
{
printf("open bmp_end fail\n");
return ;
}
close(end);
}
//27.显示游戏胜利
void showwin()
{
int victory = open(bmp_victory, O_RDONLY);
if(victory == -1)
{
printf("open bmp_victory fail\n");
return;
}
close(victory);
sleep(2);
int win = open(bmp_win, O_RDONLY);
if(win == -1)
{
printf("open bmp_win fail\n");
return;
}
close(win);
}
//26. 0点击 1左划 2右划 3上划 4下划 12-16特效
int paddle_ts(P_PDI p_pdi)
{
int x = 0, y = 0, xx = 0, yy = 0;
struct input_event ts;
memset(&ts, 0, sizeof(struct input_event));
while (1)
{
//读触摸屏
read(p_pdi->ts,&(p_pdi->touch),sizeof(p_pdi->touch));
//决断是否为相对坐标类型
if(p_pdi->touch.type == EV_ABS && p_pdi->touch.code == ABS_X)
{
x = p_pdi->touch.value;;
}
//决断是否为相对坐标类型
if(p_pdi->touch.type == EV_ABS && p_pdi->touch.code == ABS_Y)
{
y = p_pdi->touch.value;
}
//表示手指按下
if(p_pdi->touch.type == EV_KEY && p_pdi->touch.code == BTN_TOUCH && p_pdi->touch.value == 1)
{
//记录起点坐标
xx = x;
yy = y;
}
//表示手指松开
if(p_pdi->touch.type == EV_KEY && p_pdi->touch.code == BTN_TOUCH && p_pdi->touch.value == 0)
{
//坐标换算 起点坐标
xx = xx;
yy = yy;
//坐标换算 结束坐标
x = x;
y = y;
//如果点击功能菜单区域
if(x>520 && x<760)
{
if(y>0 && y<80)
{
return 11;
}
if(y>80 && y<160)
{
return 12;
}
if(y>160 && y<240)
{
return 13;
}
if(y>240 && y<320)
{
return 14;
}
if(y>320 && y<400)
{
return 15;
}
if(y>400 && y< 480)
{
return 16;
}
}
//点击游戏界面
if(x>0 && x<480)
{
if(abs(xx-x) > abs(yy - y))
{
if((xx - x) > 100)
{
return 1; //左划
}
if((x - xx) >= 100)
{
return 2; //右划
}
return 0;
}
else
{
if((yy - y) > 50)
{
return 3; //上划
}
if((y - yy) >= 50)
{
return 4; //下划
}
return 0;
}
return 0; //点击
}
}
}
return 0;
}
//17.判断是否还有空位
int checkSpace(int data[N][N])
{
int i, j, n;
n = 0;
for(i = 0; i<N; i++)
{
for(j = 0; j<N; j++)
{
if(!data[i][j]) //还有空位
{
n++;
}
}
}
return n;
}
//18.选择一个空坐标,生成数字
void produceXY(int data[N][N], int *array, int n)
{
int i, j, flag, a[2];
flag = checkSpace(data);
if(!flag) //如果没有空位就不用产生数字
{
return;
}
while(1) //一定可以找到空位并产生数字
{
flag = 0;
Random(a, 2); //随机产生一个坐标, (a[0], a[1])
for(i = 0; i<N; i++)
{
for(j = 0; j<N;
没有合适的资源?快使用搜索试试~ 我知道了~
基于6818开发板实现2048小游戏和电子相册
共7个文件
c:5个
demo2:1个
h:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 111 浏览量
2024-03-17
09:06:41
上传
评论
收藏 27KB ZIP 举报
温馨提示
(1)基于6818开发板使用C语言实现2048小游戏和电子相册 (2)2048小游戏实现步骤 1.进行初始化,触摸屏,LCD还有图片的初始化 2.游戏初始化,随机生成两个数字方块,开始进入游戏 3.封装显示图片函数功能 4.点击开始游戏,进入游戏界面 5.显示游戏界面 6.判断手指滑动,是那个开进行计算左划还是右划或者或者上划还是下滑 7.进行数字方块合并 8.判断是否还有空位,进行判断游戏胜负 (3)电子相册实现步骤 1.滑动解锁 2.显示电子相册缩略图 3.点击进入相册应用界面 4.点击图片可进行图片的放大和缩小 5.读取文件目录,分页显示
资源推荐
资源详情
资源评论
收起资源包目录
项目源码.zip (7个子文件)
photo_show.c 10KB
game2.c 23KB
demo2 35KB
draw.c 1KB
project.h 6KB
project_set.c 10KB
main.c 2KB
共 7 条
- 1
资源评论
小风飞子
- 粉丝: 332
- 资源: 1532
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功