C语言100行的程序,要自己写的 谢谢. 所有分全给了.

用的东西尽量简单。

这是我写的贪吃蛇,楼主看行不行?不行换一个
#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<windows.h>

int length=1;//蛇的当前长度,初始值为1
int line[100][2];//蛇的走的路线
int head[2]={40,12};//蛇头
int food[2];//食物的位置
char direction;//蛇运动方向
int x_min=1;x_max=77; y_min=2; y_max=23;//设置蛇的运动区域
int tail_before[2]={40,12};//上一个状态的蛇尾
char direction_before='s';//上一个状态蛇的运动方向
int live_death=1;//死活状态,0死,1活
int eat_flag=0;//吃食物与否的状态。0没吃 1吃了
int max=0;
int delay;//移动延迟时间

void gotoxy(int x, int y)//x为列坐标,y为行坐标
{
COORD pos = {x,y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}

void hidden()//隐藏光标
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut,&cci);
cci.bVisible=0;//赋1为显示,赋0为隐藏
SetConsoleCursorInfo(hOut,&cci);
}

void update_score()
{
gotoxy(2,1);
printf("我的分数:%d",length);
gotoxy(42,1);
printf("最高记录:%d",max);
}

void create_window()
{
gotoxy(0,0);
printf("╔══════════════════╦═══════════════════╗");
printf("║ ║ ║");
printf("╠══════════════════╩═══════════════════╣");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("║ ║");
printf("╚══════════════════════════════════════╝");

}

void update_line()
{
int i;
if(eat_flag==0)//吃了食物就不用记住上一个状态的蛇尾,否则会被消掉
{
tail_before[0]=line[0][0];//记住上一个状态的蛇尾
tail_before[1]=line[0][1];

for(i=0;i<length-1;i++)//更新蛇头以后部分
{
line[i][0]=line[i+1][0];
line[i][1]=line[i+1][1];
}

line[length-1][0]=head[0];//更新蛇头
line[length-1][1]=head[1];

}

}

void initial()
{
FILE *fp;
gotoxy(head[0],head[1]);
printf("蛇");

line[0][0]=head[0];//把蛇头装入路线
line[0][1]=head[1];

if((fp=fopen("highest","r"))==NULL)
{
fp=fopen("highest","w");
fprintf(fp,"%d",0);
max=0;
fclose(fp);
}//第一次使用时,初始化奖最高分为0

else
{
fp=fopen("highest","r");
fscanf(fp,"%d",&max);
}
update_score();

}

void createfood()
{
int flag,i;
srand((unsigned)time(NULL));
for(;;)
{
for(;;)
{
food[0]=rand()%(x_max+1);
if(food[0]%2==0 && food[0]>x_min)
break;
}//产生一个偶数横坐标

for(;;)
{
food[1]=rand()%(y_max);
if(food[1]>y_min)
break;
}

for(i=0,flag=0;i<length;i++)//判断产生的食物是否在蛇身上,在flag=1,否则为0
if(food[0]==line[i][0] && food[1]==line[i][1])
{ flag=1; break; }

if(flag==0)// 食物不在蛇身上 结束循环
break;

}
gotoxy(food[0],food[1]);
printf("蛇");

}

void show_snake()
{

gotoxy(head[0],head[1]);
printf("蛇");

if(eat_flag==0)//没吃食物时消去蛇尾
{
gotoxy(tail_before[0],tail_before[1]);
printf(" ");//消除蛇尾
}
else
eat_flag=0;//吃了食物就回到没吃状态

}

char different_direction(char dir)
{
switch(dir)
{
case 'a': return 'd';
case 'd': return 'a';
case 'w': return 's';
case 's': return 'w';

}
}

void get_direction()
{
direction_before=direction;//记住蛇上一个状态的运动方向

while(kbhit()!=0) //调试
direction=getch();

if( direction_before == different_direction(direction) || (direction!='a' && direction!='s' && direction!='d' && direction!='w') ) //新方向和原方向相反,或获得的方向不是wasd时,保持原方向
direction=direction_before;

switch(direction)
{
case 'a': head[0]-=2; break;
case 'd': head[0]+=2; break;
case 'w': head[1]--; break;
case 's': head[1]++; break;
}
}

void live_state()//判断蛇的生存状态
{
FILE *fp;
int i,flag;
for(i=0,flag=0;i<length-1;i++)//判断是否自己咬到自己
if( head[0]==line[i][0] && head[1]==line[i][1])
{
flag=1;
break;
}
if(head[0]<=x_min || head[0]>=x_max || head[1]<=y_min || head[1]>=y_max || flag==1)
{
system("cls");
create_window();
update_score();
gotoxy(35,12);
printf("游戏结束!\n");
Sleep(500);
live_death=0;
fp=fopen("highest","w");
fprintf(fp,"%d",max);//保存最高分
}

}

void eat()
{
if(head[0]==food[0]&&head[1]==food[1])
{
length++;
line[length-1][0]=head[0];//更新蛇头
line[length-1][1]=head[1];
eat_flag=1;
createfood();
if(length>max)
max=length;
update_score();
if(delay>100)
delay-=30;//加速
}
}

