| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 381 人关注过本帖, 1 人收藏
标题:求解一个循环问题
取消只看楼主 加入收藏
feiei
Rank: 2
来 自:河北省石家庄
等 级:论坛游民
帖 子:41
专家分:37
注 册:2012-9-15
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:0 
求解一个循环问题
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define M 23
#define N 39
#define B 0

 int sta = 1;

void dayin(int b[M][N])
{
    int i,j;
    for(i = 0;i < M;i++)
    {
        for(j = 0; j < N; j++)
        {
            switch(b[i][j])
            {
            case 0: printf("  "); break;
            case 1: printf(" o"); break;
            case 2: printf(" $"); break;
            case 3: printf(" |"); break;
            }
        }
        printf("\n");
    }
    printf("请输入要走的方向并按回车键确认(w,s,a,d一次代表上下左右:):\n");
}

void main()
{
    int o=0,p;
    char kg;
    printf("\n\n\n\n\n\n\t\t&^这是我做的第一个小游戏希望大家多多指导^&\n");
    printf("\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t作者:崔浚飞\n");
    printf("\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t    准备好了吗!  准备好了按数字0开始!\n");\
    printf("\n\n\n你输入的是(回车键确认):");
    start:
    scanf("%d",&p);
    if(p!=0)
    {
        printf("出错啦亲~~\n要开始要输入“0”数字哦\n");
        goto start;
        system("pause");
        
    }
    else
    {
    system("cls");
    printf("\n\t\t\t\t@游戏帮助@\n");
    printf("\n\t\t\t$这个代表小蛇,即你的操作对象!\n");
    printf("\n\t\t\to这个代表老鼠,即你的捕捉目标!\n");
    printf("\n\t\t\t|这个代表墙壁,即你的行进障碍!\n");
    printf("\n\t请用w,s,a,d来控制上下左右。并且依次输入用回车键进行确认!\n");
    printf("\n\t\t特别提醒请注意墙壁哦!会死的哦!祝你玩得开心!\n");
    printf("\n\n\t\t*****************************************\n");
    printf("\t\t*\t\t\t\t\t*\n");
    printf("\t\t*\t\t版权所有\t\t*\n");
    printf("\t\t*\t\t翻版必究\t\t*\n");
    printf("\t\t*  QQ:253135364         tel:18396835746\t*\n");
    printf("\t\t*****************************************\n");
    printf("\n\n\t\t\t\t\t\t\t\t崔浚飞\n\t\t\t\t\t\t\t\t2012年10月25日\n");
    system("pause");
    system("cls");
    if(o==p)
    {
    int    b[M][N] =
    {
        {2,0,0,3,0,1,3,1,0,3,1,0,0,1,0,1,3,0,0,3,1,0,3,1,0,3,0,1,3,1,0,3,1,0,0,1,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,1,3,1,3,1,0,3,1,3,1,3,0,1,0,3,1,0,1,3,3,1,0,3,3,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,0,0,1,0,3,3,1,0,0,1,0,0,3,0,0,1,0,3,0,1,0,3,0,1,0},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3,1,3,3,1,0,3,3,3,1,3,0,1,3,1,0,3,0,1,3,1,0,1,0,0},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,0,0,1,0,3,3,1,0,1,1,1,3,0,1,3,1,3,1,3,0,3,1,0,0,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,3,1,3,3,3,1,3,3,0,3,1,0,0,3,0,0,1,0,0,1,3,1,1,0,3,1},
        {0,3,1,0,0,3,0,0,1,0,3,0,1,0,3,0,1,0,3,0,1,1,0,1,1,0,3,3,1,0,0,1,0,0,3,0,0,3,1},
        {1,0,0,3,0,1,3,1,0,3,0,1,3,1,0,1,3,3,1,3,3,0,3,1,0,3,3,1,0,1,1,1,3,0,1,3,1,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,3,0,1,3,0,1,0,3,3,1,3,3,1,1,0,0,3,1,3,3,3,1,3,3,0,3,0,0},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,1,0,3,3,3,1,0,3,0,0,1,0,3,1,3,3,3,1,3,3,0,3,1,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,1,0,1,0,3,0,1,3,3,1,1,0,3,3,1,0,0,0,1,3,3,1,3,3,0},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,0,1,3,3,1,3,3,0,0,1,0,3,1,3,3,3,1,3,3,0,3,1,0,3,1},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3,0,1,0,3,0,1,1,3,1,1,3,3,1,0,3,1,3,3,1,0,3,3,1,1},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,0,3,3,3,1,3,3,0,1,1,1,0,3,3,1,0,0,0,1,3,3,1,3,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,1,3,1,3,1,0,3,1,3,1,3,0,1,0,3,1,0,1,3,3,1,0,3,3,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,0,0,1,0,3,3,1,0,0,1,0,0,3,0,0,1,0,3,0,1,0,3,0,1,0},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3,1,3,3,1,0,3,3,3,1,3,0,1,3,1,0,3,0,1,3,1,0,1,0,0},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,0,0,1,0,3,3,1,0,1,1,1,3,0,1,3,1,3,1,3,0,3,1,0,0,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,3,1,3,3,3,1,3,3,0,3,1,0,0,3,0,0,1,0,0,1,3,1,1,0,3,1},
        {0,3,1,0,0,3,0,0,1,0,3,0,1,0,3,0,1,0,3,0,1,1,0,1,1,0,3,3,1,0,0,1,0,0,3,0,0,3,1},
        {1,0,0,3,0,1,3,1,0,3,0,1,3,1,0,1,3,3,1,3,3,0,3,1,0,3,3,1,0,1,1,1,3,0,1,3,1,1,3},
        {3,1,3,1,3,0,1,3,1,3,1,3,0,3,1,0,1,0,1,0,1,0,3,1,1,3,3,1,0,3,1,3,3,1,0,3,3,0,1}
    };
   
    int m=0,n=0,h,f=0,z=10;
    char w,s,a,d,ch;
     //ok:
    do
    {
    while(sta)
    {   dayin(b);
        fflush(stdin);
        scanf("%c",&ch);
        switch(ch)
        {
        case 'w':
                  m=m-1;
                  n=n;
                  h=b[m][n];
                if(m<B)
                {
                    b[0][0]=2;
                    sta = 0;
                }
                else if(h==0)
                {
                    b[m][n]=2;
                    b[m+1][n]=0;
                }
                else if(h==1)
                {
                    b[m][n]=2;
                    b[m+1][n]=0;
                }
                else if(h==3)
                {
                    sta = 0;
                }
                    break;
        case 's':
                m=m+1;
                n=n;
                h=b[m][n];
            if(m>M)
            {
                b[0][0]=2;
                sta = 0;
            }
            else if(h==0)
            {
               
                 b[m][n]=2;
                 b[m-1][n]=0;
                 f=f+z;
            }
            else if(h==1)
            {
            
                b[m][n]=2;
                b[m-1][n]=0;
            }
            else if(h==3)
            {
                sta = 0;
            }
                break;
        case 'a':
                m=m;
                n=n-1;
                h=b[m][n];
             if(n<B)
             {
                 b[0][0]=2;
                sta = 0;
             }
             else if(h==0)
             {
                b[m][n+1]=0;
                b[m][n]=2;
                f=f+z;
             }
             else if(h==1)
             {
                b[m][n+1]=0;
                b[m][n]=2;
             }
             else if(h==3)
             {
                sta = 0;
             }
                break;
        case 'd':
                m=m;
                n=n+1;
                h=b[m][n];
             if(n>N)
             {
                 b[0][0]=0;
             sta = 0;
             }
             else if(h==0)
             {
                b[m][n-1]=0;
                b[m][n]=2;
                f=f+z;
             }
             else if(h==1)
             {
                b[m][n-1]=0;
                b[m][n]=2;
             }
             else if(h==3)
             {
               sta = 0;
             }
                break;
        default:
                printf("输入错误!\n请真确输入w,s,a,d\n");
                system("pause");
          }   
          system("cls");
         
       }
     printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t你死的好惨!\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
     system("pause");
     system("cls");
     printf("\n\n\t\t\t真不小心你死了重新在玩吧!哈哈哈\n");
    // printf("\n\t\t\t\t 由于作者比较懒!\n\t\t\t\t暂时没有实现循环!\n\t\t\t\t   尽请期待!\n\t\t\t  现在关闭重新打开吧!嘎嘎");
     printf("\n\n\t如有任何意见或建议请与我联系QQ:253135364   tel:18396835746");
    // printf("\n\n\n\t\t\t     游戏结束按任意键退出\n");
     printf("\n\n\n\n\n\n");
     printf("请输入是否继续(y/n):");
     fflush(stdin);
     scanf("%c",&kg);
     //if(kg=='y'||'Y')
      //goto ok;
    }while(kg=='y'||'Y');
    }

}
}





为什么我的循环不是从do那开始的   而是循环   你死了  这里
求解 ‘
同样用goto语句也是同样


求指导
搜索更多相关主题的帖子: include void 
2012-10-29 00:50
快速回复:求解一个循环问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved