您当前的位置:首页 > 生活 > 内容

用C语言编写贪吃蛇游戏的程序?手机c语言编程软件有哪些,谢谢,我们学校不让带电脑

C语言:指针型数组是什么意思int*p[n];-----指针数组,顺序链表(要用到指针),每个元素均为指向整型数据的指针,《数据结构(C语言版)》的内容主要是什么C语言的数据结构是用C 语言描述数据结构的,int(*)p();------p为指向函数的指针,int*p();----------函数带回指针,主要有顺序表(是用数组实现的),int(*)p[n];------p为指向一维数组的指针。

用C语言编写贪吃蛇游戏的程序

回答:Mr.emily大师6月3日 16:45 #define N 200#include《graphics.h》#include《stdlib.h》#include《dos.h》#define LEFT 0x4b00#define RIGHT 0x4d00#define DOWN 0x5000#define UP 0x4800#define Esc 0x011bint i,key;int score=0;int gamespeed=50000;struct Food{int x;int y;int yes;}food;struct Snake{int x[N];int y[N];int node;int direction;int life;}snake;void Init();void Close();void DrawK();void GamePlay();void GameOver();void PrScore();void main(){ Init();DrawK();GamePlay();Close();}void Init(){int gd=DETECT,gm;initgraph(&gd,&gm,“F:\\tuoboc2“);/*此处为turboc的路径,读者可以根据自己的电脑而改*/cleardevice();}void DrawK(){setbkcolor(LIGHTGREEN);setcolor(11);setlinestyle(SOLID_LINE,0,THICK_WIDTH);for(i=50;i《=600;i+=10){rectangle(i,40,i+10,49);rectangle(i,451,i+10,460);}for(i=40;i《=450;i+=10){rectangle(50,i,59,i+10);rectangle(601,i,610,i+10);}}void GamePlay(){randomize();food.yes=1;snake.life=0;snake.direction=1;snake.x=100;snake.y=100;snake.x=110;snake.y=100 ;snake.node=2;PrScore();while(1){while(!kbhit()){ if(food.yes==1){food.x=rand()%400+60;food.y=rand()%350+60;while(food.x%10!=0)food.x++;while(food.y%10!=0)food.y++;food.yes=0;}if(food.yes==0){setcolor(GREEN);rectangle(food.x,food.y,food.x+10,food.y-10);}for(i=snake.node-1;i》0;i--){snake.x[i]=snake.x[i-1];snake.y[i]=snake.y[i-1];}switch(snake.direction){case 1:snake.x+=10;break;case 2:snake.x-=10;break;case 3:snake.y-=10;break;case 4:snake.y+=10;break;}for(i=3;i《snake.node;i++){if(snake.x[i]==snake.x&&snake.y[i]==snake.y){ GameOver();snake.life=1;break;}}if(snake.x《55||snake.x》595||snake.y《55||snake.y》455){GameOver();snake.life=1;}if(snake.life==1)break;if(snake.x==food.x&&snake.y==food.y){setcolor(0);rectangle(food.x,food.y,food.x+10,food.y-10);snake.x[snake.node]=-20;snake.y[snake.node]=-20;snake.node++;food.yes=1;score+=10;PrScore();}setcolor(4);for(i=0;i《snake.node;i++)rectangle(snake.x[i],snake.y[i],snake.x[i]+10,snake.y[i]-10);delay(gamespeed);setcolor(0);rectangle(snake.x[snake.node-1],snake.y[snake.node-1],snake.x[snake.node-1]+10,snake.y[snake.node-1]-10);}if(snake.life==1)break;key=bioskey(0);if(key==Esc)break;else if(key==UP&&snake.direction!=4)snake.direction=3;else if(key==RIGHT&&snake.direction!=2)snake.direction=1;else if(key==LEFT&&snake.direction!=1)snake.direction=2;else if(key==DOWN&&snake.direction!=3)snake.direction=4;}}void GameOver(){cleardevice();PrScore();setcolor(RED);settextstyle(3,0,4);outtextxy(100,100,“Mengmeng,i love you!“);getch();}void PrScore(){char str;setfillstyle(SOLID_FILL,YELLOW);bar(50,15,220,35);setcolor(6);settextstyle(0,0,2);sprintf(str,“score:%d“,score);outtextxy(55,20,str);}void Close(){ getch();closegraph();}Mr.emily

手机c语言编程软件有哪些,谢谢,我们学校不让带电脑

MicrosoftVisualC++、MicrosoftVisualStudio、DEVC++、Code::Blocks、BorlandC++、WaTComC++、BorlandC++Builder、GNUDJGPPC++、Lccwin32CCompiler3.1、HighC、TurbC、gcc、C-Free和Win-TC、MyTc等等,太多了,由于C语言比较成熟,所以编程环境很多。建议使用MicrosoftVisualC++。

《数据结构(C语言版)》的内容主要是什么

C语言的数据结构是用C 语言描述数据结构的,主要有顺序表(是用数组实现的),顺序链表(要用到指针),串(就是C语言中的字符串),堆栈【顺序堆栈(用数组实现)和链接堆栈(用链表实现)】,树(主要是讲二叉树),图,再就是内排序,外排序,文件的查找。链表,二叉树,图是最重要的。基本就是这样!!!!

C语言:指针型数组是什么意思

int*p[n];-----指针数组,每个元素均为指向整型数据的指针。int(*)p[n];------p为指向一维数组的指针,这个一维数组有n个整型数据。int*p();----------函数带回指针,指针指向返回的值。int(*)p();------p为指向函数的指针。


声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,谢谢。

上一篇: 荣耀60发布会直播(荣耀60系列发布,这款手机都有什么亮点)

下一篇: 2022勿忘国耻振兴中华个人演讲稿经典素材



推荐阅读

网站内容来自网络,如有侵权请联系我们,立即删除! | 软文发布 | 粤ICP备2021106084号