| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3138 人关注过本帖, 3 人收藏
标题:分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
取消只看楼主 加入收藏
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
结帖率:83.33%
收藏(3)
已结贴  问题点数:20 回复次数:1 
分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
#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,0,0,0,0},
        {0,0,0,1,3,1,0,0,0,0},
        {0,0,0,1,2,1,1,1,1,0},
        {0,1,1,1,4,4,2,3,1,0},
        {0,1,3,2,4,6,1,1,1,0},
        {0,1,1,1,1,4,1,0,0,0},
        {0,0,0,0,1,3,1,0,0,0},
        {0,0,0,0,1,1,1,0,0,0},
        {0,0,0,0,0,0,0,0,0,0},
    };
       while (true)
    {
        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;
        }
        printf("确认找到%d  %d",i,j);        
        input = getch();
        switch (input)
        {case 'w':
            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 's':
            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 'a':
            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 'd':
            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恭喜通关!");
    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");
                }
}
由于没学图形,所以那几个图标是复制过来的!
收到的鲜花
  • 广陵绝唱2009-12-25 13:54 送鲜花  49朵   附言:good
  • Devil_W2009-12-31 13:05 送鲜花  -1朵  
搜索更多相关主题的帖子: 箱子 童鞋 分享 
2009-12-25 13:14
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
收藏
得分:0 
回复 3楼 zhanfffmmm
那就while(1)吧!!!这个是11月份上数组的时候写的!本人初学者呢,现在于指针的苦海中!努力中......大虾别见笑啊!

[ 本帖最后由 jcslt 于 2009-12-25 17:18 编辑 ]

www.
2009-12-25 17:17
快速回复:分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
数据加载中...
 
   



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

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