热门标签 | 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开发板上实现五子棋小游戏。 


推荐阅读
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • 也就是|小窗_卷积的特征提取与参数计算
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了卷积的特征提取与参数计算相关的知识,希望对你有一定的参考价值。Dense和Conv2D根本区别在于,Den ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • Android中高级面试必知必会,积累总结
    本文介绍了Android中高级面试的必知必会内容,并总结了相关经验。文章指出,如今的Android市场对开发人员的要求更高,需要更专业的人才。同时,文章还给出了针对Android岗位的职责和要求,并提供了简历突出的建议。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • 阿,里,云,物,联网,net,core,客户端,czgl,aliiotclient, ... [详细]
  • Metasploit攻击渗透实践
    本文介绍了Metasploit攻击渗透实践的内容和要求,包括主动攻击、针对浏览器和客户端的攻击,以及成功应用辅助模块的实践过程。其中涉及使用Hydra在不知道密码的情况下攻击metsploit2靶机获取密码,以及攻击浏览器中的tomcat服务的具体步骤。同时还讲解了爆破密码的方法和设置攻击目标主机的相关参数。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • [译]技术公司十年经验的职场生涯回顾
    本文是一位在技术公司工作十年的职场人士对自己职业生涯的总结回顾。她的职业规划与众不同,令人深思又有趣。其中涉及到的内容有机器学习、创新创业以及引用了女性主义者在TED演讲中的部分讲义。文章表达了对职业生涯的愿望和希望,认为人类有能力不断改善自己。 ... [详细]
  • C# 7.0 新特性:基于Tuple的“多”返回值方法
    本文介绍了C# 7.0中基于Tuple的“多”返回值方法的使用。通过对C# 6.0及更早版本的做法进行回顾,提出了问题:如何使一个方法可返回多个返回值。然后详细介绍了C# 7.0中使用Tuple的写法,并给出了示例代码。最后,总结了该新特性的优点。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文介绍了在mac环境下使用nginx配置nodejs代理服务器的步骤,包括安装nginx、创建目录和文件、配置代理的域名和日志记录等。 ... [详细]
  • C# WPF自定义按钮的方法
    本文介绍了在C# WPF中实现自定义按钮的方法,包括使用图片作为按钮背景、自定义鼠标进入效果、自定义按压效果和自定义禁用效果。通过创建CustomButton.cs类和ButtonStyles.xaml资源文件,设计按钮的Style并添加所需的依赖属性,可以实现自定义按钮的效果。示例代码在ButtonStyles.xaml中给出。 ... [详细]
  • Imtryingtofigureoutawaytogeneratetorrentfilesfromabucket,usingtheAWSSDKforGo.我正 ... [详细]
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社区 版权所有