这到底错哪了,我改了好久了
#include<stdio.h>#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
int i=0,j=0;
int snakey={5,4,3,2,1};
int snakex={1,1,1,1,1};
int life=0;
int lenght=5;
char map={"**********************",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"* *",
"**********************"};
void put_money(int i,int j)
{
int x=0,y=0;
srand((unsigned)time(NULL));
while((map==003)||(map==002||map=='*')||((x==i)&&(y==j)))
{
x=rand()%21+1;
y=rand()%10+1;
}
map='$';
return;
}
void output()
{
system("cls");
for(i=0;i<12;i++)
{
for(j=0;j<23;j++)
printf("%c",map);
printf("\n");
}
return;
}
void gameover()
{
life=1;
printf("笨蛋,输了吧!!!\n");
return;
}
void turn_up()
{
system("cls");
if( (snakex==1)||(map-1]]==003) )
gameover();
else
{
if(map-1]]=='$');
{
put_money(snakey,snakex-1);
lenght++;
map]]=003;
}
for(i=lenght;i>0;i--)
{
snakex=snakex;
snakey=snakey;
}
map]]=' ';
snakex--;
for(i=lenght-1;i>0;i--)
map]]=003;
map]]=002;
output();
}
return;
}
void turn_down()
{
system("cls");
if((snakex==10)||(map+1]]==003))
gameover();
else
{
if(map+1]=='$'])
{
put_money(snakey,snakex+1);
lenght++;
map]]=003;
}
for(i=lenght;i>0;i--)
{
snakex=snakex;
snakey=snakey;
}
snakex++;
map]]=' ';
for(i=lenght-1;i>0;i--)
map]]=003;
map]]=002;
output();
}
return;
}
void turn_left()
{
system("cls");
if ((snakey==1)||(map]-1]==003))
gameover();
else
{
if(map]-1]=='$')
{
put_money(snakey-1,snakex);
lenght++;
map]]=003;
}
for(i=lenght;i>0;i--)
{
snakex=snakex;
snakey=snakey;
}
map]]=' ';
snakey--;
for(i=lenght-1;i>0;i--)
map]]=003;
map]]=002;
output();
}
return;
}
void turn_right()
{
system("cls");
if ((snakey==21)||(map]+1]==003))
gameover();
else
{
if(map],snakex+1=='$')
lenght++;
map]]=003;
}
for(i=lenght;i>0;i--)
{
snakex=snakex;
snakey=snakey;
}
map]]=' ';
snakey++;
for(i=lenght-1;i>0;i--)
map]]=003;
map]]=002;
output();
return;
}
int main()
{
int i,timeover,hard;
long start;
char name,direcation;
printf("\n向上移动:W;向下移动:S;向左移动:A;向右移动:D\n");
printf("\t 请选择难度(数字)\n\t分1-5级,分别代表\n\t1难,2中上,3中,4中下,5易:\n");
scanf("%d",&hard);
system("cls");
for(i=1;i<5;i++)
map=003;
map=002;
put_money(0,0);
output();
while(life!=1)
{
timeover=1;
start=clock();
while((timeover=(clock()-start<=hard*100))&&!kbhit());
if(timeover)
{
direcation=getch();
}
switch(direcation)
{
case'W':turn_up();break;
case'S':turn_down();break;
case'A':turn_left();break;
case'D':turn_right();break;
}
}
system("pause");
return 0;
}
请对程序做一个注释,方便进行解读,并确认哪里有问题。
页:
[1]