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

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("\n请输入要走的方向并按回车确认(w,s,a,d一次代表上下左右:)");
}

/*int isOK(int m, int n)
{

}*/
void main()
{
    int    b[M][N] =
    {
        {2,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,3,3},
        {0,3,1,0,0,3,0,0,1,0,3,0,1,0,3},
        {1,0,0,3,0,1,3,1,0,3,0,1,3,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,3,0,1,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
        {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
    };
    int m=0,n=0,h;
    char w,s,a,d,ch;
        dayin(b);
    while(1)
        {
        scanf("%c",&ch);

        switch(ch)
        {
        case 'w':
         m=m-1;
          n=n;
          h=b[m][n];
        if(m<0||n<0||n>15)
        {
            b[0][0]=0;
            printf("\n你死了\n");
        }
        else if(h==0)
        {
            b[m+1][n]=0;
            b[m][m]=2;
        }
        else if(h==1)
        {
            b[m+1][n]=0;
            b[m][m]=2;
        }
        else if(h==3)
        {
            system("cls");
            printf("\n你死了\n");
        }
            break;
        case 's':
            m=m+1;
            n=n;
            h=b[m][n];
        if(m>15||n<0||n>15)
        {
            b[0][0]=0;
            printf("\n你死了\n");
        }
        else if(h==0)
        {
            b[m-1][n]=0;
             b[m][n]=2;
        }
        else if(h==1)
        {
            b[m-1][n]=0;
            b[m][n]=2;
        }
        else if(h==3)
        printf("\n你死了\n");
            break;
        case 'a':
            m=m;
            n=n-1;
            h=b[m][n];
         if(n<0||m<0||m>15)
         {
             b[0][0]=0;
         printf("\n你死了\n");
         }
         else if(h==0)
         {
            b[m][n+1]=0;
            b[m][n]=2;
         }
         else if(h==1)
         {
            b[m][n+1]=0;
            b[m][n]=2;
         }
         else if(h==3)
         {
            system("cls");
            printf("\n你死了\n");
         }
            break;
        case 'd':
            m=m;
            n=n+1;
            h=b[m][n];
         if(n>15||m<0||m>15)
         {
             b[0][0]=0;
         printf("\n你死了\n");
         }
         else if(h==0)
         {
            b[m][n-1]=0;
            b[m][n]=2;
         }
         else if(h==1)
         {
            b[m][n-1]=0;
            b[m][n]=2;
         }
         else if(h==3)
         {
           system("cls");
           printf("\n你死了\n");
         }
            break;
            
        }
    }getch();
}



我实现不了哪错了      我想实现在一个界面上移动     指点下
搜索更多相关主题的帖子: include 贪吃蛇 
2012-10-24 12:56
feiei
Rank: 2
来 自:河北省石家庄
等 级:论坛游民
帖 子:41
专家分:37
注 册:2012-9-15
收藏
得分:0 
没有知道的吗

小白初来。求各种罩。。。。
2012-10-24 16:36
feiei
Rank: 2
来 自:河北省石家庄
等 级:论坛游民
帖 子:41
专家分:37
注 册:2012-9-15
收藏
得分:0 
最新 修改 代码
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define M 15
#define N 15

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("\n请输入要走的方向并按回车确认(w,s,a,d一次代表上下左右:):\n");
}

/*int isOK(int m, int n)
{

}*/
void main()
{
    int    b[M][N] =
    {
        {2,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,3,3},
        {0,3,1,0,0,3,0,0,1,0,3,0,1,0,3},
        {1,0,0,3,0,1,3,1,0,3,0,1,3,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,3,0,1,3},
        {1,0,0,3,0,1,3,1,0,3,1,0,0,1,3},
        {0,3,1,0,0,3,0,0,1,0,0,1,3,1,3},
        {0,1,0,0,3,0,0,1,0,3,3,1,0,0,3},
        {3,0,3,0,1,0,3,1,0,1,3,3,1,0,3},
        {0,1,0,0,3,0,0,1,0,3,0,1,3,1,3},
        {3,3,3,3,3,3,3,3,3,3,3,3,3,3,3}
    };
    int m=0,n=0,h;
    char w,s,a,d,ch;
    while(1)
    {
        dayin(b);
        scanf("%c",&ch);
        switch(ch)
        {
        case 'w':
          m=m-1;
          n=n;
          h=b[m][n];
        if(m<0||n<0||n>15)
        {
            b[0][0]=0;
            printf("\n你死了\n");
        }
        else if(h==0)
        {
            b[m+1][n]=0;
            b[m][m]=2;
        }
        else if(h==1)
        {
            b[m+1][n]=0;
            b[m][m]=2;
        }
        else if(h==3)
        {
            printf("\n你死了\n");
        }
            break;
        case 's':
            m=m+1;
            n=n;
            h=b[m][n];
        if(m>15||n<0||n>15)
        {
            b[0][0]=0;
            printf("\n你死了\n");
        }
        else if(h==0)
        {
            b[m-1][n]=0;
             b[m][n]=2;
        }
        else if(h==1)
        {
            b[m-1][n]=0;
            b[m][n]=2;
        }
        else if(h==3)
        printf("\n你死了\n");
            break;
        case 'a':
            m=m;
            n=n-1;
            h=b[m][n];
         if(n<0||m<0||m>15)
         {
             b[0][0]=0;
         printf("\n你死了\n");
         }
         else if(h==0)
         {
            b[m][n+1]=0;
            b[m][n]=2;
         }
         else if(h==1)
         {
            b[m][n+1]=0;
            b[m][n]=2;
         }
         else if(h==3)
         {
            printf("\n你死了\n");
         }
            break;
        case 'd':
            m=m;
            n=n+1;
            h=b[m][n];
         if(n>15||m<0||m>15)
         {
             b[0][0]=0;
         printf("\n你死了\n");
         }
         else if(h==0)
         {
            b[m][n-1]=0;
            b[m][n]=2;
         }
         else if(h==1)
         {
            b[m][n-1]=0;
            b[m][n]=2;
         }
         else if(h==3)
         {
           printf("\n你死了\n");
         }
            break;
        
        }
    }

}

小白初来。求各种罩。。。。
2012-10-24 16:46
快速回复:类似贪吃蛇的问题 求指导
数据加载中...
 
   



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

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