C海龟图形问题

[复制链接]
查看11 | 回复1 | 2009-3-19 21:39:53 | 显示全部楼层 |阅读模式
#include
#define SIZE 50
int main()
{
int command; /*用户输入的命令*/
int moveNumber; /*移动的步数*/
int orientation;/*存储方向*/
int x;
int y;
int floor[SIZE][SIZE] = { 0 };
int i = 0;

int j = 0;
int pen = 1; /*默认笔向上*/

/*游戏说明*/
printf( "命令
含义\n" );
printf( "1
笔在上\n" );
printf( "2
笔在下\n" );
printf( "3
向右转\n" );
printf( "4
向左转\n" );
printf( "5
向前移动10个空格(或者10以外的其它数字)\n" );
printf( "6
输出20乘20数组\n" );
printf( "9
数据结束(标志)\n" );
printf( "\n\n\n请输入命令: " );
scanf( "%d", &command );

while( command != 9 )
{
switch( command )
{
case 1:

pen = 1;

break;
case 2:

pen = 2;

break;
case 3:

orientation = 0; /*0为向右转*/

break;
case 4:

orientation = 1; /*1为向左转*/

break;
case 5:

printf( "输入要移动的步数: " );

scanf( "%d", &moveNumber );



if( orientation == 0 )

{

if( i == 0 && j == 0 )

{

j = j + moveNumber;

for( x = 0; x0 )

{

i += moveNumber;

for( x = 0; x0 && j > 0 )

{

j = j - moveNumber;

for( x = j; x >= j - moveNumber ; x-- )

{

if( pen == 2 )

{

floor[x] = 1;

}



}

break;

}



if( i > 0 && j == 0 )

{

i = i - moveNumber;

for( x = i; x >= i - moveNumber; x--)

{

if( pen == 2 )

{

floor[x][j] = 1;

}



}

break;

}

}
case 6:

for( x = 0; x <= 19; x++)

{

for( y = 0; y <= 19; y++)

{

if( floor[x][y] == 0 )

{

printf( "" );

}



if( floor[x][y] == 1 )

{

printf( "# " );

}

if( y == 19 )

{

printf( "\n" );

}

}

}

break;
}
printf( "请输入命令: " );
scanf( "%d", &command );
}
return 0;
}
这个程序只完成了部分功能
我输入,2,3,5,12,可以输出12个#
再输3,5,12,又输出12个#
再输3,5,12就不能输出12个#了,只有一个
请高手看下哪错了

回复

使用道具 举报

千问 | 2009-3-19 21:39:53 | 显示全部楼层
这个是C程序啊...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行