贪吃蛇程序c++贪食蛇程序
贪吃蛇程序 时间:2022-03-02 阅读:(
)
c++贪食蛇程序
#include<stdio.h> #include<graphics.h> #include<bios.h> #include<stdlib.h> #include<conio.h> #define BC LIGHTBLUE #define FC RED #define LEFT 0x4b00 #define RIGHT 0x4d00 #define DOWN 0x5000 #define UP 0x4800 #define ESC 0x011b void drawmat(char *mat,int matsize,int x,int y,int color); void ashui(); void printsnake(int x,int y,int corlor); void moveh(int *x,int *y,char (*p)[30],int dir); void movet(int *tx,int *ty,char (*p)[30]); void food(char (*p)[30]); void main() { int x,y,tx,ty,driver=DETECT,mode,key,key1;char snake[40][30]={0}; initgraph(&driver,&mode,""); ashui(); setcolor(RED); rectangle(80,80,520,420) ; rectangle(100,100,500,400) ; setfillstyle(SOLID_FILL, BC); floodfill(200,200,RED); printsnake(2,15,FC); printsnake(3,15,FC); snake[2][15]=snake[3][15]=1; food(snake); key=RIGHT; x=3;y=15;tx=2;ty=15; for(;;) { if(bioskey(1))key1=bioskey(0); if(key1==ESC)break; if(key1==LEFT&&key!=RIGHT||key1==RIGHT&&key!=LEFT||key1==UP&&key!=DOWN||key1==DOWN&&key!=UP)key=key1; moveh(&x,&y,snake,key); if(snake[x][y]!=5) { movet(&tx,&ty,snake); if(x<0||x>39||y<0||y>29) {printsnake(x,y,0); break; } else if(snake[x][y])break; } else food(snake); delay(10000); } moveto(260,240); outtext("GAME OVER!"); getch(); getch(); } void printsnake(int x,int y,int corlor) { int xx,yy; setfillstyle(SOLID_FILL, corlor); setcolor(corlor); xx=100+10*x+5; yy=100+10*y+5; circle(xx,yy,5); floodfill(xx,yy,corlor); } void moveh(int *x,int *y,char (*p)[30],int dir) { int i,j; i=*x;j=*y; switch(dir) { case RIGHT:p[i][j]=1;(*x)++;break; case UP:p[i][j]=2;(*y)--;break; case LEFT:p[i][j]=3;(*x)--;break; case DOWN:p[i][j]=4;(*y)++;break; } printsnake(*x,*y,FC); } void movet(int *tx,int *ty,char (*p)[30]) { int i,j; i=*tx;j=*ty; printsnake(i,j,BC); switch(p[i][j]) { case 1:(*tx)++;break; case 2:(*ty)--;break; case 3:(*tx)--;break; case 4:(*ty)++;break; } p[i][j]=0; } void food(char (*p)[30]) { int x,y; for(;;) { srand( (unsigned)time(NULL)); x=random(40); y=random(30); if(!p[x][y])break; } printsnake(x,y,WHITE); p[x][y]=5; } void drawmat(char *mat,int matsize,int x,int y,int color) { int i, j, k, n; n = (matsize - 1) / 8 + 1; for(j = 0; j < matsize; j++) for(i = 0; i < n; i++) for(k = 0;k < 8; k++) if(mat[j * n + i] & (0x80 >> k)) putpixel(x + i * 8 + k, y + j, color); } void ashui() { char tan32K[]={ 0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00, 0x00,0x03,0x00,0x00,0x00,0x07,0x00,0x00, 0x00,0x07,0x80,0x00,0x00,0x0C,0x60,0x00, 0x00,0x18,0x30,0x00,0x00,0x38,0x1C,0x00, 0x00,0x73,0x0E,0x00,0x00,0xE1,0x83,0x80, 0x01,0x80,0x01,0xF0,0x03,0x03,0xF0,0xFE, 0x06,0x7E,0x70,0x3E,0x0C,0x00,0xC0,0x00, 0x30,0x00,0x80,0x00,0x40,0x01,0x00,0x00, 0x00,0x43,0xF8,0x00,0x00,0x7C,0x1C,0x00, 0x00,0x60,0x18,0x00,0x00,0x63,0x18,0x00, 0x00,0x63,0x18,0x00,0x00,0x63,0x18,0x00, 0x00,0x62,0x18,0x00,0x00,0x62,0x18,0x00, 0x00,0x46,0x18,0x00,0x00,0x04,0x00,0x00, 0x00,0x0C,0xC0,0x00,0x00,0x18,0x70,0x00, 0x00,0x30,0x38,0x00,0x00,0x60,0x1C,0x00, 0x01,0xC0,0x0C,0x00,0x02,0x00,0x04,0x00, }; char chi32K[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00, 0x00,0x00,0x70,0x00,0x00,0x00,0x70,0x00, 0x00,0x00,0x60,0x00,0x00,0x00,0xE0,0x00, 0x00,0x00,0xC1,0x80,0x00,0x01,0x9F,0xC0, 0x00,0xC1,0xFE,0x00,0x67,0xE3,0x00,0x00, 0x7C,0xE2,0x00,0x00,0x20,0xC4,0x00,0x00, 0x30,0xC8,0x00,0x00,0x30,0x80,0x38,0x00, 0x30,0x81,0xF8,0x00,0x17,0xC7,0x60,0x00, 0x1E,0x00,0x60,0x00,0x10,0x00,0xC0,0x00, 0x10,0x00,0xC0,0x00,0x00,0x00,0x80,0x08, 0x00,0x01,0x80,0x08,0x00,0x01,0x00,0x08, 0x00,0x01,0x00,0x08,0x00,0x03,0x00,0x18, 0x00,0x01,0x80,0x3C,0x00,0x01,0xFF,0xF8, 0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char she32K[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x1C,0x00,0x01,0x80,0x0E,0x00, 0x01,0x80,0x06,0x00,0x01,0x80,0x02,0x00, 0x00,0x80,0x00,0x00,0x00,0x80,0x00,0x70, 0x00,0x80,0x87,0xF8,0x00,0xBC,0xF8,0x30, 0x3F,0xCE,0xC0,0x60,0x18,0x8D,0x80,0x40, 0x18,0x89,0x80,0x00,0x08,0x89,0x30,0x40, 0x08,0xB8,0x10,0x60,0x0B,0xE0,0x10,0xE0, 0x0C,0x80,0x11,0xC0,0x00,0x88,0x13,0x00, 0x00,0x8C,0x1C,0x00,0x00,0x8C,0x10,0x00, 0x00,0xF6,0x30,0x08,0x03,0xC4,0x30,0x08, 0x7F,0x00,0x10,0x08,0x3C,0x00,0x10,0x18, 0x00,0x00,0x18,0x3C,0x00,0x00,0x0F,0xFC, 0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; char a16S[]={ 0x00,0x00,0x7B,0xFE,0x48,0x08,0x50,0x08, 0x60,0x08,0x53,0xE8,0x4A,0x28,0x4A,0x28, 0x4A,0x28,0x6B,0xE8,0x50,0x08,0x40,0x08, 0x40,0x08,0x40,0x08,0x40,0x28,0x40,0x10, }; char shui16S[]={ 0x01,0x00,0x01,0x00,0x01,0x08,0x01,0x10, 0x7D,0x20,0x05,0xC0,0x05,0x40,0x09,0x20, 0x09,0x20,0x11,0x10,0x11,0x18,0x21,0x0E, 0xC1,0x04,0x01,0x00,0x05,0x00,0x02,0x00, }; char zuo16S[]={ 0x08,0x80,0x0C,0x80,0x09,0x00,0x13,0xFE, 0x12,0x80,0x34,0x88,0x50,0xFC,0x90,0x80, 0x10,0x80,0x10,0x84,0x10,0xFE,0x10,0x80, 0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x80, }; char pin16S[]={ 0x00,0x00,0x0F,0xF0,0x08,0x10,0x08,0x10, 0x08,0x10,0x0F,0xF0,0x08,0x10,0x00,0x00, 0x7E,0xFC,0x42,0x84,0x42,0x84,0x42,0x84, 0x42,0x84,0x7E,0xFC,0x42,0x84,0x00,0x00, }; drawmat(tan32K,32,150,180,BLUE); drawmat(chi32K,32,300,180,BLUE); drawmat(she32K,32,450,180,BLUE); drawmat(a16S,16,350,250,RED); drawmat(shui16S,16,370,250,RED); drawmat(zuo16S,16,390,250,RED); drawmat(pin16S,16,410,250,RED); getch(); cleardevice(); }
修罗云怎么样?修罗云是一家国内老牌商家,修罗云商家以销售NAT机器起家,国内的中转机相当不错,给的带宽都非常高,此前推荐的也都是国内NAT VPS机器。今天,云服务器网(www.yuntue.com)小编主要介绍一下修罗云的香港云服务器,适合建站,香港沙田cn2云服务器,2核2G,5M带宽仅70元/月起,同时香港香港大带宽NAT VPS低至50元/月起,性价比不错,可以尝试一下!点击进入:修罗云官...
亚洲云Asiayun怎么样?亚洲云Asiayun好不好?亚洲云成立于2021年,隶属于上海玥悠悠云计算有限公司(Yyyisp),是一家新国人IDC商家,且正规持证IDC/ISP/CDN,商家主要提供数据中心基础服务、互联网业务解决方案,及专属服务器租用、云服务器、云虚拟主机、专属服务器托管、带宽租用等产品和服务。Asiayun提供源自大陆、香港、韩国和美国等地骨干级机房优质资源,包括B...
sharktech怎么样?sharktech (鲨鱼机房)是一家成立于 2003 年的知名美国老牌主机商,又称鲨鱼机房或者SK 机房,一直主打高防系列产品,提供独立服务器租用业务和 VPS 主机,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹,所有产品均提供 DDoS 防护。此文只整理他们家10Gbps专用服务器,此外该系列所有服务器都受到高达 60Gbps(可升级到 100Gbps)的保护。...
贪吃蛇程序为你推荐
alexa排名助手有什么方法可以提高alexa排名?或者软件?北京移动官网北京的移动网站官网是必须注册吗?湖北文理学院地址湖北文理学院教课办在哪北方民族大学地址北方民族学校好吗?具体位置在宁夏哪?是几本啊?杭州工作室杭州有特色的工作室?哪家拍婚纱照服务好?杭州工作室杭州那么多工作室,怎么挑选呢?是影楼好还是工作室好?交通信号灯控制系统交通信号灯控制用PLC如何编写程序?csol进不去CSOL怎么进不去游戏?cmnet设置CMNET怎样在手机里设置会议管理平台会议系统后台管理有什么功能模块?
西安服务器租用 域名查询软件 日本私人vps 免费申请网站域名 老域名全部失效请记好新域名 流媒体服务器 英语简历模板word 表格样式 抢票工具 php探针 美国php空间 2017年万圣节 新家坡 isp服务商 100m独享 metalink 鲁诺 跟踪路由命令 智能dns解析 国外的代理服务器 更多