贪吃蛇程序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(); }

Hostodo:4款便宜美国vps七折优惠低至$13/年;NVMe阵列1Gbps带宽,免费DirectAdmin授权

hostodo怎么样?快到了7月4日美国独立日,hostodo现在推出了VPS大促销活动,提供4款Hostodo美国独立日活动便宜VPS,相当于7折,低至$13/年,续费同价。Hostodo美国独立日活动结束时间不定,活动机售完即止。Hostodo商家支持加密数字货币、信用卡、PayPal、支付宝、银联等付款。Hostodo美国独立日活动VPS基于KVM虚拟,NVMe阵列,1Gbps带宽,自带一个...

青云互联19元/月,美国洛杉矶CN2GIA/香港安畅CN2云服务器低至;日本云主机

青云互联怎么样?青云互联美国洛杉矶cn2GIA云服务器低至19元/月起;香港安畅cn2云服务器低至19元/月起;日本cn2云主机低至35元/月起!青云互联是一家成立于2020年的主机服务商,致力于为用户提供高性价比稳定快速的主机托管服务。青云互联本站之前已经更新过很多相关文章介绍了,青云互联的机房有香港和洛杉矶,都有CN2 GIA线路、洛杉矶带高防,商家承诺试用7天,打死全额退款点击进入:青云互联...

tmhhost:暑假快乐,全高端线路,VPS直接8折,200G高防,美国gia日本软银韩国cn2香港cn2大带宽

tmhhost为2021年暑假开启了全场大促销,全部都是高端线路的VPS,速度快有保障。美国洛杉矶CN2 GIA+200G高防、洛杉矶三网CN2 GIA、洛杉矶CERA机房CN2 GIA,日本软银(100M带宽)、香港BGP直连200M带宽、香港三网CN2 GIA、韩国双向CN2。本次活动结束于8月31日。官方网站:https://www.tmhhost.com8折优惠码:TMH-SUMMER日本...

贪吃蛇程序为你推荐
交通流双实线掉头怎么处罚?裂缝检测房屋裂缝找什么部门做鉴定计算机网络安全试题计算机安全的基本知识有哪些?焦点论坛房产都有什么论坛?数据库系统概论数据库系统概论的重点是哪些章节?声源定位内囊位于何处?内蒙古工业大学地址内蒙古工业大学怎么样数据挖掘的应用机器学习在数据挖掘中的应用中山大学南校区地址中山大学各个校区的地址,专业分布寻找手机怎样在手机关机的状态下寻找手机
河北服务器租用 景安vps 国外idc ixwebhosting 512m内存 北京双线机房 卡巴斯基免费试用 重庆双线服务器托管 免费私人服务器 厦门电信 数据库空间 秒杀品 lamp架构 测速电信 google搜索打不开 winds websitepanel symantec 日本小学生 vi命令 更多