编程c游戏(计算器编程游戏)

2024-01-03 14:16:50 数码极客 bianji01

 

c语言编程小游戏实现的超级玛丽游戏源码

int game::GetCommand()int c = 0;if (GetAsyncKeyState(A) & 0x8000)c |= CMD_LEFT;if (GetAsyncKeyState(D) & 0x8000)c |= CMD_RIGHT;if ((GetAsyncKeyState(W) & 0x8000)||(GetAsyncKeyState(K) & 0x8000))c |= CMD_UP;if (GetAsyncKeyState(S) & 0x8000)c |= CMD_DOWN;if (GetAsyncKeyState(J) & 0x8000)c |= CMD_SHOOT;if (GetAsyncKeyState(VK_ESCAPE) & 0x8000)c |= CMD_ESC;return c;void game::left()role.iframe*=-1;role.turn=-1;role.x-=STEP;if(is_l_touch(1)==1)role.x+=STEP;if(role.xrole.x+=STEP;void game::right()role.iframe*=-1;role.turn=1;role.x+=STEP;if(is_r_touch(1)==1)role.x-=STEP;if(role.x>role.xright&&(-xmap+role.xrole.x-=STEP;xmapsky-=1;xmap-=STEP;void game::up()mciSendString("play mymuSIc4 from 0", NULL, 0, NULL);role.iframe*=-1;v0=-sqrt(2*G*HIGH);role.jump=1;

c语言游戏编程,下落的小鸟 求代码

下落的小鸟

#include

#include

#include

#include

#include

intGrade=1,Score=0,Max_blank=9,Distance=18;

structBirds{intx;inty;};//定义一种Birds数据类型(含3个成员)

Birds*Bird=(Birds*)malloc(sizeof(Birds));//定义Birds类型指针变量Bird并赋初值

structBg{intx,y;intl_blank;Bg*pri;Bg*next;};//定义一种Bg数据类型(含5个成员)

Bg*Bg1=(Bg*)malloc(sizeof(Bg));//定义Bg类型指针变量Bg1并赋初值

voidPosition(intx,inty)

//光标定位函数(用于指定位置输出)

{COORDpos={x-1,y-1};

HANDLEOut=GetStdHandle(STD_OUTPUT_HANDLE);

SetConsolECursorPosition(Out,pos);

voidcsh()

//初始化界面

printf("══════════════════════════════════════\n");

printf("■■■■C语言版FlappyBird\n");

printf("■■■■\n");

printf("■■■■\n");

printf("■■■■瞎搞人:yyposs原创\n");

printf("■■■■瞎搞日期:2014.2\n");

printf("■■■■\n");

printf("■■■■改编:鸣蝉百2021.7\n");

printf("■■■■操作:按向上方向键让小鸟起飞\n");

printf("■■\n");

printf("■■\n");

printf("■■■■\n");

printf("■■■■\n");

printf("■■■■\n");

printf("■■■■\n");

printf("■■■■DEVc++运行通过\n");

printf("══════════════════════════════════════\n");

printf("按键继续…");

getch();

system("cls");

voidPrFK()

//输出方框(游戏范围区)

{inti;

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(i<11)printf("0%d",i-1);elseprintf("%d",i-1);

Position(79,i);printf("║");

Position(4,25);printf("小鸟即将出现,请准备按键起飞…");

getch();

Position(4,25);printf("");

voidCreatBg()

//创建障碍物坐标(便于打印输出)

{Bg*Bg2=(Bg*)malloc(sizeof(Bg));

Bg1->x=90;Bg1->y=8;//确定障碍物的一对基本坐标(此时值是在游戏框之外)

Bg2->x=Bg1->x+Distance;Bg2->y=9;//下一障碍物的基本坐标x、y

Bg1->l_blank=Max_blank-Grade;//障碍物上下两部分之间的空白距离l_blank

Bg2->l_blank=Max_blank-Grade;

Bg1->next=Bg2;Bg1->pri=Bg2;

Bg2->next=Bg1;Bg2->pri=Bg1;

voidInsertBg(Bg*p)

//随机改变障碍物的y坐标,让空白通道有上下变化

{inttemp;

Bg*Bgs=(Bg*)malloc(sizeof(Bg));

Bgs->x=p->pri->x+Distance;

Bgs->l_blank=Max_blank-Grade;

srand((int)time(0));//启动随机数发生器

temp=rand();//产生一个随机数并赋值给temp

if(temp%2==0)

{if((temp%4+p->pri->y+Max_blank-Grade)<21)

Bgs->y=p->pri->y+temp%4;

elseBgs->y=p->pri->y;

{if((p->pri->y-temp%4)>2)Bgs->y=p->pri->y-temp%4;

elseBgs->y=p->pri->y;

Bgs->pri=p->pri;Bgs->next=p;

p->pri->next=Bgs;p->pri=Bgs;

voidCreatBird()

//建立小鸟的坐标(初始打印输出小鸟的位置)

{Bird->x=41;Bird->y=10;}

intCheckYN(Bg*q)

//判断游戏结束与否(值为0是要结束,为1没有要结束)

{Bg*p=q;inti=0;

while(++i<=5)

{if(Bird->y>23)return0;

if(Bird->x==p->x&&Bird->y<=p->y)return0;

if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y)return0;

if(Bird->x==p->x&&Bird->y>p->y+p->l_blank)return0;

if((Bird->x==p->x||Bird->x==p->x+1||Bird->x==p->x+2)&&Bird->y==p->y+p->l_blank)

return0;

p=p->next;

return1;

voidCheck_Bg(Bg*q)

//核查开头的障碍物坐标是否在游戏区内

{Bg*p=q;inti=0,temp;

while(++i<=5)

{if(p->x>-4)p=p->next;

{srand((int)time(0));temp=rand();

if(temp%2==0)

{if((temp%4+p->y+Max_blank-Grade)<21)p->y=p->y+temp%4;

elsep->y=p->y;p->x=p->pri->x+Distance;

p->l_blank=Max_blank-Grade;

{if((p->y-temp%4)>2)p->y=p->y-temp%4;

elsep->y=p->y;p->x=p->pri->x+Distance;

p->l_blank=Max_blank-Grade;

voidPrt_Bg(Bg*q)

//打印输出障碍物(依据其x、y坐标进行相应输出)

{Bg*p=q;inti=0,k,j;

while(++i<=5)

{if(p->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<=23;k++){Position(p->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<=22;j++){Position(p->x+1,j);printf("");printf("");}

voidPrtBird()

//打印输出小鸟

{Position(Bird->x,Bird->y-1);printf("");

Position(Bird->x,Bird->y);printf("Ю");

Position(38,2);printf("Score:%d",Score);

voidLoop_Bg(Bg*q)

//障碍物x坐标左移,并记录成绩

{Bg*p=q;inti=0;

while(++i<=5)

{p->x=p->x-1;p=p->next;

if(Bird->x==p->x)

{Score+=1;

if(Score%4==0&&Grade<4)Grade++;

intmain()

{inti=0;intt;

while(1)

Csh();PrFK();CreatBg();

InsertBg(Bg1);InsertBg(Bg1);InsertBg(Bg1);

CreatBird();

while(1)

{if(!CheckYN(Bg1))break;

Check_Bg(Bg1);Prt_Bg(Bg1);

PrtBird();Loop_Bg(Bg1);

Bird->y=Bird->y+1;

if(GetAsyncKeyState(VK_UP))

//按下了向上方向键

{Position(Bird->x,Bird->y-1);printf("");

Bird->y=Bird->y-4;

Sleep(200);

//程序延时200毫秒(数值大小决定游戏速度快慢)

Position(6,25);

printf("游戏结束!请输入:0.退出1.重玩");

scanf("%d",&t);

if(t==0)break;

system("cls");Score=0;

return0;

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告