| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 433 人关注过本帖
标题:谁有某一个游戏的代码?我试试在 vs2013 运行一下
只看楼主 加入收藏
wangjiang624
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-3
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:4 
谁有某一个游戏的代码?我试试在 vs2013 运行一下
表示还没运行过小游戏,想试试
搜索更多相关主题的帖子: 小游戏 
2014-11-16 18:43
wangjiang624
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2014-11-3
收藏
得分:0 
回复 楼主 wangjiang624
用c编的哦
2014-11-16 18:43
黑漆漆
Rank: 2
等 级:论坛游民
帖 子:31
专家分:48
注 册:2014-11-4
收藏
得分:10 
推箱子

[ 本帖最后由 黑漆漆 于 2014-11-17 20:06 编辑 ]
2014-11-17 20:04
黑漆漆
Rank: 2
等 级:论坛游民
帖 子:31
专家分:48
注 册:2014-11-4
收藏
得分:0 
推箱子

[ 本帖最后由 黑漆漆 于 2014-11-17 20:06 编辑 ]
2014-11-17 20:04
黑漆漆
Rank: 2
等 级:论坛游民
帖 子:31
专家分:48
注 册:2014-11-4
收藏
得分:0 
...........重新来
#include <stdio.h>
#include <bios.h>
#include <conio.h>

typedef int bios.h;

#define ESC   0x011b
#define UP    0x4800
#define DOWN  0x5000
#define LEFT  0x4b00
#define RIGHT 0x4d00

#define MAXSIZE 10

typedef struct
{
    int x;
    int y;
}point;

point des[MAXSIZE];

char map[10][10] =
{
    "        ",
    "    ####",
    "  ### @#",
    "  #  b #",
    " ## # ###",
    " #  # #*#",
    " # #  b*#",
    " # b   *#",
    " ########",
    "         "
};

void DrawMan(int x, int y)
{
    gotoxy(x+10, y+5);
    textcolor(YELLOW);
    putch(2);
    printf('\b');
}

void DrawSpace(int x, int y)
{
    gotoxy(x+10, y+5);
    printf(" ");
}

void DrawBox(int x, int y)
{
    gotoxy(x+10, y+5);
    textcolor(CYAN);
    putch('@');
}

void DrawDes(int x, int y)
{
    gotoxy(x+10, y+5);
    textcolor(YELLOW);
    putch('*');
}

void DrawBoxIn(int x, int y)
{
    gotoxy(x+10, y+5);
    textcolor(YELLOW);
    putch('@');
}

void DrawMap(point *pman)
{
    int x = 0, y = 0;
    int i = 0;
    for (; y < 10; ++y)
    {
        for (x=0; x < 10; ++x)
        {
            if (map[y][x] == '#')
            {
                textcolor(GREEN);
                gotoxy(x+10, y+5);
                putch(219);
            }
            else if (map[y][x] == '*')
            {
                DrawDes(x, y);
                des[i].x = x;
                des[i].y = y;
                ++i;
            }
            else if (map[y][x] == '@')
            {
                pman->x = x;
                pman->y = y;
                DrawMan(x, y);
                map[y][x] = ' ';
            }
            else if (map[y][x] == 'b')
            {
                DrawBox(x, y);
            }
            else if (map[y][x] == 'i')
            {
                DrawBoxIn(x, y);
                des[i].x = x;
                des[i].y = y;
                ++i;
            }
            des[i].x = -1;
        }
        gotoxy(48, 6);
        printf("Welcome to come to BoxMan!!");
        gotoxy(48, 8);
        printf("Press direct key to move the man!");
        gotoxy(48, 10);
        printf("Press ESC to quit the game!");
        gotoxy(48, 12);
        printf("Enjoy yourself in this game!");
        gotoxy(36, 2);
        textcolor(RED);
        putch('B');
        putch('o');
        putch('x');
        putch('M');
        putch('a');
        putch('n');
    }
}

