c语言贪吃蛇UI界面版.docx
- 文档编号:5918688
- 上传时间:2023-01-02
- 格式:DOCX
- 页数:86
- 大小:32.42KB
c语言贪吃蛇UI界面版.docx
《c语言贪吃蛇UI界面版.docx》由会员分享,可在线阅读,更多相关《c语言贪吃蛇UI界面版.docx(86页珍藏版)》请在冰豆网上搜索。
c语言贪吃蛇UI界面版
c语言UI界面版贪吃蛇
使用ege图形库,游戏实现单双人功能。
道具有炸弹,随机魔盒,炸弹。
有随机障碍物生成。
不附加图片。
/***************************************************************************
*
*
出品方:
债组*
成员:
冯强陈志豪邓青松俄木木果*
时间:
2016/7/11*
*
*
****************************************************************************
*/
#include"graphics.h"
#include
#include
#include
#include
#include
#include
#include
#defineprintfouttext
intspeed=5;
#defineU1
#defineD2
#defineL3
#defineR4
#defineA5
#defineS6
#defineW7
#defineDd8
#defineVK_A0x41//虚拟键值宏定义
#defineVK_S0x53
#defineVK_W0x57
#defineVK_D0X44
#defineVK_N0X4E
#defineVK_M0x4d
#definewd10//蛇身的宽
#definehg10//蛇身的高
//蛇身的一个节点
typedefstructSNAKE
{
intx;
inty;
structSNAKE*next;
}snake;
//全局变量//
intscore=0,add=10,score1=0,add1=10;;//总得分与每次吃食物得分。
intstatus,status1,sleeptime=130,bomb_suiji=1234,wall_suiji=5678,magic_suiji=6589,magic_suiji1=3256;//每次运行的时间间隔
intoneortwo=0;
intdwall=1,isdwall=0;
snake*head,*head1,*food,*bomb,*wall,*magic;
snake*q;//便利第一条蛇用到的指针
snake*q1;//遍历第二条蛇的时候用到的指针
intendgamestatus=0;//游戏结束的情况,
intwall_suiji_u=1111,wall_suiji_d=2222,wall_suiji_r=333,wall_suiji_l=444;
intwall_u,wall_d,wall_l,wall_r;
intuwall_u,uwall_d,uwall_l,uwall_r;
intmagic_x=0,magic_xx;
//后台的函数
voidinitsnake();
voidinitsnake1();
voidcreatmagic();
voidgomagic();
voidcreatefood();
voidcreatbomb();
voidcreatwall();
voiddrawwall();
voidsnakemove();
voidpausegame();
voidgamecircle();
voidwelcomeintogame();
intbiteself();
voidiswin();
voidgamestart();
voidcleanwall();
voidupdatewall();
voidendgame();//iswin改变
voidcantcrosswall();//撞墙,改变值
//UI函数
voidprompt();
voidpause();
voidUI();
voidFence();
voidwelcometogame();
//后台函数
voidgomagic()
{
inti=5;
PIMAGEss;
PIMAGEbj;
MUSICmuc;
MUSICmuc1;
muc.OpenFile("good.mp3");
muc1.OpenFile("bomm.mp3");
bj=newimage();
ss=newimage();
getimage(ss,"ss.png",0,0);//加载蛇身图片
if(oneortwo)
getimage(bj,"m.png",0,0);//加载背景图片
else
getimage(bj,"danren.png",0,0);//加载背景图片
snake*nexthead;
snake*nexthead1;
nexthead=(snake*)malloc(sizeof(snake));
nexthead1=(snake*)malloc(sizeof(snake));
srand((time_t)magic_suiji);
wall_suiji=wall_suiji+3652;
magic_x=rand()%4;
i++;
if(magic_x==0||magic_x==1)
{
if(magic_xx==1)
{
PlaySound("mgwall.wav",NULL,SND_FILENAME|SND_ASYNC);
score=score+add;
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next!
=NULL)
{
putimage(q->x,q->y,wd,hg,ss,0,0);
q=q->next;
}
putimage(q->next->x,q->next->y,wd,hg,bj,q->next->x,q->next->y);
free(q->next);
q->next=NULL;
cleanwall();
drawwall();
}
elseif(magic_xx==3)
{
PlaySound("mgwall.wav",NULL,SND_FILENAME|SND_ASYNC);
score1=score1+add1;
nexthead1->next=head1;
head1=nexthead1;
q1=head1;
while(q1->next->next!
=NULL)
{
putimage(q1->x,q1->y,wd,hg,ss,0,0);
q1=q1->next;
}
putimage(q1->next->x,q1->next->y,wd,hg,bj,q1->next->x,q1->next->y);
free(q1->next);
q1->next=NULL;
cleanwall();
drawwall();
}
}
elseif(magic_x==2)
{
if(magic_xx==1)
{
PlaySound("mgbomb.wav",NULL,SND_FILENAME|SND_ASYNC);
nexthead->next=head;
head=nexthead;
q=head;
while(q->next->next->next!
=NULL)
{
putimage(q->x,q->y,wd,hg,ss,0,0);
q=q->next;
}
putimage(q->next->x,q->next->y,wd,hg,bj,q->next->x,q->next->y);
putimage(q->next->next->x,q->next->next->y,wd,hg,bj,q->next->next->x,q->next->next->y);
updatewall();
free(q->next->next);
free(q->next);
q->next=NULL;
iswin();
}
elseif(magic_xx==2)
{
PlaySound("mgbomb.wav",NULL,SND_FILENAME|SND_ASYNC);
nexthead1->next=head1;
head1=nexthead1;
q1=head1;
while(q1->next->next->next!
=NULL)
{
putimage(q1->x,q1->y,wd,hg,ss,0,0);
q1=q1->next;
}
putimage(q1->next->x,q1->next->y,wd,hg,bj,q1->next->x,q1->next->y);
putimage(q1->next->next->x,q1->next->next->y,wd,hg,bj,q1->next->next->x,q1->next->next->y);
updatewall();
free(q1->next->next);
free(q1->next);
q1->next=NULL;
iswin();
}
}
elseif(magic_x==3)
{
if(magic_xx==2)
{
PlaySound("mggood.wav",NULL,SND_FILENAME|SND_ASYNC);
nexthead1->next=head1;
head1=nexthead1;
q1=head1;
while(q1!
=NULL)
{
putimage(q1->x,q1->y,wd,hg,ss,0,0);
q1=q1->next;
}
updatewall();
score1=score1+add1;
}
elseif(magic_xx==1)
{
PlaySound("mggood.wav",NULL,SND_FILENAME|SND_ASYNC);
nexthead->next=head;
head=nexthead;
q=head;
while(q!
=NULL)
{
putimage(q->x,q->y,wd,hg,ss,0,0);
q=q->next;
}
updatewall();
score=score+add;
if(!
oneortwo)
sleeptime=sleeptime-50;
}
}
}
voidcreatmagic()
{
re:
q=head;
q1=head1;
PIMAGEmagics;
magics=newimage();
getimage(magics,"magic.png",0,0);//加载食物图片
snake*magic_1;
magic_1=(snake*)malloc(sizeof(snake));
srand((time_t)magic_suiji+220);
magic_suiji=magic_suiji+66;
magic_1->x=rand()%280;
magic_1->y=rand()%260;
magic_1->x=(magic_1->x/wd)*wd+250;
magic_1->y=(magic_1->y/wd)*wd+110;//控制坐标保证食物出现在正确的位置并且不会和蛇头错开
if(isdwall==0&&magic_1->x>=310&&magic_1->x<=490&&magic_1->y>=170&&magic_1->y<=300)
{
gotore;
}
while(q->next!
=NULL)
{
if(magic_1->x==q->x&&magic_1->y==q->y)
creatmagic();
q=q->next;
}
if(oneortwo)
{
while(q1->next!
=NULL)
{
if(magic_1->x==q1->x&&magic_1->y==q1->y)
creatmagic();
q1=q1->next;
}
}
q=head;
q1=head;
while(q->next==NULL)
{
if(q->x==magic_1->x||q->y==magic_1->y)//判断蛇身是否与食物重合
{
free(magic_1);
creatmagic();
}
q=q->next;
}
while(q1->next==NULL)
{
if(q1->x==magic_1->x&&q1->y==magic_1->y)//判断蛇身是否与食物重合
{
free(magic_1);
creatmagic();
}
q1=q1->next;
}
magic=magic_1;
putimage(magic_1->x,magic_1->y,wd,hg,magics,0,0);
}
voidupdatewall()
{
if(isdwall)
{
inti;
PIMAGEupwall;
upwall=newimage();
getimage(upwall,"m.png",0,0);
for(i=0;i<100;i=i+10)//1
{
putimage(i+150,uwall_l,wd,hg,upwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(i+530,uwall_r,wd,hg,upwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(uwall_u,i+10,wd,hg,upwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(uwall_d,i+370,wd,hg,upwall,0,0);
}
delimage(upwall);
}
}
voiddrawwall()
{
PlaySound("wall.wav",NULL,SND_FILENAME|SND_ASYNC);
PIMAGEnewwall;
inti;
newwall=newimage();
getimage(newwall,"m.png",0,0);
srand(wall_suiji_u);
wall_u=rand()%480;
srand(wall_suiji_d);
wall_d=rand()%480;
srand(wall_suiji_l);
wall_l=rand()%460;
srand(wall_suiji_r);
wall_r=rand()%460;
wall_suiji_u=wall_suiji_d+74;
wall_suiji_d=wall_suiji_d+85;
wall_suiji_l=wall_suiji_l+90;
wall_suiji_r=wall_suiji_r+74;
wall_u=(wall_u/wd)*wd+150;
wall_d=(wall_d/wd)*wd+150;
wall_l=(wall_l/wd)*wd+10;
wall_r=(wall_r/wd)*wd+10;
uwall_u=wall_u;
uwall_d=wall_d;
uwall_l=wall_l;
uwall_r=wall_r;
for(i=0;i<100;i=i+10)//1
{
putimage(i+150,wall_l,wd,hg,newwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(i+530,wall_r,wd,hg,newwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(wall_u,i+10,wd,hg,newwall,0,0);
}
for(i=0;i<100;i=i+10)//1
{
putimage(wall_d,i+370,wd,hg,newwall,0,0);
}
isdwall=isdwall+1;
}
voidcleanwall()
{
inti;
PIMAGEcleanwall;
cleanwall=newimage();
if(oneortwo)
getimage(cleanwall,"m.png",0,0);
else
getimage(cleanwall,"danren.png",0,0);
if(isdwall)
{
for(i=0;i<100;i=i+10)//1
{
putimage(i+150,wall_l,wd,hg,cleanwall,i+150,wall_l);
}
for(i=0;i<100;i=i+10)//1
{
putimage(i+530,wall_r,wd,hg,cleanwall,i+530,wall_r);
}
for(i=0;i<100;i=i+10)//1
{
putimage(wall_u,i+10,wd,hg,cleanwall,wall_u,i+10);
}
for(i=0;i<100;i=i+10)//1
{
putimage(wall_d,i+370,wd,hg,cleanwall,wall_d,i+370);
}
}
elseif(isdwall==0)
{
putimage(310,180,170,110,cleanwall,310,180);
for(i=0;i<50;i=i+10)
{
putimage(250+i+80-20,200-20,wd,hg,cleanwall,250+i+80-20,200-20);
putimage(290+80-20,200+i-20,wd,hg,cleanwall,290+80-20,200+i-20);
putimage(250+i+80-20,250-20,wd,hg,cleanwall,250+i+80-20,250-20);
putimage(250+80-20,250+i-20,wd,hg,cleanwall,250+80-20,250+i-20);
putimage(200+i+50+80-20,300-20,wd,hg,cleanwall,200+i+50+80-20,300-20);
}
for(i=0;i<50;i=i+10)
{
putimage(250+i+66+80-30,200-20,wd,hg,cleanwall,250+i+66+80-30,200-20);
putimage(290+66+80-30,200+i-20,wd,hg,cleanwall,290+66+80-30,200+i-20);
putimage(250+i+66+80-30,250-20,wd,hg,cleanwall,250+i+66+80-30,250-20);
putimage(250+66+80-30,250+i-20,wd,hg,cleanwall,250+66+80-30,250+i-
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 贪吃 UI 界面