




已阅读5页,还剩62页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
c语言UI界面版贪吃蛇使用ege图形库,游戏实现单双人功能。道具有炸弹,随机魔盒,炸弹。有随机障碍物生成。不附加图片 。/* * *出品方:债组 *成员:冯强 陈志豪 邓青松 俄木木果 *时间:2016/7/11 * * */#include graphics.h#include #include#include#include#include#include#include #define printf outtextint speed=5;#define U 1#define D 2#define L 3#define R 4#define A 5#define S 6#define W 7#define Dd 8#define VK_A 0x41/虚拟键值宏定义#define VK_S 0x53#define VK_W 0x57#define VK_D 0X44#define VK_N 0X4E#define VK_M 0x4d#define wd 10/蛇身的宽#define hg 10/蛇身的高/蛇身的一个节点typedef struct SNAKE int x;int y;struct SNAKE *next;snake;/全局变量/int score = 0, add = 10, score1 = 0, add1 = 10;/总得分与每次吃食物得分。int status, status1, sleeptime=130 ,bomb_suiji = 1234,wall_suiji=5678,magic_suiji=6589,magic_suiji1=3256;/每次运行的时间间隔int oneortwo = 0;int dwall=1,isdwall=0;snake *head, *head1, *food, *bomb,*wall,*magic;snake *q;/便利第一条蛇用到的指针snake *q1;/遍历第二条蛇的时候用到的指针int endgamestatus = 0; /游戏结束的情况,int wall_suiji_u = 1111, wall_suiji_d = 2222, wall_suiji_r = 333, wall_suiji_l = 444;int wall_u, wall_d, wall_l, wall_r;int uwall_u, uwall_d, uwall_l, uwall_r;int magic_x=0,magic_xx;/后台的函数void initsnake();void initsnake1();void creatmagic();void gomagic();void createfood();void creatbomb();void creatwall();void drawwall();void snakemove();void pausegame();void gamecircle();void welcomeintogame();int biteself();void iswin();void gamestart();void cleanwall();void updatewall();void endgame();/iswin改变void cantcrosswall();/撞墙,改变值/UI函数void prompt();void pause();void UI();void Fence();void welcometogame();/后台函数void gomagic()int i = 5;PIMAGE ss;PIMAGE bj;MUSIC muc;MUSIC muc1;muc.OpenFile(good.mp3);muc1.OpenFile(bomm.mp3);bj = newimage();ss = newimage();getimage(ss, ss.png, 0, 0);/加载蛇身图片if (oneortwo)getimage(bj, m.png, 0, 0);/加载背景图片elsegetimage(bj, danren.png, 0, 0);/加载背景图片snake * nexthead;snake * nexthead1;nexthead = (snake*)malloc(sizeof(snake);nexthead1 = (snake*)malloc(sizeof(snake);srand(time_t)magic_suiji);wall_suiji = wall_suiji + 3652;magic_x = rand() % 4;i+;if (magic_x = 0 | magic_x=1) if (magic_xx = 1)PlaySound(mgwall.wav, NULL, SND_FILENAME | SND_ASYNC);score = score + add;nexthead-next = head;head = nexthead;q = head;while (q-next-next != NULL)putimage(q-x, q-y, wd, hg, ss, 0, 0);q = q-next;putimage(q-next-x, q-next-y, wd, hg, bj, q-next-x, q-next-y);free(q-next);q-next = NULL;cleanwall();drawwall();else if (magic_xx = 3)PlaySound(mgwall.wav, NULL, SND_FILENAME | SND_ASYNC);score1 = score1 + add1;nexthead1-next = head1;head1 = nexthead1;q1 = head1;while (q1-next-next != NULL)putimage(q1-x, q1-y, wd, hg, ss, 0, 0);q1 = q1-next;putimage(q1-next-x, q1-next-y, wd, hg, bj, q1-next-x, q1-next-y);free(q1-next);q1-next = NULL;cleanwall();drawwall();else if (magic_x = 2)if (magic_xx = 1)PlaySound(mgbomb.wav, NULL, SND_FILENAME | SND_ASYNC);nexthead-next = head;head = nexthead;q = head;while (q-next-next-next != NULL)putimage(q-x, q-y, wd, hg, ss, 0, 0);q = q-next;putimage(q-next-x, q-next-y, wd, hg, bj, q-next-x, q-next-y);putimage(q-next-next-x, q-next-next-y, wd, hg, bj, q-next-next-x, q-next-next-y);updatewall();free(q-next-next);free(q-next);q-next = NULL;iswin();else if (magic_xx = 2)PlaySound(mgbomb.wav, NULL, SND_FILENAME | SND_ASYNC);nexthead1-next = head1;head1 = nexthead1;q1 = head1;while (q1-next-next-next != NULL)putimage(q1-x, q1-y, wd, hg, ss, 0, 0);q1 = q1-next;putimage(q1-next-x, q1-next-y, wd, hg, bj, q1-next-x, q1-next-y);putimage(q1-next-next-x, q1-next-next-y, wd, hg, bj, q1-next-next-x, q1-next-next-y);updatewall();free(q1-next-next);free(q1-next);q1-next = NULL;iswin();else if (magic_x = 3)if (magic_xx = 2)PlaySound(mggood.wav, NULL, SND_FILENAME | SND_ASYNC);nexthead1-next = head1;head1 = nexthead1;q1 = head1;while (q1 != NULL)putimage(q1-x, q1-y, wd, hg, ss, 0, 0);q1 = q1-next;updatewall();score1 = score1 + add1;else if (magic_xx = 1)PlaySound(mggood.wav, NULL, SND_FILENAME | SND_ASYNC);nexthead-next = head;head = nexthead;q = head;while (q != NULL)putimage(q-x, q-y, wd, hg, ss, 0, 0);q = q-next;updatewall();score = score + add;if (!oneortwo)sleeptime = sleeptime - 50;void creatmagic()re:q = head;q1 = head1;PIMAGE magics;magics = newimage();getimage(magics, magic.png, 0, 0);/加载食物图片snake *magic_1;magic_1 = (snake *)malloc(sizeof(snake);srand(time_t)magic_suiji+220);magic_suiji = magic_suiji + 66;magic_1-x = rand() % 280;magic_1-y = rand() % 260;magic_1-x = (magic_1-x / wd) * wd + 250;magic_1-y = (magic_1-y / wd) * wd + 110;/控制坐标 保证食物出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 & magic_1-x = 310 & magic_1-x y = 170 & magic_1-y next != NULL)if (magic_1-x = q-x & magic_1-y = q-y)creatmagic();q = q-next;if (oneortwo)while (q1-next != NULL)if (magic_1-x = q1-x & magic_1-y = q1-y)creatmagic();q1 = q1-next;q = head;q1 = head;while (q-next = NULL)if (q-x = magic_1-x | q-y = magic_1-y) /判断蛇身是否与食物重合free(magic_1);creatmagic();q = q-next;while (q1-next = NULL)if (q1-x = magic_1-x & q1-y = magic_1-y) /判断蛇身是否与食物重合free(magic_1);creatmagic();q1 = q1-next;magic = magic_1;putimage(magic_1-x, magic_1-y, wd, hg,magics, 0, 0);void updatewall()if (isdwall)int i;PIMAGE upwall;upwall = newimage();getimage(upwall, m.png, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(i + 150, uwall_l, wd, hg, upwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(i + 530, uwall_r, wd, hg, upwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(uwall_u, i + 10, wd, hg, upwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(uwall_d, i + 370, wd, hg, upwall, 0, 0);delimage(upwall);void drawwall()PlaySound(wall.wav, NULL, SND_FILENAME | SND_ASYNC);PIMAGE newwall;int i;newwall = newimage();getimage(newwall, m.png, 0, 0);srand(wall_suiji_u);wall_u = rand() % 480;srand(wall_suiji_d);wall_d = rand() % 480;srand(wall_suiji_l);wall_l = rand() % 460;srand(wall_suiji_r);wall_r = rand() % 460;wall_suiji_u = wall_suiji_d + 74;wall_suiji_d = wall_suiji_d + 85;wall_suiji_l = wall_suiji_l + 90;wall_suiji_r = wall_suiji_r + 74;wall_u = (wall_u / wd)*wd + 150;wall_d = (wall_d / wd)*wd + 150;wall_l = (wall_l / wd)*wd + 10;wall_r = (wall_r / wd)*wd + 10;uwall_u = wall_u;uwall_d = wall_d;uwall_l = wall_l;uwall_r = wall_r;for (i = 0; i 100; i = i + 10) /1putimage(i + 150, wall_l, wd, hg, newwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(i + 530, wall_r, wd, hg, newwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(wall_u, i + 10, wd, hg, newwall, 0, 0);for (i = 0; i 100; i = i + 10) /1putimage(wall_d, i + 370, wd, hg, newwall, 0, 0);isdwall = isdwall+1;void cleanwall()int i;PIMAGE cleanwall;cleanwall = newimage();if (oneortwo)getimage(cleanwall, m.png, 0, 0);elsegetimage(cleanwall, danren.png, 0, 0);if (isdwall)for (i = 0; i 100; i = i + 10) /1putimage(i + 150, wall_l, wd, hg, cleanwall, i + 150, wall_l);for (i = 0; i 100; i = i + 10) /1putimage(i + 530, wall_r, wd, hg, cleanwall, i + 530, wall_r);for (i = 0; i 100; i = i + 10) /1putimage(wall_u, i + 10, wd, hg, cleanwall, wall_u, i + 10);for (i = 0; i 100; i = i + 10) /1putimage(wall_d, i + 370, wd, hg, cleanwall, wall_d, i + 370);else if (isdwall = 0)putimage(310, 180, 170, 110, cleanwall, 310,180);for (i = 0; i 50; i = i + 10)putimage(250 + i + 80 - 20, 200 - 20, wd, hg, cleanwall, 250 + i + 80 - 20, 200 - 20);putimage(290 + 80 - 20, 200 + i - 20, wd, hg, cleanwall, 290 + 80 - 20, 200 + i - 20);putimage(250 + i + 80 - 20, 250 - 20, wd, hg, cleanwall, 250 + i + 80 - 20, 250 - 20);putimage(250 + 80 - 20, 250 + i - 20, wd, hg, cleanwall, 250 + 80 - 20, 250 + i - 20);putimage(200 + i + 50 + 80 - 20, 300 - 20, wd, hg, cleanwall, 200 + i + 50 + 80 - 20, 300 - 20);for (i = 0; i 50; i = i + 10)putimage(250 + i + 66 + 80 - 30, 200 - 20, wd, hg, cleanwall, 250 + i + 66 + 80 - 30, 200 - 20);putimage(290 + 66 + 80 - 30, 200 + i - 20, wd, hg, cleanwall, 290 + 66 + 80 - 30, 200 + i - 20);putimage(250 + i + 66 + 80 - 30, 250 - 20, wd, hg, cleanwall, 250 + i + 66 + 80 - 30, 250 - 20);putimage(250 + 66 + 80 - 30, 250 + i - 20, wd, hg, cleanwall, 250 + 66 + 80 - 30, 250 + i - 20);putimage(200 + i + 50 + 66 + 80 - 30, 300 - 20, wd, hg, cleanwall, 200 + i + 50 + 66 + 80 - 30, 300 - 20);for (i = 0; i 50; i = i + 10)putimage(490 + i - 40 - 20, 200 - 20, wd, hg, cleanwall, 490 + i - 40 - 20, 200 - 20);putimage(490 + i - 40 - 20, 300 - 20, wd, hg, cleanwall, 490 + i - 40 - 20, 300 - 20);for (i = 0; i x = rand() % 280;wall_1-y = rand() % 260;wall_1-x = (wall_1-x / wd) * wd + 250;wall_1-y = (wall_1-y / wd) * wd + 110; /控制坐标 保证炸弹出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 & wall_1-x = 300 & wall_1-x y = 170 & wall_1-y next != NULL)if (wall_1-x = q-x & wall_1-y = q-y)creatwall();q = q-next;if (oneortwo)while (q1-next != NULL)if (wall_1-x = q1-x & wall_1-y = q1-y)creatwall();q1 = q1-next;q = head;q1 = head1;while (q-next = NULL)if (q-x = wall_1-x & q-y = wall_1-y) /判断蛇身是否碰到炸弹free(wall_1);creatbomb();q = q-next;while (q1-next = NULL)if (q1-x = wall_1-x & q1-y = wall_1-y) /判断蛇身是否碰到炸弹free(wall_1);creatwall();q1 = q1-next;wall = wall_1;putimage(wall_1-x, wall_1-y, wd, hg, walls, 0, 0);void iswin()int snake1 = 0;int snake2 = 0;q1 = head1;q = head;if (score = 100 & score1 = 100 & score1 next != NULL)snake1 = snake1 + 1;q = q-next;while (q1-next != NULL)snake2 = snake2 + 1;q1= q1-next;if (snake1 = 2)endgamestatus = 5;endgame();else if (snake2 x = 200;tail-y = 200;tail-next = NULL;for (i = 0; i next = tail;head-x = 200 + i;head-y = 200;tail = head;while (tail != NULL)/从头到为,输出蛇身putimage(tail-x, tail-y, wd, hg, ss, 0, 0);tail = tail-next;void initsnake1()/初始化第二条蛇身PIMAGE ss1;ss1 = newimage();getimage(ss1, bs.png, 0, 0);/加载蛇身图片snake *tail1;int i;tail1 = (snake*)malloc(sizeof(snake);/从蛇尾开始,头插法,以x,y设定开始的位置/tail1-x = 200;tail1-y = 300;tail1-next = NULL;for (i = 0; i next = tail1;head1-x = 200 + i;head1-y = 300;tail1 = head1;while (tail1 != NULL)/从头到为,输出蛇身if (oneortwo)putimage(tail1-x, tail1-y, wd, hg, ss1, 0, 0);tail1 = tail1-next;int biteself()/判断是否咬到了自己snake *self;snake *self1;self = head-next;self1 = head1-next;while (self != NULL)if (self-x = head-x & self-y = head-y)return 1;self = self-next;while (self1 != NULL)if (self1-x = head1-x & self1-y = head1-y)return 1;self1 = self1-next;return 0;void createfood()/随机出现食物 re2:q = head;q1 = head1;PIMAGE foods;foods = newimage();getimage(foods, food.png, 0, 0);/加载食物图片snake *food_1;food_1 = (snake *)malloc(sizeof(snake);srand(time(NULL);food_1-x = rand() % 280;food_1-y = rand() % 260;food_1-x=(food_1-x / wd) * wd + 250;food_1-y = (food_1-y / wd) * wd + 110;/控制坐标 保证食物出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 & food_1-x = 300 & food_1-x y = 170 & food_1-y next != NULL)if (food_1-x = q-x & food_1-y = q-y)createfood();q = q-next;if (oneortwo)while (q1-next != NULL)if (food_1-x = q1-x & food_1-y = q1-y)createfood();q1 = q1-next;q = head;q1 = head;while (q-next = NULL)if (q-x = food_1-x | q-y = food_1-y) /判断蛇身是否与食物重合free(food_1);createfood();q = q-next;while (q1-next = NULL)if (q1-x = food_1-x & q1-y = food_1-y) /判断蛇身是否与食物重合free(food_1);createfood();q1 = q1-next;food = food_1;putimage(food_1-x, food_1-y, wd, hg, foods, 0, 0);void creatbomb()re3:q = head;q1 = head1;PIMAGE bombs;bombs = newimage();getimage(bombs, bomb.png, 0, 0);snake *bomb_1;bomb_1 = (snake*)malloc(sizeof(snake);srand(time_t)bomb_suiji);bomb_suiji = bomb_suiji + 1234;bomb_1-x = rand() % 280;bomb_1-y = rand() % 260;bomb_1-x = (bomb_1-x / wd) * wd + 250;bomb_1-y = (bomb_1-y / wd) * wd + 110; /控制坐标 保证炸弹出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 & bomb_1-x = 300 & bomb_1-x y = 170 & bomb_1-y next != NULL)if (bomb_1-x = q-x & bomb_1-y = q-y)creatbomb();q = q-next;if (oneortwo)while (q1-next != NULL)if (bomb_1-x = q1-x & bomb_1-y = q1-y)creatbomb();q1 = q1-next;q = head;q1 = head1;while (q-next = NULL)if (q-x = bomb_1-x & q-y = bomb_1-y) /判断蛇身是否碰到炸弹free(bomb_1);creatbomb();q = q-next;while (q1-next = NULL)if (q1-x = bomb_1-x & q1-y = bomb_1-y) /判断蛇身是否碰到炸弹free(bomb_1);creatbomb();q1 = q1-next;bomb = bomb_1;putimage(bomb_1-x, bomb_1-y, wd, hg, bombs, 0, 0);void cantcrosswall()/不能穿墙q = head;q1 = head1;int i = 0;if (oneortwo)/2人if (head-x = 150 | head-x = 630 | head-y = 10 | head-y = 470)endgamestatus = 5;endgame();if (head1-x = 150 | head1-x = 630 | head1-y = 10 | head1-y = 470)endgamestatus = 4;endgame();elseif (head-x = 150 | head-x = 630 | head-y = 10 | head-y = 470)endgamestatus = 1;endgame();/*上:围墙*/if(isdwall=0)for(int xx=310;xxx) = xx & (head-y) y) =180)endgamestatus = 1;endgame();for(int xx1=310;xx1x) = xx & (head1-y) y) =180)endgamestatus = 1;endgame();elseif ( head-x = wall_u & head-y x = wall_d & head-y = 370 )endgamestatus = 1;endgame();else if (head-x y = wall_l )endgamestatus = 1;endgame();else if (head-x = 530 & head-y = wall_r)endgamestatus = 1;endgame();if (oneortwo)if (head1-x = wall_u & head1-y x = wall_d & head1-y = 370 )endgamestatus = 1;endgame();else if (he
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030中国不溶性糖精行业销售状况及应用趋势研究报告
- 2025至2030中国一体式洗碗和烘干机行业消费动态与竞争趋势研究报告
- 2025-2030重型卡车行业市场现状供需分析及重点企业投资评估规划分析研究报告
- 2025-2030资产管理产业市场深度调研及发展趋势与投资战略研究报告
- 2025-2030药膳行业市场运行分析及竞争格局与投资战略研究报告
- 2025-2030年颗粒饮料行业竞争格局及企业投资战略研究报告
- 2025至2030年中国锅炉水位管板行业投资前景及策略咨询报告
- 现代中式园林景观设计
- 2025届攀枝花市盐边县三年级数学第一学期期末监测模拟试题含解析
- 酒店大厅设计方案
- 仓库定置目视化管理
- 工程经济课件
- 变电站值班员-中级工考试模拟题及参考答案解析
- 2024年西双版纳州景洪市事业单位选调工作人员笔试真题
- 浙江省绍兴市柯桥区2025年5月统考英语试题试卷含解析
- 2024-2025学年下学期高一物理教科版同步经典题精练之天体运动
- 慢性阻塞性肺疾病患者随访服务记录表
- 2025年气球租赁合同
- 医用耗材管理委员会2024年第4季度会议
- 黑龙江流域史(黑龙江联盟)知到智慧树章节测试课后答案2024年秋黑河学院
- 2025年江苏省凤凰出版传媒集团招聘笔试参考题库含答案解析
评论
0/150
提交评论