| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3138 人关注过本帖, 3 人收藏
标题:分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
只看楼主 加入收藏
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
结帖率:83.33%
收藏(3)
已结贴  问题点数:20 回复次数:17 
分享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
flyue
Rank: 10Rank: 10Rank: 10
来 自:江南西道
等 级:贵宾
威 望:19
帖 子:3465
专家分:1563
注 册:2006-6-20
收藏
得分:15 
建立楼主不要一条main写到底, 应当分开为几个函数(模块)

坚持"高内聚, 低耦合", 同时把代码易读性清晰性作为写程序的第一原则

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

天之道,损有余而补不足.人之道则不然,损不足以奉有余.孰能有余以奉天下,唯有道者.
2009-12-25 15:16
zhanfffmmm
Rank: 5Rank: 5
等 级:职业侠客
帖 子:238
专家分:343
注 册:2009-10-16
收藏
得分:2 
未定义true?
2009-12-25 15:36
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
longlong89
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:广州
等 级:小飞侠
威 望:6
帖 子:1043
专家分:2754
注 册:2009-8-18
收藏
得分:2 
不管怎么样,顶一下。。。

想象力征服世界
2009-12-25 19:36
混沌之灵
Rank: 2
等 级:论坛游民
帖 子:31
专家分:18
注 册:2008-12-19
收藏
得分:1 
试下吧


2009-12-27 00:46
lpf12034
Rank: 2
等 级:论坛游民
帖 子:15
专家分:52
注 册:2009-7-13
收藏
得分:0 
好难
2009-12-29 11:24
zhangwai
Rank: 1
等 级:新手上路
帖 子:23
专家分:2
注 册:2010-1-6
收藏
得分:0 
错误太多咯
2010-01-06 14:40
Alar30
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:10
帖 子:988
专家分:1627
注 册:2009-9-8
收藏
得分:0 
再写个扫雷吧
2010-01-06 15:34
BlueGuy
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:29
帖 子:4476
专家分:4055
注 册:2009-4-18
收藏
得分:0 
回复 楼主 jcslt
还不错啊, 学习学习

我就是真命天子,顺我者生,逆我者死!
2010-01-08 21:51
快速回复:分享VC下无聊的推箱子!给09的童鞋参考,给我加分也不介意的
数据加载中...
 
   



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

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