2011年5月7日星期六

  None

#include

#include

#include

 

/*logo海¡ê龟¨º画-图ª?游®?戏¡¤*/

 

void draw(int pen,int dir,int step,int arrayDir[],int arrayTotal[][50]);

 

 

int main(void)

{

    int penStatus=1; /*determine the pen status down or up*/

    int dir=0; /*detemine the direction*/

    int command=0; /*first input command*/

    int command2=0; /*steps */

    int array1[50][50]={0};

    int arrayDir[2]={0};

    int a=0;

    int i=0;

    int j=0;

    

    while(a!=-1)

    {

    printf("Enetr the command:");

    scanf("%d", &command);

 

    switch(command)

    {

    case 1:

        penStatus=1;

        break;

    case 2:

        penStatus=2;

        break;

    case 3:

        dir+=1;

        break;

    case 4:

        dir-=1;

        break;

    case 5:

        printf("dir:%d\n",dir);

        scanf(",%d", &command2);

        draw(penStatus,dir,command2,arrayDir,array1);

        printf("poisition now is %d %d\n",arrayDir[0],arrayDir[1]);

        break;

    case 6:

        for(i=0;i<50;i++)

        {

            for (j=0;j<50;j++)

            {

                if (array1[i][j]==1)

                    printf("*");

                else

                    printf(" ");

            }

            printf("\n");

            

        }

        break;

    case 9:

        a=-1;

        break;

    default:

        printf("Wrong Input");

    }

}

}

    

    void draw(int pen,int dir,int step,int arrayDir[],int arrayTotal[][50])

    {

        int i=0;

        int x;

        x=dir%4;

        printf("%d\n",x);

 

        if (dir%4==0)

        {

                if(pen==2)

            {

                for (i=0;i<=step;i++)

                {

                    arrayTotal[arrayDir[0]][arrayDir[1]+i]+=1;

                }

                    arrayDir[1]+=step;

            }

        }

                

        if (dir%4==1||-3)

        {

            if (pen==2)

            {

                for(i=0;i<=step;i++)

                {

                    arrayTotal[arrayDir[0]+i][arrayDir[1]]+=1;

                }

                arrayDir[0]+=step;

            }

        }

 

        if (dir%4==3||-1)

        {

            if (pen==2)

            {

                for(i=0;i<=step;i++)

                {

                    arrayTotal[arrayDir[0]-i][arrayDir[1]]+=1;

                }

                arrayDir[0]-=step;

            }

        }

 

         if (dir%4==2||-2)

        {

            if (pen==2)

            {

                for(i=0;i<=step;i++)

                {

                    arrayTotal[arrayDir[0]][arrayDir[1]-i]+=1;

                }

                arrayDir[1]-=step;

            }

        }

        

    }

没有评论:

发表评论