资源预览内容
第1页 / 共18页
第2页 / 共18页
第3页 / 共18页
第4页 / 共18页
第5页 / 共18页
第6页 / 共18页
第7页 / 共18页
第8页 / 共18页
第9页 / 共18页
第10页 / 共18页
亲,该文档总共18页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Win-TC (C语言)贪吃蛇游戏程序设计贪吃蛇游戏是大家熟悉的一个经典游戏,现在用Win-TC编译环境来实现游戏过程。游戏功能如下:游戏开始后在屏幕出现一条自由活动的蛇,玩家可通过小键盘的方向功能键来控制蛇的运动方向,系统每间隔10秒钟随机投放一次食物(一颗食用果或毒果)。蛇每吃到一颗食用果后其身体长度会自动增长一节,玩家得到5分的成绩奖励,当蛇吃到毒果或碰到四周边界和蛇头碰到蛇身的某一部位时,游戏结束。(更新版本) 图1、贪吃蛇游戏效果图游戏源程序清单如下:#include #include #include #include #include #include #define MAXSIZE 1000 /*定义贪吃蛇最大长度*/#define LEFT 75 /*定义方向键左向键盘值*/#define RIGHT 77 /*定义方向键右向键盘值*/#define UP 72 /*定义方向键上向键盘值*/#define DOWN 80 /*定义方向键下向键盘值*/#define WINTOP 120 /*定义游戏区上边界y坐标值*/#define WINDOWN 360 /*定义游戏区下边界y坐标值*/#define WINLEFT 140 /*定义游戏区左边界x坐标值*/#define WINRIGHT 500 /*定义游戏区右边界x坐标值*/char FILLC=0xfe,0x90,0x49,0xa0,0x30,0xc0,0x29,0xc0, 0x46,0xa0,0xfe,0x90,0x49,0xa0,0x30,0xc0, 0x21,0xc0,0x53,0x20,0x80,0x90,0x10,0x40;/*恢复屏幕数据*/char RNULL=0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00;/*头部数据*/*top*/ char headt=0x00,0x00,0x0f,0x00,0x1f,0x80,0x3f,0xc0, 0x26,0x40,0x26,0x40,0x3f,0xc0,0x3f,0xc0, 0x3f,0xc0,0x3f,0xc0,0x1f,0x80,0x1f,0x80;/*down*/char headd=0x1f,0x80,0x1f,0x80,0x3f,0xc0,0x3f,0xc0, 0x3f,0xc0,0x3f,0xc0,0x26,0x40,0x26,0x40, 0x3f,0xc0,0x1f,0x80,0x0f,0x00,0x00,0x00;/*right*/char headr=0x00,0x00,0x00,0x00,0x3f,0x80,0xfc,0xc0, 0xfc,0xe0,0xff,0xe0,0xff,0xe0,0xfc,0xe0, 0xfc,0xc0,0x3f,0x80,0x00,0x00,0x00,0x00;/*left*/char headl=0x00,0x00,0x00,0x00,0x1f,0xc0,0x33,0xf0, 0x73,0xf0,0x7f,0xf0,0x7f,0xf0,0x73,0xf0, 0x33,0xf0,0x1f,0xc0,0x00,0x00,0x00,0x00;/*身体数据*/*left down*/char leftd=0x1f,0x80,0x1f,0x80,0x1f,0xc0,0x1f,0xf0, 0x1f,0xf0,0x0f,0xf0,0x0f,0xf0,0x07,0xf0, 0x01,0xf0,0x00,0x00,0x00,0x00,0x00,0x00;/*right down*/char rightd=0x1f,0x80,0x1f,0x80,0x3f,0x80,0xff,0x80, 0xff,0x80,0xff,0x00,0xff,0x00,0xfe,0x00, 0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00;/*left top*/char leftt=0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xf0, 0x07,0xf0,0x0f,0xf0,0x0f,0xf0,0x1f,0xf0, 0x1f,0xf0,0x1f,0xc0,0x1f,0x80,0x1f,0x80;/*right top*/char rightt=0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x00, 0xfe,0x00,0xff,0x00,0xff,0x00,0xff,0x80, 0xff,0x80,0x3f,0x80,0x1f,0x80,0x1f,0x80;/*top down*/char tp_dn=0x1f,0x80,0x1f,0x80,0x1f,0x80,0x1f,0x80, 0x1f,0x80,0x1f,0x80,0x1f,0x80,0x1f,0x80, 0x1f,0x80,0x1f,0x80,0x1f,0x80,0x1f,0x80;/*left right*/char lf_rh=0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xf0, 0xff,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xf0, 0xff,0xf0,0x00,0x00,0x00,0x00,0x00,0x00;/*尾巴数据*/*down*/char re_dn=0x09,0x00,0x19,0x80,0x19,0x80,0x19,0x80, 0x19,0x80,0x19,0x80,0x19,0x80,0x1f,0x80, 0x1f,0x80,0x1f,0x80,0x1f,0x80,0x1f,0x80;/*top*/char re_tp=0x1f,0x80,0x1f,0x80,0x1f,0x80,0x1f,0x80, 0x1f,0x80,0x19,0x80,0x19,0x80,0x19,0x80, 0x19,0x80,0x19,0x80,0x19,0x80,0x09,0x00;/*right*/char re_rh=0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0xf0, 0xff,0xf0,0x01,0xf0,0x01,0xf0,0xff,0xf0, 0x7f,0xf0,0x00,0x00,0x00,0x00,0x00,0x00;/*left*/char re_lf=0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xe0, 0xff,0xf0,0xf8,0x00,0xf8,0x00,0xff,0xf0, 0xff,0xe0,0x00,0x00,0x00,0x00,0x00,0x00;/*食用果数据*/char sfood=0x00,0x00,0x0f,0x00,0x1f,0x80,0x3f,0xc0, 0x7f,0xe0,0x7f,0xe0,0x7f,0xe0,0x7f,0xe0, 0x3f,0xc0,0x1f,0x80,0x0f,0x00,0x00,0x00;/*毒果数据*/char block=0x06,0x00,0x06,0x00,0x0f,0x00,0x0f,0x00, 0x3f,0xc0,0x7f,0xe0,0x7f,0xe0,0x3f,0xc0, 0x0f,0x00,0x0f,0x00,0x06,0x00,0x06,0x00;/*定义贪吃蛇数据类型*/typedef struct TANCHISHE int x;/*每节位置x分量*/ int y;/*每节位置y分量*/ int ns;/*每节蛇体(位图)状态标识*/ int left; /*向左运动标识状态*/ int right;/*向右运动标识状态*/ int top;/*向上运动标识状态*/ int down;/*向下运动标识状态*/ TANCHISHE;/*定义整条蛇的数据类型*/typedef struct TANCHISHE Snakeh;/*头部数据*/ TANCHISHE SnakebMAXSIZE;/*刷新蛇体数据*/ TANCHISHE old_SnakebMAXSIZE;/*保存上一次蛇体数据*/ TANCHISHE Snaket;/*尾巴数据*/ int cx;/*恢复屏幕数据位置x分量*/ int cy;/*恢复屏幕数据位置y分量*/ int hx;/*头部位置x分量*/ int hy;/*头部位置y分量*/ int size;/*每节长度大小*/ int front;/*队列头指针*/ int rear;/*队列尾指针*/ TCsQueue;static char *TCShead4=headt,headd,headl,headr;static char *TCSbody6=leftt,leftd,rightt,rightd,lf_rh,tp_dn;static char *TCStail4=re_lf,re_rh,re_tp,re_dn
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号