今天小编mail为大家分享的生活小常识,希望能够帮助到大家!
c语言编程游戏,c语言游戏编程 下落的小鸟求代码这个很多人还不知道,现在让我们一起来看看吧!
1、下落的小鸟#include#include#include#include#includeint Grade = 1, Score = 0, Max_blank = 9, Distance = 18;struct Birds{int x; int y;}; //定义一种Birds数据类型(含3个成员)Birds *Bird = (Birds*)malloc(sizeof(Birds)); //定义Birds类型 指针变量Bird并赋初值struct Bg{int x, y; int l_blank; Bg *pri; Bg *next;}; //定义一种Bg数据类型(含5个成员)Bg *Bg1 = (Bg*)malloc(sizeof(Bg)); //定义Bg类型 指针变量Bg1并赋初值void Position(int x, int y) //光标定位函数(用于指定位置输出){COORD pos = { x - 1, y - 1 };HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleCursorPosition(Out, pos);}void Csh( ) //初始化界面{printf("══════════════════════════════════════");printf(" ■■ ■■ C语言版 Flappy Bird ");printf(" ■■ ■■");printf(" ■■ ■■");printf(" ■■ ■■ 瞎搞人:yyposs原创");printf(" ■■ ■■ 瞎搞日期:2014.2");printf(" ■■ ■■");printf(" ■■ ■■ 改编:鸣蝉百2021.7");printf(" ■■ ■■ 操作:按向上方向键让小鸟起飞");printf(" ■■");printf(" ■■");printf(" ■■ ■■");printf(" ■■ ■■");printf(" ■■ ■■");printf(" ■■ ■■");printf(" ■■ ■■ DEVc++运行通过");printf("══════════════════════════════════════");printf(" 按键继续…");getch( );system("cls");} void PrFK( ) //输出方框(游戏范围区){int i;Position(1, 1); printf("╔"); Position(79, 1); printf("╗");Position(1, 24); printf("╚"); Position(79, 24); printf("╝");for (i = 3; i <= 78; i += 2){Position(i, 1); printf("═"); Position(i, 24); printf("═");}for(i=2;i<=23;i++) { Position(1,i); printf("║");if(ix = 90; Bg1->y = 8; //确定障碍物的一对基本坐标(此时值是在游戏框之外)Bg2->x = Bg1->x + Distance; Bg2->y = 9; //下一障碍物的基本坐标x、yBg1->l_blank = Max_blank - Grade; //障碍物上下两部分之间的空白距离l_blankBg2->l_blank = Max_blank - Grade;Bg1->next = Bg2; Bg1->pri = Bg2;Bg2->next = Bg1; Bg2->pri = Bg1;}void InsertBg(Bg *p) //随机改变障碍物的y坐标,让空白通道有上下变化{int temp;Bg *Bgs = (Bg*)malloc(sizeof(Bg));Bgs->x = p->pri->x + Distance;Bgs->l_blank = Max_blank - Grade;srand((int)time(0)); //启动随机数发生器temp = rand( ); //产生一个随机数并赋值给tempif (temp % 2 == 0){if ((temp % 4 + p->pri->y + Max_blank - Grade)y = p->pri->y + temp % 4;else Bgs->y = p->pri->y;}else{if ((p->pri->y - temp % 4)>2)Bgs->y = p->pri->y - temp % 4;else Bgs->y = p->pri->y;}Bgs->pri = p->pri; Bgs->next = p;p->pri->next = Bgs; p->pri = Bgs;} void CreatBird( ) //建立小鸟的坐标(初始打印输出小鸟的位置){Bird->x = 41; Bird->y = 10;}int CheckYN(Bg *q) //判断游戏结束与否(值为0是要结束。
2、为1没有要结束){Bg *p = q; int i = 0;while (++i y>23)return 0;if (Bird->x == p->x&&Bird->y y)return 0;if ((Bird->x == p->x || Bird->x == p->x + 1 || Bird->x == p->x + 2) && Bird->y == p->y)return 0;if (Bird->x == p->x&&Bird->y>p->y + p->l_blank)return 0;if ((Bird->x == p->x || Bird->x == p->x + 1 || Bird->x == p->x + 2) && Bird->y == p->y + p->l_blank)return 0;p = p->next;}return 1;}void Check_Bg(Bg *q) //核查开头的障碍物坐标是否在游戏区内{Bg *p = q; int i = 0, temp;while (++i x>-4)p = p->next;else{srand((int)time(0)); temp = rand();if (temp % 2 == 0){if ((temp % 4 + p->y + Max_blank - Grade)y = p->y + temp % 4;else p->y = p->y; p->x = p->pri->x + Distance;p->l_blank = Max_blank - Grade;}else{if ((p->y - temp % 4)>2)p->y = p->y - temp % 4;else p->y = p->y; p->x = p->pri->x + Distance;p->l_blank = Max_blank - Grade;}}}} void Prt_Bg(Bg *q) //打印输出障碍物(依据其x、y坐标进行相应输出){Bg *p = q; int i = 0, k, j;while (++i x>0 && p->x <= 78){for (k = 2; ky; k++){Position(p->x + 1, k); printf("■"); printf("■"); printf(" ");}Position(p->x, p->y);printf("■"); printf("■"); printf("■"); printf(" ");Position(p->x, p->y + p->l_blank);printf("■"); printf("■"); printf("■"); printf(" ");k = k + p->l_blank + 1;for (k; k x + 1, k); printf("■"); printf("■"); printf(" ");}}p = p->next;if (p->x == 0){for (j = 2; jy; j++){Position(p->x + 1, j); printf(" "); printf(" ");}Position(p->x + 1, p->y);printf(" "); printf(" "); printf(" ");Position(p->x + 1, p->y + Max_blank - Grade);printf(" "); printf(" "); printf(" ");j = j + Max_blank - Grade + 1;for (j; j x + 1, j); printf(" "); printf(" ");}}}} void PrtBird( ) //打印输出小鸟{Position(Bird->x, Bird->y - 1); printf(" ");Position(Bird->x, Bird->y); printf("Ю");Position(38, 2); printf("Score:%d", Score);}void Loop_Bg(Bg *q) //障碍物x坐标左移,并记录成绩{Bg *p = q; int i = 0;while (++i x = p->x - 1; p = p->next;if (Bird->x == p->x){Score += 1;if (Score % 4 == 0 && Gradey = Bird->y + 1;if (GetAsyncKeyState(VK_UP)) //按下了向上方向键{Position(Bird->x, Bird->y - 1);printf(" ");Bird->y = Bird->y - 4;}Sleep(200); //程序延时200毫秒(数值大小决定游戏速度快慢)i = 0;}Position(6, 25);printf("游戏结束! 请输入:0.退出 1.重玩");scanf("%d",&t);if (t==0)break;system("cls"); Score = 0;}return 0;}。
Luochuanren.Com洛川人-综合信息门户网站,涵盖生活常识、美食、创业、体育、旅游、家居、汽车、财经、互联网、科技、房产、教育等资讯。
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理,本文部分文字与图片资源来自于网络,转载此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请立即通知我们,情况属实,我们会第一时间予以删除,并同时向您表示歉意,谢谢!
工作时间:8:00-18:00
客服电话
17898872021
电子邮件
773537036@qq.com
扫码二维码
获取最新动态