int main()
{
    point man = {1, 1};
    int key = 0;
    int i = 0, count = 0;
    clrscr();
    DrawMap(&man);

    while (key != ESC)
    {
        while (bioskey(1) == 0);
        key = bioskey(0);

        switch (key)
        {
        case UP:
            if (map[man.y - 1][man.x] == '#')
            {
                break;
            }
            else if (map[man.y - 1][man.x] == 'b' || map[man.y - 1][man.x] == 'i')
            {
                switch (map[man.y - 2][man.x])
                {
                case 'b':
                case '#':
                case 'i':
                    break;
                case ' ':
                    /*move box*/
                    if (map[man.y - 1][man.x] == 'i')
                    {
                        map[man.y - 1][man.x] = '*';
                    }
                    else
                    {
                        map[man.y - 1][man.x] = ' ';
                    }

                    map[man.y - 2][man.x] = 'b';
                    DrawBox(man.x, man.y - 2);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    --man.y;
                    DrawMan(man.x, man.y);
                    break;
                case '*':
                    /*move box in*/
                    if (map[man.y - 1][man.x] == 'i')
                    {
                        map[man.y - 1][man.x] = '*';
                    }
                    else
                    {
                        map[man.y - 1][man.x] = ' ';
                    }

                    map[man.y - 2][man.x] = 'i';
                    DrawBoxIn(man.x, man.y - 2);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    --man.y;
                    DrawMan(man.x, man.y);
                    break;
                defalut:
                    break;
                }

                break;
            }
            else
            {
                if (map[man.y][man.x] == '*')
                {
                    DrawDes(man.x, man.y);
                }
                else
                {
                    DrawSpace(man.x, man.y);
                }

                --man.y;
                DrawMan(man.x, man.y);
                break;
            }

        case DOWN:
            if (map[man.y + 1][man.x] == '#')
            {
                break;
            }
            else if (map[man.y + 1][man.x] == 'b' || map[man.y + 1][man.x] == 'i')
            {
                switch (map[man.y + 2][man.x])
                {
                case 'b':
                case '#':
                case 'i':
                    break;
                case ' ':
                    /*move box*/
                    if (map[man.y + 1][man.x] == 'i')
                    {
                        map[man.y + 1][man.x] = '*';
                    }
                    else
                    {
                        map[man.y + 1][man.x] = ' ';
                    }

                    map[man.y + 2][man.x] = 'b';
                    DrawBox(man.x, man.y + 2);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    ++man.y;
                    DrawMan(man.x, man.y);
                    break;
                case '*':
                    /*move box in*/
                    if (map[man.y + 1][man.x] == 'i')
                    {
                        map[man.y + 1][man.x] = '*';
                    }
                    else
                    {
                        map[man.y + 1][man.x] = ' ';
                    }

                    map[man.y + 2][man.x] = 'i';
                    DrawBoxIn(man.x, man.y + 2);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    ++man.y;
                    DrawMan(man.x, man.y);
                    break;
                default:
                    break;
                }

                break;
            }
            else
            {
                if (map[man.y][man.x] == '*')
                {
                    DrawDes(man.x, man.y);
                }
                else
                {
                    DrawSpace(man.x, man.y);
                }

                ++man.y;
                DrawMan(man.x, man.y);
                break;
            }
        case LEFT:
            if (map[man.y][man.x - 1] == '#')
            {
                break;
            }
            else if (map[man.y][man.x - 1] == 'b' || map[man.y][man.x - 1] == 'i')
            {
                switch (map[man.y][man.x - 2])
                {
                case 'b':
                case '#':
                case 'i':
                    break;
                case ' ':
                    /*move box*/
                    if (map[man.y][man.x - 1] == 'i')
                    {
                        map[man.y][man.x - 1] = '*';
                    }
                    else
                    {
                        map[man.y][man.x - 1] = ' ';
                    }

                    map[man.y][man.x - 2] = 'b';
                    DrawBox(man.x - 2, man.y);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    --man.x;
                    DrawMan(man.x, man.y);
                    break;
                case '*':
                    /*move box in*/
                    if (map[man.y][man.x - 1] == 'i')
                    {
                        map[man.y][man.x - 1] = '*';
                    }
                    else
                    {
                        map[man.y][man.x - 1] = ' ';
                    }

                    map[man.y][man.x - 2] = 'i';
                    DrawBoxIn(man.x - 2, man.y);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    --man.x;
                    DrawMan(man.x, man.y);
                    break;
                default:
                    break;
                }

                break;
            }
            else
            {
                if (map[man.y][man.x] == '*')
                {
                    DrawDes(man.x, man.y);
                }
                else
                {
                    DrawSpace(man.x, man.y);
                }
                --man.x;
                DrawMan(man.x, man.y);
                break;
            }
        case RIGHT:
            if (map[man.y][man.x + 1] == '#')
            {
                break;
            }
            else if (map[man.y][man.x + 1] == 'b' || map[man.y][man.x + 1] == 'i')
            {
                switch (map[man.y][man.x + 2])
                {
                case 'b':
                case '#':
                case 'i':
                    break;
                case ' ':
                    /*move box*/
                    if (map[man.y][man.x + 1] == 'i')
                    {
                        map[man.y][man.x + 1] = '*';
                    }
                    else
                    {
                        map[man.y][man.x + 1] = ' ';
                    }

                    map[man.y][man.x + 2] = 'b';
                    DrawBox(man.x + 2, man.y);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    ++man.x;
                    DrawMan(man.x, man.y);
                    break;
                case '*':
                    /*move box in*/
                    if (map[man.y][man.x + 1] == 'i')
                    {
                        map[man.y][man.x + 1] = '*';
                    }
                    else
                    {
                        map[man.y][man.x + 1] = ' ';
                    }

                    map[man.y][man.x + 2] = 'i';
                    DrawBoxIn(man.x + 2, man.y);


                    if (map[man.y][man.x] == '*')
                    {
                        DrawDes(man.x, man.y);
                    }
                    else
                    {
                        DrawSpace(man.x, man.y);
                    }

                    ++man.x;
                    DrawMan(man.x, man.y);
                    break;
                default:
                    break;
                }

                break;
            }
            else
            {
                if (map[man.y][man.x] == '*')
                {
                    DrawDes(man.x, man.y);
                }
                else
                {
                    DrawSpace(man.x, man.y);
                }
                DrawSpace(man.x, man.y);
                ++man.x;
                DrawMan(man.x, man.y);
                break;
            }
        defualt:
            break;
        }

        for (i=0, count=0; des[i].x != -1; ++i)
        {
            if (map[des[i].y][des[i].x] == '*')
            {
                ++count;
            }
        }
        if (count == 0)
        {
            gotoxy(35, 3);
            printf("Ok! you win!");
            getch();
            key = ESC;
        }
    }

    return 0;
}
2014-11-17 20:06
快速回复:谁有某一个游戏的代码?我试试在 vs2013 运行一下
数据加载中...
 
   



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

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