为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

贪吃蛇代码

2017-09-01 10页 doc 26KB 33阅读

用户头像

is_954223

暂无简介

举报
贪吃蛇代码贪吃蛇代码 #include "stdafx.h" #include #include #include #include #include int length=3; //Éߵĵ?Ç????È???õÊ?ֵΪ3 int line[100][2]; //ÉßµÄ×ßµÄÂ?Ïß int head[2]={40,12}; //ÉßÍ? int food[2]; //Ê?ÎïµÄÎ?Öà char direction; //ÉßÔË????Ïò int x_min=1,x_max=77, y_min=2,...
贪吃蛇代码
贪吃蛇代码 #include "stdafx.h" #include #include #include #include #include int length=3; //Éߵĵ?Ç????È???õÊ?ֵΪ3 int line[100][2]; //ÉßµÄ×ßµÄÂ?Ïß int head[2]={40,12}; //ÉßÍ? int food[2]; //Ê?ÎïµÄÎ?Öà char direction; //ÉßÔË????Ïò int x_min=1,x_max=77, y_min=2, y_max=23;//ÉèÖÃÉßµÄÔË??ÇøÓò int tail_before[2]={40,12}; //ÉÏÒ??ö×?Ì?µÄÉßÎ? char direction_before='s'; //ÉÏÒ??ö×?Ì?ÉßµÄÔË????Ïò int live_death=1; //ËÀ?î×?Ì???0ËÀ??1?î int eat_flag=0; //?ÔÊ?ÎïÓë?ñµÄ×?Ì???0Ã??Ô 1?ÔÁË int max=0; int delay; //ÒÆ??ÑÓ?ÙÊ??ä int a=1; //?Ø?? void gotoxy(int x, int y) //xΪÁÐ×ø?ê,yΪÐÐ×ø?ê { COORD pos = {x,y}; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos); } void hidden() //Òþ?Ø?â?ê { HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_CURSOR_INFO cci; GetConsoleCursorInfo(hOut,&cci); cci.bVisible=0; //??1ΪÏÔÊ?????0ΪÒþ?Ø SetConsoleCursorInfo(hOut,&cci); } void update_score() { gotoxy(2,1); printf("ÎÒµÄ?ÖÊý?º%d",((length-3)*10)); gotoxy(42,1); printf("?Ø???º%d", a); } void create_window() { gotoxy(0,0); printf("?X?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?j?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?["); printf("?U ?U ?U"); printf("?d?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?m?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?g"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?U ?U"); printf("?^?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?T?a"); } void update_line() { int i; if(eat_flag==0) //?ÔÁËÊ?Îï?Í??ÓÃ?Ç×?ÉÏÒ??ö×?Ì?µÄÉßÎ????ñÔò?á??Ïûµô { tail_before[0]=line[0][0]; //?Ç×?ÉÏÒ??ö×?Ì?µÄÉß tail_before[1]=line[0][1]; for(i=0;ix_min) break; } //?úÉúÒ??öÅ?Êýºá×ø?ê for(;;) { food[1]=rand()%(y_max); if(food[1]>y_min) break; } for(i=0,flag=0;i=x_max || head[1]<=y_min || head[1]>=y_max || flag==1) { system("cls"); create_window(); update_score(); gotoxy(30,12); printf("ÓÎÏ??áÊø??\n"); Sleep(500); live_death=0; } } void eat() { if(head[0]==food[0]&&head[1]==food[1]) { length++; line[length-1][0]=head[0]; //?üÐÂÉßÍ? line[length-1][1]=head[1]; eat_flag=1; createfood(); update_score(); if(delay>100&&((length-3)%5==0)) delay-=100; //?ÓËÙ if((length-2)%5==0) a =a+1; } } int _tmain(int argc, _TCHAR* argv[]) { int x=0,y=0; int i; hidden(); //Òþ?Ø?â?ê create_window(); initial(); createfood(); for(direction='s',delay=600;;) { get_direction(); eat(); update_line(); live_state(); //ÅÐ?ÏÉúËÀ×?Ì? if(live_death==1) { show_snake(); } else break; Sleep(delay); } }
/
本文档为【贪吃蛇代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索