| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 443 人关注过本帖
标题:求助大神,帮我把推箱子这个程序代码写完整来,代码不够完善,箱子推不上去 ...
只看楼主 加入收藏
yhg206
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2012-12-10
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求助大神,帮我把推箱子这个程序代码写完整来,代码不够完善,箱子推不上去呀?????
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int i,j;
void MAP(int map[10][10]);
int main()
{
    char input;   
    int point=0;
    int map[10][10] = {   
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,1,0,0,0},
{0,0,0,1,3,3,1,0,0,0},
{0,0,1,1,2,3,1,1,0,0},
{0,0,1,2,4,4,3,1,0,0},
{0,1,1,2,2,2,2,1,1,0},
{0,1,2,2,1,4,4,2,1,0},
{0,1,2,2,2,6,2,2,1,0},
{0,1,1,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0},
    };
       while (1)
    {
        system("CLS");
        MAP(map);
        
        //找到初始位置
        for (i=0;i<10;i++)
        {
            for (j=0;j<10;j++)
            {
                if (map[i][j]==6)
                    break;
            }
            if (map[i][j]==6)  
                break;
        }
               
        input = getch();
        switch (input)
        {case 72://上移
            if(map[i-1][j]==2)
            {
                map[i][j]=2;
                map[i-1][j]=6;
               
            }
            if(map[i-1][j]==4)
            {
                if (map[i-2][j]==2)
                {
                    map[i][j]=2;
                    map[i-1][j]=6;
                    map[i-2][j]=4;
                }
                 if (map[i-2][j]==3)
                {
                    map[i][j]=2;
                    map[i-1][j]=6;
                    map[i-2][j]=5;
                     point++;  
                    }
             }
        
            break;
        case 80://下移
            if(map[i+1][j]==2)
            {
                map[i][j]=2;
                map[i+1][j]=6;
               
            }
            else if(map[i+1][j]==4)
            {
                if (map[i+2][j]==2)
                {
                    map[i][j]=2;
                    map[i+1][j]=6;
                    map[i+2][j]=4;
                }
                else if (map[i+2][j]==3)
                {
                    map[i][j]=2;
                    map[i+1][j]=6;
                    map[i+2][j]=5;
                    point++;     
                }
               
            }
            break;
        case 75://左移
            if(map[i][j-1]==2)
            {
                map[i][j]=2;
                map[i][j-1]=6;
               
            }
            else if(map[i][j-1]==4)
            {
                if (map[i][j-2]==2)
                {
                    map[i][j]=2;
                    map[i][j-1]=6;
                    map[i][j-2]=4;
                }
                else if (map[i][j-2]==3)
                {
                    map[i][j]=2;
                    map[i][j-1]=6;
                    map[i][j-2]=5;
                    point++;   
                }
            }            
            break;
        case 77://右移
            if(map[i][j+1]==2)
            {
                map[i][j]=2;
                map[i][j+1]=6;
               
            }
            else if(map[i][j+1]==4)
            {
                if (map[i][j+2]==2)
                {
                    map[i][j]=2;
                    map[i][j+1]=6;
                    map[i][j+2]=4;
                }
                else if (map[i][j+2]==3)
                {
                    map[i][j]=2;
                    map[i][j+1]=6;
                    map[i][j+2]=5;
                    point++;     
                }                                
            }
            break;
        }


        if (point==4)
        {
        system("CLS");
        MAP(map);
        break;
        }
            
    }
    printf("\n恭喜通关!\n");
    return 0;
}
void MAP(int map[10][10])
{
            
                for(i=0;i<10;i++)
                {
                    for(j=0;j<10;j++)
                    {
                        switch(map[i][j])
                        {
                        case 0:
                            printf("  ");
                            break;
                        case 1:
                            printf("■");
                            break;
                        case 2:
                            printf("  ");
                            break;
                        case 3:
                            printf("×");
                            break;
                        case 4:
                            printf("◎");
                            break;
                        case 5:
                            printf("☆");
                            break;
                        case 6:
                            printf("♂");
                            break;
                        }            
                    }
                    printf("\n");
                }
}
搜索更多相关主题的帖子: 推箱子 include system 
2012-12-10 10:52
blueangel
Rank: 2
等 级:论坛游民
帖 子:1
专家分:20
注 册:2012-12-12
收藏
得分:20 
我试了下,你把input的值该成单个数字或字母(因为getch的用法好像),case后面因为input是char型要加引号。
改成 case ‘u’://上移


类似这样改就能用了
2012-12-12 22:03
快速回复:求助大神,帮我把推箱子这个程序代码写完整来,代码不够完善,箱子推不 ...
数据加载中...
 
   



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

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