c语言的题目,不知道原因。
发布时间:2025-05-13 06:56:09 发布人:远客网络
一、c语言的题目,不知道原因。
1、函数名前面有个类型说明,是指的函数返回值的类型。函数内的每个参数都必须有一个类型声明,在声明的时候也可以只有类型(在函数体中则不行)。例如声明:int add(int, int);
2、貌似没有C这样的空参数。。。D中的char [][]也不对,应该是char a[][]。
3、引用结构体中的量要用到".",所以yyy是结构体xxx中的,而zzz是结构体yyy中的。
二、C语言中的俄罗斯方块
<Russia Diamonds Ver 1.0>
/*****************************************************************************************/
#include"graphics.h"/*头文件*/
#define ESC 0x11b/*键盘扫描码*/
/*****************************************************************************************/
struct diamond/*记录每种方块每种状态的信息*/
int grid[12][23];/*记录所有格子的状态(0)没有方块(1)有固定方块(2)有活动方块*/
struct diamond*nowinfo;/*当前活动方块*/
struct diamond*nextinfo;/*下一个方块*/
int backcolor;/*游戏区域背景色*/
/*****************************************************************************************/
void show_interface(int mode);/*显示游戏界面*/
void show_copsign(int topx,int topy,int size,int color);/*显示公司标志--恒基伟业*/
void show_intro(int xs,int ys);/*显示软件介绍区*/
void scandel();/*扫描所有格子看是否有可消除行*/
void show_down();/*方块下落后的下一个状态*/
void show_next();/*方块翻转后的下一个状态*/
void show_left();/*方块向左移动后的下一个状态*/
void show_right();/*方块向右移动后的下一个状态*/
void interrupt(*oldtimer)();/*指向未安装前的中断向量,即函数指针,指向一段可执行的代码*/
void install();/*安装新的中断向量,即将中断服务程序安装到中断向量表中*/
void interrupt newtimer();/*中断服务程序*/
struct diamond*get_diamond();/*随机得到一个方块*/
struct diamond*create_I();/*函数用来构造各种类形方块的环形链表*/
struct diamond*create_T();/*返回链表中随机一个状态的指针*/
void delinfo(struct diamond*info);/*释放当前方块所占用的空间*/
void addtobuffer(int c);/*向键盘缓冲区中增加一个DOWN*/
/*void clrkey();调用dos中断清空键盘缓冲区,未使用此方法.*/
void showsubwin(struct diamond*next);/*在小窗口显示下一个方块*/
void showscore(int scoreget);/*显示分数*/
void startset();/*初始化游戏*/
/*****************************************************************************************/
initgraph(&driver,&mode,"");/*初始化*/
show_interface(9);/*显示界面*/
outtextxy(5,469,"Press any key to start...");
nowinfo=get_diamond();/*得到一个当前方块*/
for(i=0;i<=21;i++)/*初始化grid[12][23]*/
x=nowinfo->start_x;/*初始化方块位置*/
nextinfo=get_diamond();/*得到下一个方块*/
key=bioskey(0);/*得到键盘扫描码*/
outtextxy(5,469,"Are you sure to restart(Y/N)...");
key=bioskey(0);/*得到键盘扫描码*/
outtextxy(5,469,"Are you sure to exit(Y/N)...");
key=bioskey(0);/*得到键盘扫描码*/
/*****************************************************************************************/
/*****************************************************************************************/
void show_interface(int fill_mode)
setfillstyle(SOLID_FILL,backcolor);
outtextxy(422,408,"HI-TECH WEALTH");
/*****************************************************************************************/
void show_copsign(int topx,int topy,int size,int color)
rectangle(topx-halfsize,topy+halfsize,topx+halfsize,yadd1+halfsize);
setfillstyle(SOLID_FILL,color);
floodfill(xdel+1,yadd1,color);
floodfill(topx,yadd2-1,color);
floodfill(xadd-1,yadd1,color);
rectangle(topx-halfsize,yadd1-qtrsize,topx-0.75*halfsize,yadd1+qtrsize);
floodfill(topx-halfsize+1,yadd1-qtrsize+1,color);
rectangle(topx-qtrsize,yadd1-halfsize,topx+qtrsize,yadd1-0.25*halfsize);
floodfill(topx-qtrsize+1,yadd1-halfsize+1,color);
rectangle(topx+0.75*halfsize,yadd1-qtrsize,topx+halfsize,yadd1+qtrsize);
floodfill(topx+0.75*halfsize+1,yadd1-qtrsize+1,color);
rectangle(topx-qtrsize,yadd1+0.25*halfsize,topx+qtrsize,yadd2-halfsize);
floodfill(topx-qtrsize+1,yadd1+0.25*halfsize+1,color);
line(topx,topy-1,xdel-1,yadd1);
line(xdel-1,yadd1,topx,yadd2+1);
line(topx,yadd2+1,xadd+1,yadd1);
line(xadd+1,yadd1,topx,topy-1);
/*****************************************************************************************/
void show_intro(int xs,int ys)
rectangle(xs-3,ys-3,xs+239,ys+115);
line(xs-3,ys+26,xs+239,ys+26);
line(xs-3,ys+72,xs+239,ys+72);
sprintf(stemp,"-Roll-Downwards");
outtextxy(xs+40,ys+45,"<-Turn Left>-Turn Right");
outtextxy(xs+40,ys+60,"Esc-Exit R-Restart");
outtextxy(xs,ys+75,"Russia Diamonds Ver 1.0");
outtextxy(xs,ys+90,"CopyRight By ChangYong.01-11-1");
outtextxy(xs,ys+105,"Email:forever_chang@163.com");
/*****************************************************************************************/
first=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
if(random(2)==0){return first;}
/*****************************************************************************************/
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
/*****************************************************************************************/
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
/*****************************************************************************************/
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
/*****************************************************************************************/
first=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
if(random(2)==0){return first;}
/*****************************************************************************************/
first=(struct diamond*)malloc(sizeof(struct diamond));
info=(struct diamond*)malloc(sizeof(struct diamond));
if(random(2)==0){return first;}
/*****************************************************************************************/
first=(struct diamond*)malloc(sizeof(struct diamond));
/*****************************************************************************************/
int nowx;/*记录当前每个格子的位置*/
int haveit;/*当前格子是否已经显示*/
struct diamond*next;/*当前方块的翻转后的下一个状态*/
if(next==NULL){gotoxy(1,1);printf("null");}
for(i=0;i<=3;i++)/*判断是否能够翻转,若不能,就直接退出该函数*/
if(grid[x+next->x[i]][y+next->y[i]]==1)
setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
if(next->x[j]==nowinfo->x[i]&&next->y[j]==nowinfo->y[i]){haveit=1;break;}
if(haveit==0)/*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if(y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
if(grid[x+nowinfo->x[i]][y+nowinfo->y[i]]!=2)/*如果该格子还没有被显示*/
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
grid[nowx][nowy]=2;/*设置该格子当前有活动方块*/
/*****************************************************************************************/
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
for(i=0;i<=3;i++)/*判断是否可以向左移动*/
if(grid[x-1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
if(nowinfo->x[i]==nowinfo->x[j]-1&&nowinfo->y[i]==nowinfo->y[j]){haveit=1;break;}
if(haveit==0)/*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if(y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
if(grid[nowx][nowy]!=2)/*如果该格子还没有被显示*/
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
/*****************************************************************************************/
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
if(grid[x+1+nowinfo->x[i]][y+nowinfo->y[i]]==1)
return;/*判断是否可以向右移动*/
setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
if(nowinfo->x[i]==nowinfo->x[j]+1&&nowinfo->y[i]==nowinfo->y[j]){haveit=1;break;}
if(haveit==0)/*判断翻转后该格子是否显示,若不显示,将该格子设为背景色*/
grid[x+nowinfo->x[i]][y+nowinfo->y[i]]=0;
if(y+nowinfo->y[i]>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+(nowinfo->x[i]+x)*20+1,-20+(nowinfo->y[i]+y)*20+1,color);
setfillstyle(SOLID_FILL,nowinfo->color);/*设置填冲色为方块的颜色*/
if(nowy>=4)/*判断该格子是否到了可以显示的区域*/
floodfill(80+nowx*20+1,-20+nowy*20+1,color);
/*****************************************************************************************/
int haveit;/*当前格子是否已经显示*/
int nowx;/*记录当前每个格子的位置*/
if(grid[x+nowinfo->x[i]][y+nowinfo->y[i]+1]==1)/*判断方块是否能够下落*/
grid[x+nowinfo->x[j]][y+nowinfo->y[j]]=1;
outtextxy(5,469,"Do you want to restart(Y/N)...");
while(bioskey(1)) bioskey(0);/*清除键盘缓冲区*/
nowinfo=nextinfo;/*得到新的方块*/
nextinfo=get_diamond();/*得到下一个方块*/
x=nowinfo->start_x;/*重新设置方块位置*/
setfillstyle(SOLID_FILL,backcolor);/*设置背景色以消除不需要的格子*/
if(nowinfo->x[i]==nowinfo->x[j]&&nowinfo->y[i]==nowinfo->y[j]+1){haveit=1;break;}