ImageVerifierCode 换一换
格式:DOCX , 页数:117 ,大小:1.28MB ,
资源ID:6513548      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-6513548.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c语言贪吃蛇UI界面版.docx)为本站会员(HR专家)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

c语言贪吃蛇UI界面版.docx

1、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

2、#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

3、, 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_s

4、uiji_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 sn

5、akemove();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

6、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;nexthea

7、d = (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;he

8、ad = 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 = scor

9、e1 + 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)Pla

10、ySound(“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-ne

11、xt-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-nex

12、t;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_FILENAM

13、E | 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;whi

14、le (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

15、(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 q = q-next;if (oneortwo)while (q1-next != NULL)if (magic_

16、1-x = q1-x 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 creatmagic();q1 = q1-next;magic = magic_1;putimage(magic_1-x, magic_1-y, wd, hg,magics, 0, 0);void updat

17、ewall()if (isdwall)int i;PIMAGE upwall;upwall = newimage();getimage(upwall, “m.png“, 0, 0);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 q = q-next;if (oneortwo)while (q1

18、-next != NULL)if (wall_1-x = q1-x q1 = q1-next;q = head;q1 = head1;while (q-next = NULL)if (q-x = wall_1-x creatbomb();q = q-next;while (q1-next = NULL)if (q1-x = wall_1-x 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 =

19、 0;q1 = head1;q = head;if (score = 100 q = q-next;while (q1-next != NULL)snake2 = snake2 + 1;q1= q1-next;if (snake1 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

20、= 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 = hea

21、d1;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 = self-next;while (self1 != NULL)if (self1-x = head1-x sel

22、f1 = 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

23、;food_1-y = (food_1-y / wd) * wd + 110;/控制坐标 保证食物出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 q = q-next;if (oneortwo)while (q1-next != NULL)if (food_1-x = q1-x 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-n

24、ext = NULL)if (q1-x = food_1-x 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;

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报