c语言贪吃蛇UI界面版Word版

上传人:仙*** 文档编号:64937849 上传时间:2022-03-22 格式:DOC 页数:120 大小:1.49MB
收藏 版权申诉 举报 下载
c语言贪吃蛇UI界面版Word版_第1页
第1页 / 共120页
c语言贪吃蛇UI界面版Word版_第2页
第2页 / 共120页
c语言贪吃蛇UI界面版Word版_第3页
第3页 / 共120页
资源描述:

《c语言贪吃蛇UI界面版Word版》由会员分享,可在线阅读,更多相关《c语言贪吃蛇UI界面版Word版(120页珍藏版)》请在装配图网上搜索。

1、传播优秀Word版文档 ,希望对您有帮助,可双击去除!c语言UI界面版贪吃蛇使用ege图形库,游戏实现单双人功能。道具有炸弹,随机魔盒,炸弹。有随机障碍物生成。不附加图片 。传播优秀Word版文档 ,希望对您有帮助,可双击去除!传播优秀Word版文档 ,希望对您有帮助,可双击去除!/* * *出品方:债组 *成员:冯强 陈志豪 邓青松 俄木木果 *时间:2016/7/11 * * */传播优秀Word版文档 ,希望对您有帮助,可双击去除!#include graphics.h#include #include#include#include#include#include#include #d

2、efine 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传播优秀Word版文档 ,希望对您有帮助,可双击去除!#define wd 10/蛇身的宽#define hg 10/蛇身的高/蛇身的一个

3、节点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,

4、 *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;传播优秀Word版文档 ,希望对您有帮助,可双击去除!int magic

5、_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();传播优秀Wor

6、d版文档 ,希望对您有帮助,可双击去除!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();传播

7、优秀Word版文档 ,希望对您有帮助,可双击去除!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_su

8、iji);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)传播优秀Word版文档 ,希望对您有帮助,可双击去除!putimage(q-x, q-y, w

9、d, 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-

10、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();传播优秀Word版文档 ,希望对您有帮助,可双击去除!drawwall();else if (magic_x = 2)if (magic_xx = 1)PlaySound(mgbomb.wav, NULL, SND_FILENAME | SND_A

11、SYNC);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-n

12、ext);free(q-next);q-next = NULL;iswin();传播优秀Word版文档 ,希望对您有帮助,可双击去除!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,

13、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)传播优秀Word版文档 ,希望对您有帮助,可双击去除!PlaySound(mggood.wav, NULL, SND_FILE

14、NAME | 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;wh

15、ile (q != NULL)putimage(q-x, q-y, wd, hg, ss, 0, 0);q = q-next;updatewall();score = score + add;传播优秀Word版文档 ,希望对您有帮助,可双击去除!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_

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

17、 = 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)

18、;creatmagic();传播优秀Word版文档 ,希望对您有帮助,可双击去除!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 = newimag

19、e();getimage(upwall, m.png, 0, 0);for (i = 0; i 100; i = i + 10) /1传播优秀Word版文档 ,希望对您有帮助,可双击去除!putimage(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,

20、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);传播优秀Word版文档 ,希望对您有帮助,可双击去除!srand(wall_suiji_u);wall_u =

21、 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 +

22、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) /1传播优秀Word版文档 ,希望对您有帮

23、助,可双击去除!putimage(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(

24、);if (oneortwo)getimage(cleanwall, m.png, 0, 0);elsegetimage(cleanwall, danren.png, 0, 0);if (isdwall)传播优秀Word版文档 ,希望对您有帮助,可双击去除!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

25、, 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

26、 + 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);传播优秀Word版文档 ,希望对您有帮助,可双击去除!putimage(250 + i + 80 - 20, 250 - 20, wd, hg, cleanwall, 250 + i + 80 - 20, 250 - 20);putimage(

27、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);pu

28、timage(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 +

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

30、= 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)传播优秀Word版文档 ,希望对您有帮助,可双击去除!if (wall_1-x = q-x & wall_1-y = q-y)creatwal

31、l();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;传播优秀Word版文档 ,希望对您有帮助,可双击去除!while (q1-next = NULL)if (q1-x = w

32、all_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

33、 != 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;传播优秀

34、Word版文档 ,希望对您有帮助,可双击去除!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;tail

35、1 = head1;while (tail1 != NULL)/从头到为,输出蛇身if (oneortwo)传播优秀Word版文档 ,希望对您有帮助,可双击去除!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;se

36、lf = self-next;while (self1 != NULL)if (self1-x = head1-x & self1-y = head1-y)return 1;传播优秀Word版文档 ,希望对您有帮助,可双击去除!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

37、(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)传播优秀Wo

38、rd版文档 ,希望对您有帮助,可双击去除!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)传播优秀Wor

39、d版文档 ,希望对您有帮助,可双击去除!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 =

40、 (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;传播优秀Word版文档 ,希望对您有帮助,可双击去除!bomb_1-y = (bomb_1-y / wd) * wd + 110; /控制坐标 保证炸弹出现在正确的位置 并且不会和蛇头错开if (isdwall = 0 & bomb_1-x = 300 &

41、 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) /判断蛇身是否碰到炸弹传播优秀Word版文档

42、 ,希望对您有帮助,可双击去除!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人传播优

43、秀Word版文档 ,希望对您有帮助,可双击去除!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();/

44、*上:围墙*/if(isdwall=0)传播优秀Word版文档 ,希望对您有帮助,可双击去除!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

45、 = 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 )传播优秀Word版文档 ,希望对您有帮助,可双击去除!endgamestatus = 1;endgame();else if (head1-x y = wall_l )endgamestatus = 1;endgame();else if (

46、head1-x = 530 & head1-y = wall_r )endgamestatus = 1;endgame();void snakemove()/蛇前进,上U,下D,左L,右RPIMAGE ss;PIMAGE ss1;PIMAGE bj;MUSIC muc;传播优秀Word版文档 ,希望对您有帮助,可双击去除!MUSIC muc1;PIMAGE fugai;muc.OpenFile(good.mp3);muc1.OpenFile(bomm.mp3);bj = newimage();fugai = newimage();getimage(fugai, tishi.png, 0, 0);ss = newimage();ss1 = newimage();getimage(ss, ss.png, 0, 0);/加载蛇身图片getimage(ss1, bs.png, 0, 0);/加载蛇身图片if (oneortwo)getimage(bj, m.png, 0, 0);/加载背景图片elsegetimage(bj, danren.png, 0, 0);

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!