自己编了一个小游戏,但是不知道怎么过关,晕了!
玩法:输入坐标,会将坐标以及坐标上下左右的点反转(0转为x,x转为0),当所有点为X后,过关
程序:
#include<stdio.h>
#include<string.h>
char pazuru[5][5];
int checkfinished()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(pazuru[i][j]=='0')
return 0;
}
}
return 1;
}
exchange(char *position)
{
int i,j;
j=position[0]-97;
i=position[1]-65;
printf("%d%d\n",i,j);
if(pazuru[i][j]=='0')
pazuru[i][j]='x';
else
pazuru[i][j]='0';
if(i>0)
{
if(pazuru[i-1][j]=='0')
pazuru[i-1][j]='x';
else
pazuru[i-1][j]='0';
}
if(i<4)
{
if(pazuru[i+1][j]=='0')
pazuru[i+1][j]='x';
else
pazuru[i+1][j]='0';
}
if(j>0)
{
if(pazuru[i][j-1]=='0')
pazuru[i][j-1]='x';
else
pazuru[i][j-1]='0';
}
if(j<4)
{
if(pazuru[i][j+1]=='0')
pazuru[i][j+1]='x';
else
pazuru[i][j+1]='0';
}
}
int checkposition(char *position)
{
if(strlen(position)>2)
return 0;
else if(position[0]=='z' && position[1]=='z')
{
printf("Exit!");
exit(0);
}
else if(position[0]>='a' && position[0]<='e' && position[1]>='A' && position[1]<='E')
return 1;
else
return 0;
}
void showpoint()
{
int i,j;
printf("%2s%2s%2s%2s%2s%2s\n","","a","b","c","d","e");
for(i=0;i<5;i++)
{
printf("%2c",i+65);
for(j=0;j<5;j++)
{
printf("%2c",pazuru[i][j]);
}
printf("\n");
}
}
void init()
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
pazuru[i][j]='0';
}
}
}
void play()
{
char position[2];
printf(">input:");
gets(position);
if(checkposition(position))
{
exchange(position);
showpoint();
}
else
printf(">Error!\n");
}
main()
{
int gameover=0;
init();
showpoint();
while(!gameover)
{
play();
gameover=checkfinished();
}
printf("Finished!");
}