#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#define NULL 0
#define UP 18432
#define DOWN 20480
#define LEFT 19200
#define RIGHT 19712
#define ESC 283
#define ENTER 7181
struct snake
{int centerx;
int centery;
int newx;
int newy;
struct snake *next;
};
struct snake *head;
int grade=60; /*控制速度的*******/
int a,b; /* 背静遮的 位置*/
void *far1,*far2,*far3,*far4; /* 蛇身指针 背静遮的指针 虫子*/
int size1,size2,size3,size4; /* **全局变量**/
int ch=RIGHT; /**************存按键 开始蛇的方向为RIGHT***********/
int chy=RIGHT;
int flag=0; /*********判断是否退出游戏**************/
int control=4; /***********判断上次方向和下次方向不冲突***/
int nextshow=1; /*******控制下次蛇身是否显示***************/
int scenterx; /***************随即矩形中心坐标***************/
int scentery;
int sx; /*******在a b 未改变前 得到他们的值 保证随机矩形也不在此出现*******/
int sy;
/************************蛇身初始化**************************/
void snakede()
{
struct snake *p1,*p2;
head=p1=p2=(struct snake *)malloc(sizeof(struct snake));
p1->centerx=80;
p1->newx=80;
p1->centery=58;
p1->newy=58;
p1=(struct snake *)malloc(sizeof(struct snake));
p2->next=p1;
p1->centerx=58;
p1->newx=58;
p1->centery=58;
p1->newy=58;
p1->next=NULL;
}
/*******************end*******************/
void welcome() /*************游戏开始界面 ,可以选择 速度**********/
{
int key;
int size;
int x=240;
int y=300;
int f;
void *buf;
setfillstyle(SOLID_FILL,BLUE);
bar(98,100,112,125);
setfillstyle(SOLID_FILL,RED);
bar(98,112,112,114);
setfillstyle(SOLID_FILL,GREEN);
bar(100,100,110,125);
size=imagesize(98,100,112,125);
buf=malloc(size);
getimage(98,100,112,125,buf);
cleardevice();
setfillstyle(SOLID_FILL,BLUE);
bar(240,300,390,325);
outtextxy(193,310,"speed:");
setfillstyle(SOLID_FILL,RED);
bar(240,312,390,314);
setcolor(YELLOW);
outtextxy(240,330,"DOWN");
outtextxy(390,330,"UP");
outtextxy(240,360,"ENTER to start..." );
outtextxy(270,200,"SNAKE");
fei(220,220);
feiyang(280,220);
yang(340,220);
putimage(x,y,buf,COPY_PUT);
setcolor(RED);
rectangle(170,190,410,410);
while(1)
{ if(bioskey(1)) /********8选择速度部分************/
key=bioskey(0);
switch(key)
{
case ENTER:
f=1;
break;
case DOWN:
if(x>=240)
{ putimage(x-=2,y,buf,COPY_PUT);
grade++;
key=0;
break;
}
case UP:
if(x<=375)
{ putimage(x+=2,y,buf,COPY_PUT);
grade--;
key=0;
break;
}
}
if (f==1)
break;
} /********** end ****************/
free(buf);
}
/*************************随即矩形*****************/
/***********当nextshow 为1的时候才调用此函数**********/
void ran()
{ int nx;
int ny;
int show; /**********控制是否显示***********/
int jump=0;
struct snake *p;
p=head;
if(nextshow==1) /***********是否开始随机产生***************/
while(1)
{show=1;
randomize();
nx=random(14);
ny=random(14);
scenterx=nx*22+58;
scentery=ny*22+58;
while(p!=NULL)
{
if(scenterx==p->centerx&&scentery==p->centery||scenterx==sx&&scentery==sy)
{show=0;
jump=1;
break;
}
else
p=p->next;
if(jump==1)
break;
}
if(show==1)
{putimage(scenterx-11,scentery-11,far3,COPY_PUT);
nextshow=0;
break;
}
}
}
/***********过关动画**************/
void donghua()
{ int i;
cleardevice();
setbkcolor(BLACK);
randomize();
while(1)
{for(i=0;i<=5;i++)
{putpixel(random(640),random(80),13);
putpixel(random(640),random(80)+80,2);
putpixel(random(640),random(80)+160,3);
putpixel(random(640),random(80)+240,4);
putpixel(random(640),random(80)+320,1);
putpixel(random(640),random(80)+400,14);
}
setcolor(YELLOW);
settextstyle(0,0,4);
outtextxy(130,200,"Wonderful!!");
setfillstyle(SOLID_FILL,10);
bar(240,398,375,420);
feiyang(300,400);
fei(250,400);
yang(350,400);
if(bioskey(1))
if(bioskey(0)==ESC)
{
flag=1;
break;
}
}
}
/*************************end************************/
/***********************初始化图形系统*********************/
void init()
{int a=DETECT,b;
int i,j;
initgraph(&a,&b,"");
}
/***************************end****************************/
/***画立体边框效果函数******/
void tline(int x1,int y1,int x2,int y2,int white,int black)
{ setcolor(white);
line(x1,y1,x2,y1);
line(x1,y1,x1,y2);
setcolor(black);
line(x2,y1,x2,y2);
line(x1,y2,x2,y2);
}
/****end*********/
/*************飞洋标志**********/
int feiyang(int x,int y)
{int feiyang[18][18]={ {0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,0,0,0},
{0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,0,0,0},
{0,0,0,0,1,1,1,0,0,0,0,0,1,1,1,0,0,0},
{0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0},
{0,0,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,0},
{0,0,1,1,0,1,1,1,1,1,1,0,0,0,0,0,0,0},
{0,0,1,1,1,1,1,0,0,1,0,0,1,1,0,0,0,0},
{0,0,1,1,1,0,0,0,0,1,0,1,1,1,0,0,0,0},
{0,0,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0},
{0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0},
{0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,1,0,0},
{0,0,1,1,1,0,0,1,1,0,0,1,1,0,0,1,0,0},
{0,0,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,0},
{0,0,0,1,1,1,0,1,1,1,1,1,0,0,1,0,0,0},
{0,0,0,0,1,1,1,0,0,0,0,0,0,1,1,0,0,0},
{0,0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0},
{0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0}};
int i,j;
for(i=0;i<=17;i++)
for(j=0;j<=17;j++)
{if (feiyang[i][j]==1)
putpixel(j+x,i+y,RED);
}
}
/********"飞"字*************/
int fei(int x,int y)
{int fei[18][18]={{1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
{0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0},
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,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0},
{0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0},
{1,1,1,1,0
tanchishe.zip_visual c
版权申诉
98 浏览量
2022-09-20
19:30:55
上传
评论
收藏 9KB ZIP 举报
![avatar](https://profile-avatar.csdnimg.cn/36163497263541e6b6d5b627b1692a97_weixin_42653691.jpg!1)
朱moyimi
- 粉丝: 65
- 资源: 1万+
最新资源
- 使用ASP.NET Core和Entity Framework Core来构建一个基本的进销存系统.rar
- 深度学习经典数据集+FER2013面部表情识别+附带使用方法的python代码
- Python中,要实现连接多个相机并识别多个二维码.rar
- 使用FFT算法对一个信号进行分析.rar
- 171cms游戏应用下载系统源码.zip
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
- Java项目:在线蛋糕商城系统(java+jsp+mysql)源码+数据库+期末大作业.zip
- ZapyaClient10_7-1.apk
- 织梦cms站长导航网站源码.zip
- 基于SSM+MySQL的网络投票调查问卷系统源码+数据库(java期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)