热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

GEC6818开发板制作五子棋小游戏

利用GEC6818开发板制作五子棋小游戏软件及版本:Ubuntu18.04.4,SecureCRT,SourceInsight4.0,VMwareWorkstationPro

利用GEC6818开发板制作五子棋小游戏

软件及版本:Ubuntu18.04.4,SecureCRT,Source Insight4.0,VMware Workstation Pro。

主要代码:

main.c

#include
#include "light.h"
#include "ev.h"
#include "bmp.h"
#include "game.h"
int x,y;
int main()
{
Lcd_Init();
Dis_pic("xiaqi.bmp");//封面图片
Get_ev(&x, & y);//开始操作
return 0;
}

bmp.h

#ifndef __BMP_H__
#define __BMP_H__
#include "light.h"
#include
#include "ev.h"
void Dis_pan();
int Dis_pic(char *pic);
//void Draw_Ck(int x0,int y0,int color);
#endif

bmp.c

#include "bmp.h"
#include "ev.h"
int Dis_pic(char *pic)
{
int fd = open(pic,O_RDONLY);
if(-1 == fd)
{
perror("open error");
return -1;
}
int width,height;
short depth;
lseek(fd,0x12,SEEK_SET);
read(fd,&width,4);
read(fd,&height,4);

lseek(fd,0x1c,SEEK_SET);
read(fd,&depth,2);
printf("%d %d %d\n",width,height,depth);
int laizi =( 4-(width * depth / 8) % 4) % 4;
unsigned char color_buf[height*(width*depth/8+laizi)];//32 24
char color_a = 0,color_r,color_g,color_b;//颜色分量
unsigned int color;//像素点的颜色
unsigned char *p = color_buf;
lseek(fd,0x36,SEEK_SET);
int r;
r=read(fd,color_buf,height*(width*depth/8+laizi));
printf("%d %d\n",r,height*(width*depth/8+laizi));
for(int i=height-1;i>=0;i--)
{
for(int j=0;j {
color_b= *p++;//b颜色
color_g= *p++;
color_r= *p++;
if(32 == depth)
{
color_a= *p++;
}
color = color_a <<24 | color_r <<16 |color_g <<8 | color_b;//屏幕需要的颜色a r g b
Display(color, j, i);
}
p+= laizi;
}
}
void Dis_pan()//棋盘
{
for(int i=0;i<480;i++)
{
for(int j = 0;j<800;j++)
{
if(i%40 == 0||j%40 == 0)
Display(0x00, j, i);
else
{
Display(0xffff, j, i);
}
}
}
}
/*void Draw_Ck(int x0,int y0,int color)
{
int flag;
for(int i= 0;i<480;i++)
{
for(int j=0;j<800;j++)
{
if((j-x0)*(j-x0)+(i-y0)*(i-y0)<=10*10)
{
if(flag)
Display(0x0000ff,j,i);
else
Display(0xffffff, j, i);
}
}
}
}*/

ev.h

#ifndef __EV_H__
#define __EV_H__
#include
#include
#include
#include
#include
#include
#include
#include
int Get_ev(int *x,int *y);
#endif

ev.c

#include "ev.h"
#include "bmp.h"
#include "game.h"
int Get_ev(int *x,int *y)
{
int flag=0;
int flag1=3;
int fd = open("/dev/input/event0",O_RDONLY);
if(-1 == fd)
{
perror("open error");
return -1;
}
struct input_event ev;
int x1,y1;

while(1)
{
read(fd,&ev,sizeof(ev));
printf("ev_type = %d code = %d value = %d\n",ev.type,ev.code,ev.value);
if(ev.type == EV_ABS)
{
if(ev.code == 0)//x
{
x1 = ev.value * 800/1024;

}
else
{
y1 = ev.value * 480/600;
}
}
if(ev.type == EV_KEY && ev.code == 330 && ev.value == 1)//保存初始左边
{
*x = x1;
*y = y1;
}
if(ev.type == EV_KEY && ev.code == 330 && ev.value == 0)
{
if(*x == x1 && *y == y1)//点击
{
printf("dianji\n");
if(flag1==1)
Game_Change(x1,y1);
if(flag1!=1)
{
Dis_pan();
flag1=1;
}
}
if(x1 > *x)//右滑
{
printf("youhua\n");
flag1=2;
}
if(x1 <*x)//左滑
{
printf("zuohua\n");

flag1=3;
}
Game_Over();
}
}
}

game.h

#ifndef __GAME_H__
#define __GAME_H__
#include
#include
#include
#include
#include
#include
#include
#include
int Game_Change();
int Dis_zi(int x,int y,int flag);
int Game_Over();
int clear();

#endif

game.c

#include "ev.h"
#include "bmp.h"
#include "game.h"
int flag= 0;
unsigned int Game_buf[12][20] = {0};
int Game_Change(int x,int y)
{
int i,j;
i = x % 40;
j = y % 40;
if(i > 20)
{
i = x / 40 + 1;
}
else
{
i = x / 40;
}
if(j > 20)
{
j = y / 40 + 1;
}
else
{
j = y / 40;
}
x = i * 40;
y = j * 40;
if(Game_buf[j][i]==0)
{
if(flag)
{
Game_buf[j][i]=1;
Dis_zi(y,x,flag);

}
else
{
Game_buf[j][i]=2;
Dis_zi(y,x,flag);
}
flag = ~flag;
}
}
int clear()
{
for(int a=0;a<12;a++)
{
for(int b = 0;b <20;b++)
{
Game_buf[a][b]=0;
}
}
}
int Dis_zi(int x,int y,int flag)
{
int i,j;
if(flag)
{
for(i=0;i<480;i++)
{
for(j=0;j<800;j++)
{
if((i-x)*(i-x)+(j-y)*(j-y)<=330)
{
Display(0x00,j,i);
}
}
}
}
else
{
for(i=0;i<480;i++)
{
for(j=0;j<800;j++)
{
if((i-x)*(i-x)+(j-y)*(j-y)<=330)
{
Display(0x00ffffff,j,i);
}
}
}
}
}
int Game_Over()
{
int a,b,h=1,s=1,x=1,j=1;
for(a = 0;a <12;a++)
{
for(b = 0;b<20;b++)
{
if(Game_buf[a][b]!=0)
{

while(h!=5)
{
if(Game_buf[a][b]==Game_buf[a+h][b])
h++;
else
break;
}
while(s!=5)
{
if(Game_buf[a][b]==Game_buf[a][b+s])
s++;
else
break;
}
while(x!=5)
{
if(Game_buf[a][b]==Game_buf[a+x][b+x])
x++;
else
break;
}
while(j!=5)
{
if(Game_buf[a][b]==Game_buf[a+j][b-j])
j++;
else
break;
}
if(h==5||s==5||x==5||j==5)
{
Dis_pic("bucuoo.bmp");
clear();
}
}
}
}
}

light.h

#ifndef __LIGHT_H__
#define __LIGHT_H__
#include
#include
#include
#include
#include
#include
#include
int Display(int color,int x,int y);
int Lcd_Init();
void Dis_wh();
void Dis_qu();
void Dis_cir();
void Dis_tri();
#endif

light.c

#include "light.h"
unsigned int *plcd =NULL;
#include "ev.h"
int Display(int color,int x,int y)
{
if(x >= 0 && x <= 800 && y >= 0 && y <= 480)
{
*(plcd + y*800+ x) = color;
}
}
int Lcd_Init()
{
int fd = open("/dev/fb0",O_RDWR);
if(-1==fd)
{
perror("open error");
return -1;
}
plcd =mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
}
void Dis_wh()
{
for(int i = 0;i <480;i++)
{
for(int j = 0;j <800;j++)
{
Display(0xffffff,j,i);
}
}

}
//画矩形
void Dis_qu()
{
for(int i= 100;i<300;i++)
{
for(int j=100;j<600;j++)
{
Display(0xffffff,j,i);
}
}
}
//圆形
void Dis_cir()
{
for(int i= 100;i<480;i++)
{
for(int j=100;j<800;j++)
{
if((j-350)*(j-350)+(i-200)*(i-200)<=100*100)
Display(0x00ffff,j,i);
if((j-400)*(j-400)+(i-275)*(i-275)<=100*100)
Display(0xff00ff,j,i);
if((j-450)*(j-450)+(i-200)*(i-200)<=100*100)
Display(0xffff00,j,i);
if(((j-350)*(j-350)+(i-200)*(i-200)<=100*100)&&((j-400)*(j-400)+(i-275)*(i-275)<=100*100)&&((j-450)*(j-450)+(i-200)*(i-200)<=100*100))
Display(0xff0000,j,i);
}
}
}
void Dis_tri()
{
for(int i = 0;i<480;i++)
{
for(int j = 0;j<800;j++)
{
if(i+j<=400)
Display(0xff00ff,j,i);
}
}
}
/*
void Dis_tri()
{
for(int y = 0;y<480;y++)
{
for(int x = 0;x<800;x++)
{
if(x>=100 && y<=300 && y>=100 && y<=-x+400&& y>=x)
Display(0xff00ff,x,y);
}
}
}
*/
/*int main()
{
Lcd_Init();
Dis_wh();
//Dis_wh();
//Dis_qu();
//Dis_cir();
Dis_tri();

return 0;

}*/

代码完成后在Ubuntu控制台终端进行验证 。

代码验证无误后,通过SecureCRT将其烧录到GEC6818开发板当中。

最后即可在GEC6818开发板上实现五子棋小游戏。 


推荐阅读
  • 学习SLAM的女生,很酷
    本文介绍了学习SLAM的女生的故事,她们选择SLAM作为研究方向,面临各种学习挑战,但坚持不懈,最终获得成功。文章鼓励未来想走科研道路的女生勇敢追求自己的梦想,同时提到了一位正在英国攻读硕士学位的女生与SLAM结缘的经历。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 本文介绍了如何将CIM_DateTime解析为.Net DateTime,并分享了解析过程中可能遇到的问题和解决方法。通过使用DateTime.ParseExact方法和适当的格式字符串,可以成功解析CIM_DateTime字符串。同时还提供了关于WMI和字符串格式的相关信息。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • C# 7.0 新特性:基于Tuple的“多”返回值方法
    本文介绍了C# 7.0中基于Tuple的“多”返回值方法的使用。通过对C# 6.0及更早版本的做法进行回顾,提出了问题:如何使一个方法可返回多个返回值。然后详细介绍了C# 7.0中使用Tuple的写法,并给出了示例代码。最后,总结了该新特性的优点。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 3.223.28周学习总结中的贪心作业收获及困惑
    本文是对3.223.28周学习总结中的贪心作业进行总结,作者在解题过程中参考了他人的代码,但前提是要先理解题目并有解题思路。作者分享了自己在贪心作业中的收获,同时提到了一道让他困惑的题目,即input details部分引发的疑惑。 ... [详细]
  • Ubuntu安装常用软件详细步骤
    目录1.GoogleChrome浏览器2.搜狗拼音输入法3.Pycharm4.Clion5.其他软件1.GoogleChrome浏览器通过直接下载安装GoogleChro ... [详细]
  • 本文讨论了clone的fork与pthread_create创建线程的不同之处。进程是一个指令执行流及其执行环境,其执行环境是一个系统资源的集合。在调用系统调用fork创建一个进程时,子进程只是完全复制父进程的资源,这样得到的子进程独立于父进程,具有良好的并发性。但是二者之间的通讯需要通过专门的通讯机制,另外通过fork创建子进程系统开销很大。因此,在某些情况下,使用clone或pthread_create创建线程可能更加高效。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
  • 本文介绍了一道网络流题目hdu4888 Redraw Beautiful Drawings的解题思路。题目要求以行和列作为结点建图,并通过最大流算法判断是否有解以及是否唯一。文章详细介绍了建图和算法的过程,并强调在dfs过程中要进行回溯。 ... [详细]
  • 本文介绍了使用哈夫曼树实现文件压缩和解压的方法。首先对数据结构课程设计中的代码进行了分析,包括使用时间调用、常量定义和统计文件中各个字符时相关的结构体。然后讨论了哈夫曼树的实现原理和算法。最后介绍了文件压缩和解压的具体步骤,包括字符统计、构建哈夫曼树、生成编码表、编码和解码过程。通过实例演示了文件压缩和解压的效果。本文的内容对于理解哈夫曼树的实现原理和应用具有一定的参考价值。 ... [详细]
author-avatar
小丁啊小丁
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有