main()
{
int x=0,y=0;
int i;
hidden();//隐藏光标
create_window();
initial();
createfood();
for(direction='s',delay=600;;)
{
get_direction();
eat();
update_line();
live_state();//判断生死状态
if(live_death==1)
{
show_snake();

}
else
break;
Sleep(delay);

}

}
这是在VC6.0环境下运行的,如果你用的TC,我可以帮你改成TC环境下运行的追问

能把调试中的错误发给我么

追答

错误我已经改完了,现在程序已经没有错误了。
以下是的错误是已经改正了的。
C(205) : error C2143: syntax error : missing ';' before 'case'
C(265) : warning C4013: 'eat1' undefined; assuming extern returning int
C(257) : warning C4101: 'i' : unreferenced local variable
warning C4715: 'different_direction' : not all control paths return a value
C(188) : error C2143: syntax error : missing ';' before '}'
error LNK2001: unresolved external symbol _print
fatal error LNK1120: 1 unresolved externals
C(126) : error C2065: 'f' : undeclared identifier
C(126) : error C2143: syntax error : missing ';' before 'type'
C(145) : error C2065: 'i' : undeclared identifier
C(145) : error C2065: 'flag' : undeclared identifier

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-16
C语言1~100 行 完毕 跳转 任务结束 给分 给分
第2个回答  2011-06-16
#include<stdio.h>
#include<stdlib.h>

struct student
{
char stunumb[13];
int score;
};
typedef struct node
{
struct student content;
struct node* next;
} Stu;

Stu* Creat(void);
void ShowList(Stu*);
void DeleList(Stu*);
Stu* DeleElem(Stu**,int);
void MaxScore(Stu*);

int main()
{
int s;
printf("创建列表,请以负数成绩结束\n");
Stu* a=Creat();
printf("\n");
ShowList(a);
MaxScore(a);
printf("请输入要删除的元素:");
while(scanf("%d",&s)!=1)
{
fflush(stdin);
printf("成绩格式有误!\n");
}
printf("\n");
DeleElem(&a,s);//严防野指针
ShowList(a);
DeleList(a);
return 0;
}

Stu* Creat()
{
printf("(请以学号 成绩的顺序输入)\n");
Stu*Temp;
int m,ch=0;
char*p;
Stu*Curent=NULL;
Stu*head=NULL;
Temp=(Stu*)malloc(sizeof(Stu));
while((m=scanf("%d",&Temp->content.score))!=1)
{
fflush(stdin);
printf("成绩输入格式有误请重新输入:\n");
}

if(Temp->content.score>=0)
head=Temp;
while(Temp->content.score>=0)
{
fflush(stdin);
do
{
ch=0;
gets(Temp->content.stunumb);
p=Temp->content.stunumb;
while(*p!='\0')
{
p++;
ch++;
}
if(ch>12)
printf("学号格式为12位,请重新输入:\n");
}while(ch>12);
Curent=Temp;
Temp=(Stu*)malloc(sizeof(Stu));
Curent->next=Temp;
while((m=scanf("%d",&Temp->content.score))!=1)
{
fflush(stdin);
printf("成绩输入格式有误请重新输入:\n");
}

}
if(head!=NULL)
Curent->next=NULL;
free(Temp);
return head;
}
void ShowList(Stu* head)
{
if(head==NULL)
{
printf("空链表");
}
else
{
printf("学号\t\t成绩\n");
while(head!=NULL)
{
printf("%-12s\t\t%3d\n",head->content.stunumb,head->content.score);
head=head->next;
}
}
}
void DeleList(Stu*head)
{
Stu*temp;
if(head==NULL)
return;
else
{
while(head!=NULL)
{
temp=head;
head=head->next;
free(temp);
}
}
}

Stu* DeleElem(Stu**head,int s)
{
Stu* previous=NULL;
Stu* temp;
Stu* phead=*head;
int tag=0;
while(phead!=NULL)
{
if(phead->content.score==s)
{
if(NULL==previous)
{
temp=phead;
phead=phead->next;
*head=phead;
free(temp);
tag=1;
}
else
{
temp=phead;
previous->next=phead->next;
phead=phead->next;
free(temp);
tag=1;
}
}
else
{
previous=phead;
phead=phead->next;
}
}
if(0==tag)
{
printf("没有要删除的元素!!\n");
}
return *head;
}

void MaxScore(Stu* head)
{
int max=0;
Stu* temp=NULL;
if(head==NULL)
printf("空链表!!");
else
{
while(head!=NULL)
{
if(head->content.score>max)
{
temp=head;
}
head=head->next;
}
}
printf("成绩最高者信息:\n");
printf("%-12s\t\t%-2d\n",temp->content.stunumb,temp->content.score);
}
第3个回答  2011-06-16
我不清楚这样做有何意义?对你?对我?
第4个回答  2011-06-16
关于哪方面的? 要不这么写呀 具体的要求追问

随便写什么都行 只要是100行,还能不能把调试中的错误写给我呀

邮箱 94277133@qq.com

追答

你总得给个题吧 每题怎魔写 还不如 去网上找个

追问

老师就是要求这样阿。。随便你写什么 只要有100行,把调试错误也给他就行了呀

追答

别的朋友都给你了

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网