精华内容
下载资源
问答
  • 推箱子游戏 C语言

    2021-01-25 21:47:56
    //0:空地,1:墻,3:目的地,4:箱子,5:人 int Maps[][16][16] = { { {0,0,1,1,1,0,0,0},{0,0,1,3,1,0,0,0},{0,0,1,0,1,1,1,1},{1,1,1,4,0,4,3,1}, {1,3,0,4,5,1,1,1},{1,1,1,1,4,1,0,0},{0,0,0,1,3,1,0,0},{0,0,0,1,1,1...
    #pragma once
    
    #define A 2
    #define B 6
    #define C 5
    
    typedef struct
    {
        int x, y;
    }Point;
    Point point[] = 
    { 
        {8,8},{9,9},{7,10},{8,6},{8,8},{11,13},{8,10},{7,10},{9,11},{8,7},{6,12},{7,8},{13,10},{7,8},{7,8},{9,10},{7,9},{9,10},
        {8,10},{8,7},{8,11},{9,9},{8,10},{9,14},{10,11},{12,13},{12,15},{13,16},{7,9},{7,12},{8,9},{8,8},{12,14},{13,15},{10,10},
        {12,15},{8,9},{12,12},{10,11},{7,7}
    };
    
    //0:空地,1:墻,3:目的地,4:箱子,5:人
    int Maps[][16][16] =
    {
        {
           {0,0,1,1,1,0,0,0},{0,0,1,3,1,0,0,0},{0,0,1,0,1,1,1,1},{1,1,1,4,0,4,3,1},
           {1,3,0,4,5,1,1,1},{1,1,1,1,4,1,0,0},{0,0,0,1,3,1,0,0},{0,0,0,1,1,1,0,0}
        },
        {
            {1,1,1,1,1,0,0,0,0},{1,0,0,0,1,0,0,0,0},{1,0,4,4,1,0,1,1,1},{1,5,4,0,1,0,1,3,1},
            {1,1,1,0,1,1,1,3,1},{0,1,1,0,0,0,0,3,1},{0,1,0,0,0,1,0,0,1},{0,1,0,0,0,1,1,1,1},{0,1,1,1,1,1,0,0,0}
        },
        {
            {0,1,1,1,1,1,1,1,0,0},{0,1,0,0,0,0,0,1,1,1},{1,1,4,1,1,1,0,0,0,1},{1,5,0,0,4,0,0,4,0,1},
            {1,0,3,3,1,0,4,0,1,1},{1,1,3,3,1,0,0,0,1,0},{0,1,1,1,1,1,1,1,1,0}
        },
        {
            {0,1,1,1,1,0},{1,1,0,0,1,0},{1,5,0,4,1,0},{1,1,0,0,1,1},{1,1,4,4,0,1},{1,3,4,0,0,1},
            {1,3,3,7,3,1},{1,1,1,1,1,1}
        },
        {
            {0,1,1,1,1,1,0,0},{0,1,0,5,1,1,1,0},{0,1,0,4,0,0,1,0},{1,1,1,0,1,0,1,1},{1,3,1,0,1,0,0,1},
            {1,3,4,0,0,1,0,1},{1,3,0,0,0,4,0,1},{1,1,1,1,1,1,1,1}
        },
        {
            {0,0,0,1,1,1,1,1,1,1,0,0,0},{1,1,1,1,0,0,0,0,0,1,0,0,0},{1,0,0,0,3,1,1,1,0,1,0,0,0},
            {1,0,1,0,1,0,0,0,0,1,1,0,0},{1,0,1,0,4,0,4,1,3,0,1,0,0},{1,0,1,0,0,7,0,0,1,0,1,0,0},{1,0,3,1,4,0,4,0,1,0,1,0,0},
            {1,1,0,0,0,0,1,0,1,0,1,1,1},{0,1,0,1,1,1,3,0,0,0,0,5,1},{0,1,0,0,0,0,0,1,1,0,0,0,1},{0,1,1,1,1,1,1,1,1,1,1,1,1}
        },
        {
            {0,0,0,1,1,1,1,1,1,1},{0,0,1,1,0,0,1,0,5,1},{0,0,1,0,0,0,1,4,0,1},{0,0,1,4,0,0,4,0,0,1},
            {0,0,1,0,4,1,1,0,0,1},{1,1,1,0,4,0,1,0,1,1},{1,3,3,3,3,3,0,0,1,0},{1,1,1,1,1,1,1,1,1,0}
        },
        {
             {0,0,0,1,1,1,1,1,1,0},{0,1,1,1,0,0,0,0,1,0},{1,1,3,0,4,1,1,0,1,1},{1,3,3,4,0,4,0,0,5,1},
             {1,3,3,0,4,0,4,0,1,1},{1,1,1,1,1,1,0,0,1,0},{0,0,0,0,0,1,1,1,1,0}
        },
        {
            {0,1,1,1,1,1,1,1,1,1,0},{0,1,0,0,1,1,0,0,0,1,0},{0,1,0,0,0,4,0,0,0,1,0},{0,1,4,0,1,1,1,0,4,1,0},
            {0,1,0,1,3,3,3,1,0,1,0},{1,1,0,1,3,3,3,1,0,1,1},{1,0,4,0,0,4,0,0,4,0,1},{1,0,0,0,0,0,1,0,0,5,1},{1,1,1,1,1,1,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,1},{1,3,3,4,3,3,1},{1,3,3,1,3,3,1},{1,0,4,4,4,0,1},{1,0,0,4,0,0,1},{1,0,4,4,4,0,1},
            {1,0,0,1,0,5,1},{1,1,1,1,1,1,1}
        },
        {
            {0,1,1,1,1,0,0,1,1,1,1,1},{1,1,0,0,1,0,0,1,0,0,0,1},{1,0,4,0,1,1,1,1,4,0,0,1},{1,0,0,4,3,3,3,3,0,4,0,1},
            {1,1,0,0,0,0,1,0,5,0,1,1},{0,1,1,1,1,1,1,1,1,1,1,0}
        },
        {
            {0,0,1,1,1,1,1,0},{1,1,1,0,0,5,1,0},{1,0,0,4,3,0,1,1},{1,0,0,3,4,3,0,1},{1,1,1,0,7,4,0,1},{0,0,1,0,0,0,1,1},
            {0,0,1,1,1,1,1,0}
        },
        {
            {0,0,1,1,1,1,1,1,1,0},{0,1,1,0,0,0,0,0,1,1},{0,1,0,4,0,0,4,3,0,1},{1,1,0,0,1,1,3,4,0,1},{1,0,0,4,5,1,4,3,0,1},
            {1,0,0,0,1,1,3,4,1,1},{1,1,1,4,1,0,4,3,0,1},{0,1,0,0,3,0,1,1,0,1},{0,1,0,0,0,0,1,0,0,1},{0,1,1,3,0,1,1,0,1,1},{0,0,1,1,3,1,0,0,1,0},
            {0,0,0,1,0,0,0,1,1,0},{0,0,0,1,1,1,1,1,0,0}
        },
        {
            {1,1,1,1,1,1,1,1},{1,0,0,1,0,0,0,1},{1,0,4,3,3,4,0,1},{1,5,4,3,7,0,1,1},{1,0,4,3,3,4,0,1},
            {1,0,0,1,0,0,0,1},{1,1,1,1,1,1,1,1}
        },
        {
            {0,1,1,1,1,1,1,0},{1,1,0,0,0,0,1,1},{1,0,4,0,4,4,0,1},{1,3,3,3,3,3,3,1},{1,0,4,4,0,4,0,1},
            {1,1,1,0,5,1,1,1},{0,0,1,1,1,1,0,0}
        },
        {
            {0,0,1,1,1,1,1,1,1,1},{0,0,1,0,0,0,0,1,1,1},{0,0,1,0,4,0,0,0,0,1},{1,1,1,0,4,0,1,1,0,1},{1,3,3,3,0,4,0,0,0,1},
            {1,3,3,3,4,1,4,0,1,1},{1,1,1,1,0,1,0,4,0,1},{0,0,0,1,0,0,0,5,0,1},{0,0,0,1,1,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,0,0,0},{1,0,0,0,0,1,0,0,0},{1,0,4,4,4,1,1,0,0},{1,0,0,1,3,3,1,1,1},{1,1,0,0,3,3,4,0,1},
            {0,1,0,0,5,0,0,0,1},{0,1,1,1,1,1,1,1,1}
        },
        {
            {0,0,1,1,1,1,1,1,1,1},{0,0,1,0,0,0,1,3,0,1},{0,1,1,0,0,4,3,3,3,1},{0,1,0,0,4,0,1,7,3,1},
            {1,1,0,1,1,4,1,0,1,1},{1,0,0,0,4,0,0,4,0,1},{1,0,0,0,1,0,0,0,0,1},{1,1,1,1,1,1,1,5,0,1},{0,0,0,0,0,0,1,1,1,1}
        },
        {
            {0,1,1,1,1,1,1,1,0,0},{0,1,3,3,3,3,0,1,0,0},{1,1,1,3,3,3,4,1,1,1},{1,0,0,4,1,4,0,4,0,1},
            {1,0,4,4,0,0,1,4,0,1},{1,0,0,0,0,1,0,0,0,1},{1,1,1,1,0,5,0,1,1,1},{0,0,0,1,1,1,1,1,0,0}
        },
        {
            {1,1,1,1,1,1,1},{1,3,3,4,3,3,1},{1,3,3,1,3,3,1},{1,0,4,4,4,0,1},{1,0,0,4,0,0,1},{1,0,4,4,4,0,1},
            {1,0,0,1,5,0,1},{1,1,1,1,1,1,1}
        },
        {
            {0,0,0,1,1,1,1,1,1,0,0},{0,0,0,1,0,3,3,3,1,0,0},{1,1,1,1,3,3,3,3,1,0,0},{1,0,0,1,1,1,4,0,1,1,1},
            {1,0,4,0,4,0,0,4,4,0,1},{1,5,0,4,0,4,0,0,0,0,1},{1,0,0,0,1,1,1,0,0,0,1},{1,1,1,1,1,0,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,1,1,0},{1,0,0,0,0,0,0,1,0},{1,0,1,4,4,0,0,1,0},{1,0,3,3,3,1,0,1,0},{1,1,3,3,3,4,0,1,1},
            {0,1,0,1,1,0,4,0,1},{0,1,4,0,0,4,0,0,1},{0,1,0,0,1,0,0,5,1},{0,1,1,1,1,1,1,1,1}
        },
        {
            {0,0,1,1,1,1,1,0,0,0},{1,1,1,0,0,0,1,1,1,1},{1,0,0,0,4,0,0,4,0,1},{1,0,4,0,5,4,0,0,0,1},{1,1,1,4,4,1,1,1,1,1},
            {0,0,1,0,0,3,3,1,0,0},{0,0,1,3,3,3,3,1,0,0},{0,0,1,1,1,1,1,1,0,0}
        },
        {
            {1,1,1,1,1,1,0,0,0,1,1,1,1,1},{1,0,0,0,0,1,1,1,0,1,0,0,0,1},{1,0,0,4,0,4,0,1,0,1,3,3,3,1},
            {1,0,1,0,0,4,0,1,1,1,0,0,3,1},{1,0,0,4,4,4,0,0,0,4,0,5,3,1},{1,1,1,0,0,4,0,0,4,1,0,0,3,1},{0,0,1,0,0,4,1,4,0,1,3,3,3,1},
            {0,0,1,1,0,0,0,0,0,1,0,0,3,1},{0,0,0,1,1,1,1,1,1,1,1,1,1,1}
        },
        {
            {0,0,0,0,0,1,1,1,1,1,1},{0,1,1,1,1,1,3,0,0,0,1},{0,1,0,0,1,3,3,1,1,0,1},{0,1,0,0,4,3,3,0,0,0,1},
            {0,1,0,0,1,0,3,1,0,1,1},{1,1,1,0,1,1,4,1,0,0,1},{1,0,4,0,0,0,0,4,4,0,1},{1,0,1,4,1,0,0,1,0,0,1},{1,5,0,0,1,1,1,1,1,1,1},
            {1,1,1,1,1,0,0,0,0,0,0}
        },
        {
            {0,1,1,1,1,1,1,1,1,1,0,0,0},{0,1,0,0,0,1,1,0,0,1,1,1,1},{0,1,0,4,0,0,0,0,0,0,0,0,1},{0,1,1,4,1,1,1,0,1,1,0,0,1},
            {0,1,0,0,1,1,0,7,0,1,0,1,1},{0,1,0,4,3,3,3,3,3,3,0,1,0},{1,1,0,1,1,1,0,3,0,1,0,1,0},{1,0,0,0,0,0,4,1,1,1,4,1,0},
            {1,0,0,0,1,0,0,0,0,4,5,1,0},{1,1,1,1,1,4,1,0,1,1,1,1,0},{0,0,0,0,1,0,0,0,1,0,0,0,0},{0,0,0,0,1,1,1,1,1,0,0,0,0}
        },
        {
            {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1},{0,0,0,0,0,0,1,0,0,0,0,0,0,0,1},{0,0,0,0,0,0,1,0,1,0,1,0,1,0,1},
            {0,0,0,0,0,0,1,0,0,4,0,4,1,0,1},{1,1,1,1,1,1,1,0,0,0,4,0,0,0,1},{1,3,3,1,0,0,1,1,0,4,0,4,1,0,1},{1,3,3,0,0,0,1,1,0,4,0,4,0,0,1},
            {1,3,3,1,0,0,1,1,0,1,1,1,1,1,1},{1,3,3,1,0,1,0,4,0,4,0,1,0,0,0},{1,3,3,0,0,0,0,0,4,0,0,1,0,0,0},{1,0,0,1,1,1,5,0,0,1,1,1,0,0,0},
            {1,1,1,1,0,1,1,1,1,1,0,0,0,0,0}
        },
        {
            {0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},{1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0},{1,0,0,4,0,4,0,1,0,1,1,1,1,1,1,1},
            {1,0,0,0,4,0,0,1,0,1,7,3,7,3,7,1},{1,1,0,4,0,4,0,1,1,1,3,7,3,7,3,1},{0,1,4,0,4,0,0,1,0,0,7,3,7,3,7,1},{0,1,5,4,0,4,0,0,0,0,3,7,3,7,1,1},
            {0,1,4,0,4,0,0,1,0,0,7,3,7,3,7,1},{1,1,0,4,0,4,0,1,1,1,3,7,3,7,3,1},{1,0,0,0,4,0,0,1,0,1,7,3,7,3,7,1},
            {1,0,0,4,0,4,0,1,0,1,1,1,1,1,1,1},{1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0},{0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0}
        },
        {
            {1,1,1,1,1,1,1,1,0},{1,3,3,3,3,3,3,1,0},{1,0,0,4,0,1,0,1,1},{1,0,4,0,1,0,4,0,1},{1,1,4,0,4,0,4,0,1},
            {0,1,0,0,5,0,0,0,1},{0,1,1,1,1,1,1,1,1}
        },
        {
            {0,0,1,1,1,1,1,1,1,1,1,1},{1,1,1,0,0,0,3,4,5,0,0,1},{1,0,0,0,1,1,4,1,1,0,0,1},{1,0,0,0,7,0,3,0,3,0,1,1},
            {1,1,0,4,1,1,4,1,1,0,1,0},{0,1,0,0,0,0,3,0,0,0,1,0},{0,1,1,1,1,1,1,1,1,1,1,0}
        },
        {
             {0,0,0,1,1,1,1,1,1},{1,1,1,1,3,0,0,5,1},{1,0,0,4,4,4,0,0,1},{1,3,1,1,3,1,1,3,1},{1,0,0,0,4,0,0,0,1},
             {1,0,0,4,3,1,0,1,1},{1,1,1,1,0,0,0,1,0},{0,0,0,1,1,1,1,1,0}
        },
        {
             {0,1,1,1,1,1,1,0},{0,1,3,0,3,3,1,0},{0,1,3,0,4,3,1,0},{1,1,1,0,0,4,1,1},{1,0,4,0,0,4,0,1},
             {1,0,1,4,1,1,0,1},{1,0,0,0,5,0,0,1},{1,1,1,1,1,1,1,1}
        },
        {
            {0,0,0,0,1,1,1,1,1,1,0,0,0,0},{0,0,1,1,1,0,0,0,0,1,1,1,0,0},{0,0,1,0,0,0,1,4,0,0,0,1,1,1},{0,0,1,0,0,0,4,0,0,0,4,4,0,1},
            {0,0,1,0,4,4,0,1,4,0,0,0,0,1},{0,0,1,1,0,0,0,4,0,0,0,4,0,1},{1,1,1,1,1,1,0,1,4,1,1,1,1,1},{1,3,3,5,0,1,4,0,0,1,0,0,0,0},
            {1,3,1,3,3,0,0,4,1,1,0,0,0,0},{1,3,3,3,3,4,1,0,1,0,0,0,0,0},{1,3,3,3,3,0,0,0,1,0,0,0,0,0},{1,1,1,1,1,1,1,1,1,0,0,0,0,0}
        },
        {
            {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},{1,0,0,0,0,0,0,1,0,0,0,0,0,0,1},{1,0,4,0,1,4,0,1,0,4,1,1,4,0,1},
            {1,0,1,0,0,4,0,1,0,0,0,0,0,0,1},{1,0,0,0,1,1,4,1,4,1,1,4,4,0,1},{1,0,1,0,1,0,3,3,3,0,1,0,0,0,1},{1,0,4,0,0,3,0,1,0,3,4,0,0,0,1},
            {1,0,4,1,5,4,3,3,3,1,0,1,0,0,1},{1,0,0,0,0,3,0,1,0,3,0,0,4,0,1},{1,0,1,1,3,4,1,1,1,4,3,0,1,0,1},{1,0,1,0,4,3,3,3,3,3,0,1,1,0,1},
            {1,0,0,0,0,0,0,0,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,1,1,1,0},{1,0,0,0,1,1,0,0,1,0},{1,0,1,0,4,0,4,0,1,0},{1,0,0,7,3,1,0,0,1,0},{1,1,0,1,3,5,3,1,1,0},
            {1,1,4,1,1,1,7,1,1,1},{1,0,0,0,0,0,0,0,0,1},{1,0,0,0,1,1,0,1,0,1},{1,1,1,1,1,1,0,0,0,1},{0,0,0,0,0,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0},{1,0,0,0,0,0,0,1,0,0,0,0,0,0,0},{1,0,4,4,0,0,0,1,1,1,0,0,0,0,0},
            {1,0,0,4,0,4,4,4,0,1,1,1,1,1,0},{1,1,0,1,1,0,3,3,3,0,0,0,0,1,1},{0,1,0,1,5,1,3,3,3,1,1,1,4,0,1},
            {0,1,0,1,0,4,3,3,3,0,0,0,0,0,1},{1,1,0,1,0,4,3,3,3,4,0,1,0,1,1},{1,0,0,1,1,1,1,1,0,1,1,1,0,1,0},
            {1,0,0,0,0,0,0,4,0,0,0,4,0,1,0},{1,1,1,1,1,1,1,1,1,1,1,0,0,1,0},{0,0,0,0,0,0,0,0,0,0,1,1,1,1,0}
        },
        {
             {0,0,0,1,1,1,1,1,0},{0,0,0,1,0,5,0,1,0},{0,0,0,1,4,4,4,1,0},{1,1,1,1,0,0,0,1,0},{1,0,0,0,3,4,4,1,1},
             {1,0,4,3,4,3,0,3,1},{1,0,0,1,3,1,3,1,1},{1,1,1,1,1,1,1,1,0}
        },
        {
             {1,1,1,1,1,1,1,1,1,1,1,1},{1,3,3,3,0,1,0,0,0,0,0,1},{1,3,3,0,0,1,0,1,1,0,0,1},{1,3,3,0,0,0,0,0,1,0,0,1},
             {1,3,3,0,0,1,0,4,1,1,0,1},{1,3,3,3,0,1,4,0,4,0,0,1},{1,1,1,1,1,1,0,0,4,4,0,1},{0,1,1,0,0,4,0,4,4,0,0,1},{0,1,5,0,4,4,4,0,0,1,0,1},
             {0,1,1,0,4,0,1,1,0,0,0,1},{0,0,1,0,0,0,0,0,0,0,0,1},{0,0,1,1,1,1,1,1,1,1,1,1}
        },
        {
             {1,1,1,1,1,1,1,1,1,0,0},{1,0,0,0,0,0,0,0,1,0,0},{1,0,0,4,0,4,0,4,1,0,0},{1,1,0,1,4,1,1,0,1,0,0},{0,1,0,3,3,0,3,3,1,1,0},
             {0,1,1,3,3,0,3,3,0,1,0},{0,0,1,0,1,1,4,1,0,1,1},{0,0,1,4,0,4,0,4,0,0,1},{0,0,1,0,0,0,0,0,0,5,1},{0,0,1,1,1,1,1,1,1,1,1}
        },
        {
            {1,1,1,1,1,1,1},{1,3,0,3,0,3,1},{1,0,4,4,4,0,1},{1,3,4,5,4,3,1},{1,0,4,4,4,0,1},{1,3,0,3,0,3,1},{1,1,1,1,1,1,1}
        }
    };
    
    
    void GameOperate(int Map[][20], int* n, int* m, int* js, int* sum, int* data, int* sl, int* guanshu, char* ch);
    void EasyGameOperate(int Map[][20], int* n, int* m, int* js, int* sum, int* data, int* sl, int* guanshu, char* ch);
    void EasyMap(int Map[20][20], int* n, int* m, char* ch);
    void MiddleMap(int Map[20][20], int* n, int* m, char* ch);
    void DifficultyMap(int Map[][20], int* n, int* m, char* ch);
    void SelectMap(int Map[][20], int* n, int* m, char* ch, int guan);
    void MenuTwo(char* ch);
    void MenuOne(char* ch);
    void Menu(char* ch);
    void PlayGame(int Map[20][20], int* n, int* m, char* ch);
    void EasyGame(char* ch);
    void MiddleGame(char* ch);
    void DifficultyGame(char* ch);
    void Operation(char* ch);
    void Introduction(char* ch);
    void Gameintor(char* ch);
    void Autor(char* ch);
    void Select(char* ch);
    void SelectGame(char* ch, int guan);
    void Gotoxy(int x, int y);
    void Password(char* ch);
    void Hide();
    void MyTime();
    int BoxData(int Map[][20], int* n, int* m);
    int GroundData(int Map[][20], int* n, int* m);
    int DrawMap(int Map[20][20], int* n, int* m, int* guanshu);
    int GameReady();
    int SelectGameReady(char* ch, int guan);
    
    int data = 0;//步数
    int* bushu = &data;
    int kongge = 0;
    int* KonGe = &kongge;
    int xianshi = 0;
    int* XianShi = &xianshi;
    int yanchi = 0;
    int* YanChi = &yanchi;
    
    #include <time.h>
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include "Sokoban.h"
    
    void Gotoxy(int x, int y)  //定位光标
    {
        COORD pos;
        pos.X = x;
        pos.Y = y;
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
    }
    
    void Hide() //隐藏光标
    {
        HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
        //COORD coord;
        CONSOLE_CURSOR_INFO cursor_info = { 1,0 };
        SetConsoleCursorInfo(hout, &cursor_info);
    }
    
    void EasyMap(int Map[20][20], int* n, int* m, char* ch) //简单关卡
    {
        static int cs = 0;
        int guan;
        if (*ch == '*')
        {
            guan = cs;
            if (guan > 0)
                guan--;
            *ch = '!';
        }
        else 
        {
            guan = cs;
            cs++;
        }
    
        *n = point[guan].x;
        *m = point[guan].y;
        for (unsigned int i = 0; i < *n; i++)
        {
            for (unsigned int j = 0; j < *m; j++)
            {
                Map[i][j] = Maps[guan][i][j];
            }
        }
    }
    
    void MiddleMap(int Map[20][20], int* n, int* m, char* ch)//中等关卡
    {
        static int cs = 0;
        int guan;
        //fscanf(fp1, "%d", &guanshu2);
        //fclose(fp1);//关闭文件
        if (*ch == '*') 
        {
            guan = cs;
            if (guan > 0)
                guan--;
            *ch = '!';
        }
        else 
        {
            guan = cs;
            cs++;
            //guan=guanshu2;
            //guanshu2++;
        }
    
        *n = point[guan + 10].x;
        *m = point[guan + 10].y;
        for (unsigned int i = 0; i < *n; i++)
        {
            for (unsigned int j = 0; j < *m; j++)
            {
                Map[i][j] = Maps[guan + 10][i][j];
            }
        }
    }
    
    void DifficultyMap(int Map[][20], int* n, int* m, char* ch) //困难关卡
    {
        static int css = 0;
        int guan;
        if (*ch == '*') 
        {
            guan = css;
            if (guan > 0)
                guan--;
            *ch = '!';
        }
        else
        {
            guan = css;
            css++;
        }
    
        *n = point[guan + 20].x;
        *m = point[guan + 20].y;
        for (unsigned int i = 0; i < *n; i++)
        {
            for (unsigned int j = 0; j < *m; j++)
            {
                Map[i][j] = Maps[guan + 20][i][j];
            }
        }
    }
    
    void SelectMap(int Map[][20], int* n, int* m, char* ch, int guan) //选关地图
    {
        if (guan > 0)guan--;
    
        *n = point[guan].x;
        *m = point[guan].y;
        for (unsigned int i = 0; i < *n; i++)
        {
            for (unsigned int j = 0; j < *m; j++)
            {
                Map[i][j] = Maps[guan][i][j];
            }
        }
    }
    
    void MenuTwo(char* ch) //菜单二
    {
        while (1) 
        {
            system("cls");
            Hide();
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            int s;
            printf("\n\n\n\n\n\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t   (1):简单关卡\n\n");
            printf("\t\t   (2):中等关卡\n\n");
            printf("\t\t   (3):困难关卡\n\n");
            printf("\t\t   (4):退出页面\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t    请输入序号。\n");
            s = _getch();
            while (s < '1' || s>'4') 
            {
                printf("输入有误,请重新输入:");
                s = _getch();
            }
            if (s == '1')
                EasyGame(ch);
            else if (s == '2')
                MiddleGame(ch);
            else if (s == '3')
                DifficultyGame(ch);
            else if (s == '4')
                MenuOne(ch);
        }
    }
    
    void Autor(char* ch) //作者。。。
    {
        char hh = '!';
        system("cls");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        printf("\n\n\n\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        printf("\t\t    退出请按   键。\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
        Gotoxy(28, 27);
        printf("ESC");
        hh = _getch();
        if (hh == 27)
            Introduction(ch);
    }
    
    void Menu(char* ch) {//主菜单
        while (1) 
        {
            system("cls");
            Hide();
            int s;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            printf("\n\n\n\n\n\t       主        菜        单\n\n");
            printf("\n\n\t\t       推箱子\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t   (1):开始游戏\n\n");
            printf("\t\t   (2):操作介绍\n\n");
            printf("\t\t   (3):游戏介绍\n\n");
            printf("\t\t   (4):退出游戏\n\n");
            printf("         ------------------------------------\n\n");
            printf("****************第一次请先观看操作介绍****************\n\n");
            printf("\t\t    请输入序号。\n");
            s = _getch();
            while (s < '1' || s>'4') 
            {
                printf("\t\t输入有误,请重新输入。\n");
                s = _getch();
            }
            if (s == '1')
                MenuOne(ch);
            else if (s == '2')
                Operation(ch);
            else if (s == '3')
                Introduction(ch);
            else
            {
                int i = MessageBox(NULL, L"\n确定要退出游戏吗?", L"退出提示", MB_YESNO);
                if (i == IDYES)
                    exit(0);
            }
    
        }
    }
    
    void MenuOne(char* ch) {//菜单一
        while (1) 
        {
            system("cls");
            Hide();
            int s;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            printf("\n\n\n\n\n\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t   (1):闯关模式\n\n");
            printf("\t\t   (2):选关模式\n\n");
            printf("\t\t   (3):退出页面\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t    请输入序号。\n");
            s = _getch();
            while (s < '1' || s>'3')
            {
                printf("\t\t输入有误,请重新输入。\n");
                s = _getch();
            }
            if (s == '1')
                MenuTwo(ch);
            else if (s == '2')
                Select(ch);
            else
                Menu(ch);
        }
    }
    
    void Select(char* ch) //选关
    {
        system("cls");
        int guan;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
        printf("\n\n\n\n\n\n\n\n\n");
        printf("\t\t\t    请\n\n\t\t\t   输入\n\n\t\t\t 所要选择\n\n\t\t      的关卡(1-40关),\n\n\t\t     输入0回退到前一\n\n\t\t    页面。之后按回车键:");
        scanf_s("%d", &guan);
        while (guan < 0 || guan>40)
        {
            printf("\t\t输入有误,请重新输入。\n");
            scanf_s("%d", &guan);
        }
        if (guan == 0)
            MenuOne(ch);
        SelectGameReady(ch, guan);
    }
    
    void SelectGame(char* ch, int guan)
    {
        int Map[20][20], n, m;
        memset(Map, -1, sizeof(Map));
        int sum = 0, data = 0, sl = 0;
        while (1)
        {
            SelectMap(Map, &n, &m, ch, guan);
            data = BoxData(Map, &n, &m);
            sl = GroundData(Map, &n, &m);
            while (1) 
            {
                system("cls");//清屏
                sum = DrawMap(Map, &n, &m, &guan);//画图
                sum -= sl;
                if (sum == data) {
                    Hide();//隐藏光标
                    printf("\n\t\t    恭 喜 通 关!\n\n");
                    printf("\t       请稍等,正在重置关卡。\n");
                    MyTime();
                    break;
                }
                PlayGame(Map, &n, &m, ch);//操作函数
                if (*ch == '*') {
                    *bushu = 0;
                    //*XianShi=1;
                    break;
                }
            }
            if (*ch == '*') 
            {
                *ch = '!';
                break;
            }
        }
    }
    
    int SelectGameReady(char* ch, int guan) {//游戏准备
        while (1)
        {
            system("cls");
            Hide();
            int s;
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            printf("\n\n\n\n\n\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t   (1):游戏开始\n\n");
            printf("\t\t   (2):游戏退出\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t    请输入序号。\n");
            s = _getch();
            while (s != '1' && s != '2')
            {
                printf("\t\t输入有误,请重新输入。\n");
                s = _getch();
            }
            if (s == '1')
                SelectGame(ch, guan);
            else
                Select(ch);
        }
        return 0;
    }
    
    void Password(char* ch) //密码输入判断
    {
        char passwords[10], Passwords[10] = { "123456789" };
        while (1)
        {
            system("cls");
            printf("\n\n\n\n\n\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            printf("    说明:\n\t       输入密码后按回车键。\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t (1):输入密码\n\n");
            printf("\t\t (2):退出页面\n\n");
            printf("         ------------------------------------\n\n");
            printf("\t\t    输入序号\n\n");
            //printf("\n\n\n");
            int t = _getch();
            if (t == '1')
            {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
                printf("\t\t密码:");
                int i;
                for (i = 0; i < 100; i++) 
                {
                    passwords[i] = _getch();
                    if (passwords[i] == 8)
                    {
                        i -= 2;
                        printf("\b \b");
                    }
                    else if (passwords[i] == '\r')
                        break;
                    else
                        printf("*");
                }
                passwords[i] = '\0';
                if (strcmp(passwords, Passwords) == 0)
                    break;
                else
                    MessageBox(NULL, L"\t    密码错误!!!\t\n\t请重新输入密码。\t", L"输入提示", MB_OK);
            }
            else
                Introduction(ch);
        }
    }
    
    void Introduction(char* ch)
    {
        system("cls");
        Hide();
        int s;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);//白色
        printf("\n\n\n\n\n\n\n");
        printf("         ------------------------------------\n\n");
        printf("\t\t (1):游戏名称:推箱子\n\n");
        printf("\t\t (2):游戏简介:->(next)\n\n");
        printf("\t\t (7):退出页面\n\n");
        printf("         ------------------------------------\n\n");
        printf("\t\t    请输入序号。\n");
        s = _getch();
        while (s != '2' && s != '7' && s != '4') 
        {
            printf("\t\tSorry,此序号没有下一页了。\n");
            s = _getch();
        }
        if (s == '2')
            Gameintor(ch);
        else if (s == '7')
            Menu(ch);
        else if (s == '4') 
        {
            MessageBox(NULL, L"\t          请输入密码。\t\n\t(少于十个数字或字母)\t", L"输入提示", MB_OK);
            Password(ch);
            Autor(ch);
        }
    
    }
    
    void Gameintor(char* ch) {//游戏介绍
        while (1) 
        {
            system("cls");
            Hide();
            char hh = '!';
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);//红色
            printf("\n\n\n\n\n");
            printf("   《推箱子》是一款经典电子游戏,1982年由日本Thinking Rabbit公司首次发行");
            printf("之后其他游戏开发者争相制作仿制或衍生作品。致使推箱子成为此类游戏的代名词。");
            printf("游戏要求玩家在一个狭小的仓库中,要求把木箱放到指定的位置,稍不小心就会出现");
            printf("t箱子无法移动或者通道被堵住的情况,所以需要巧妙的利用有限的空间和通道,合理");
            printf("t安排移动的次序和位置,才能顺利的完成任务。 \n");
            printf("    推箱子是一个来自日本的古老游戏,目的是在训练玩家的逻辑思考能力。在一个狭");
            printf("小的仓库中,要求把木箱放到指定的位置,稍不小心就会出现箱子无法移动或者通道被堵");
            printf("住的情况,所以需要巧妙的利用有限的空间和通道,合理安排移动的次序和位置,才能顺");
            printf("利的完成任务。\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
            printf("        注:游戏关卡来源于经典推箱子关卡。\n\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
            printf("\t\t  退出请按   键。\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
            Gotoxy(26, 21);
            printf("ESC");
            hh = _getch();
            if (hh == 27)
                Introduction(ch);
        }
    }
    
    void Operation(char* ch) {//操作介绍
        char hh = '!';
        while (1) 
        {
            system("cls");
            Hide();
            printf("\n\n\n\n\n\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
            printf("\t\t\t操作说明:\n\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);//红色
            printf("   (W):向上移动 (S):向下移动 (A):向左移动 (D):向右移动\n\n");
            printf("      (□):代表箱子 (♀):代表人   (☆):代表目的地\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
            printf("\t        *按键盘前请调整好输入法。\n\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_GREEN);
            printf("\t\t     退出请按   键。\n");
            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
            Gotoxy(29, 16);
            printf("ESC");
            hh = _getch();
            if (hh == 27)
                Menu(ch);
        }
    }
    
    int BoxData(int Map[][20], int* n, int* m)//计算箱子数
    {
        int sum = 0;
        for (int i = 0; i < *n; i++) {
            for (int j = 0; j < *m; j++) {
                if (Map[i][j] == 3)
                    sum++;
            }
        }
        return sum;
    }
    
    int GroundData(int Map[][20], int* n, int* m) //计算箱子开始时就在目的地的数目
    {
        int sum = 0;
        for (int i = 0; i < *n; i++)
        {
            for (int j = 0; j < *m; j++) 
            {
                if (Map[i][j] == 7)
                    sum++;
            }
        }
        return sum;
    }
    
    int DrawMap(int Map[20][20], int* n, int* m, int* guanshu) //画出地图
    {
        int sum = 0;
        Hide();
        printf("\n\n\n\n\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE);
        printf("\t\t     第  %d  关\n\n\n\n", *guanshu);
        for (int i = 0; i < *n; i++) 
        {
            printf("\t\t   ");
            for (int j = 0; j < *m; j++) 
            {
                switch (Map[i][j]) {
                case 1://SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);//改变颜色函数
                    printf("■");
                    break;
                case 0://空地
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
                    printf("  ");
                    break;
                case 3://目的地
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
                    printf("☆");
                    break;
                case 4://箱子
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE | FOREGROUND_RED);
                    printf("□");
                    break;
                case 5://SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
                    printf("♀");
                    break;
                case 7://箱子在目的地 4+3
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
                    printf("★");
                    sum++;
                    break;
                case 8://人在目的地  5+3
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
                    printf("♀");
                    break;
                }
            }
            printf("\n");
        }
        if (kongge == 1) 
        {
            printf("\n\t\t     当前步数为%d步。", *bushu);
            if (yanchi == 10) 
            {
                *KonGe = 0;
                *YanChi = 0;
            }
            yanchi++;
            xianshi = 1;
        }
        if (xianshi == 0)
        {
            printf("\n\t\t  按空格键查看当前步数。");
        }
        *XianShi = 0;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
        printf("\n     按ESC键退出此游戏,之后重新进入从该关重新开始。\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
        printf("\n\t   开始游戏前输入法请锁定成英文大写。\n");
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
        Gotoxy(12, 23);
        printf("W/↑:上移");
        Gotoxy(32, 23);
        printf("S/↓:下移");
        Gotoxy(12, 25);
        printf("A/←:左移");
        Gotoxy(32, 25);
        printf("D/→:右移");
        return sum;
    }
    
    void PlayGame(int Map[20][20], int* n, int* m, char* ch)//游戏控制/*************这个是最重要的**************/
    {
        char input;
        int i, j;
        //确定人的位置
        for (i = 0; i < *n; i++) 
        {
            for (j = 0; j < *m; j++) 
            {
                if (Map[i][j] == 5 || Map[i][j] == 8)
                    break;
            }
            if (Map[i][j] == 5 || Map[i][j] == 8)
                break;
        }
        input = _getch();//头文件conio.h
        switch (input) 
        {
        case 72:
        case 'W'://case 'w':
            if (Map[i - 1][j] == 0 || Map[i - 1][j] == 3)//人前面是空地或者人前面是目的地
            {
                Map[i - 1][j] += 5;
                Map[i][j] -= 5;
                data++;
            }
            else if (Map[i - 1][j] == 4 || Map[i - 1][j] == 7) //人的前面是箱子的情况
            {
                if (Map[i - 2][j] == 0 || Map[i - 2][j] == 3) 
                {
                    Map[i - 2][j] += 4;
                    Map[i - 1][j] += 1;
                    Map[i][j] -= 5;
                    data++;
                }
            }
            break;
        case 80:
        case 'S'://case 's':
            if (Map[i + 1][j] == 0 || Map[i + 1][j] == 3)//人前面是空地或者人前面是目的地
            {
                Map[i + 1][j] += 5;
                Map[i][j] -= 5;
                data++;
            }
            else if (Map[i + 1][j] == 4 || Map[i + 1][j] == 7)//人的前面是箱子的情况
            {
                if (Map[i + 2][j] == 0 || Map[i + 2][j] == 3) 
                {
                    Map[i + 2][j] += 4;
                    Map[i + 1][j] += 1;
                    Map[i][j] -= 5;
                    data++;
                }
            }
            break;
        case 75:
        case 'A'://case 'a':
            if (Map[i][j - 1] == 0 || Map[i][j - 1] == 3) //人前面是空地或者人前面是目的地
            {
                Map[i][j - 1] += 5;
                Map[i][j] -= 5;
                data++;
            }
            else if (Map[i][j - 1] == 4 || Map[i][j - 1] == 7) //人的前面是箱子的情况
            {
                if (Map[i][j - 2] == 0 || Map[i][j - 2] == 3) 
                {
                    Map[i][j - 2] += 4;
                    Map[i][j - 1] += 1;
                    Map[i][j] -= 5;
                    data++;
                }
            }
            break;
        case 77:
        case 'D'://case 'd':
            if (Map[i][j + 1] == 0 || Map[i][j + 1] == 3) //人前面是空地或者人前面是目的地
            {
                Map[i][j + 1] += 5;
                Map[i][j] -= 5;
                data++;
            }
            else if (Map[i][j + 1] == 4 || Map[i][j + 1] == 7)//人的前面是箱子的情况
            {
                if (Map[i][j + 2] == 0 || Map[i][j + 2] == 3) 
                {
                    Map[i][j + 2] += 4;
                    Map[i][j + 1] += 1;
                    Map[i][j] -= 5;
                    data++;
                }
            }
            break;
        case 27:
            *ch = '*';
            break;
        case 32:
            *KonGe = 1;
            break;
        }
    }
    
    void MyTime() //倒计时
    {
        int t = 0;
        for (int i = 9; i >= 0; i--) 
        {
            Sleep(500);
            Gotoxy(25, 23);
            if (t == 3)
                t = 0;
            if (t == 0)
                printf("%d.  ", i);
            else if (t == 1)
                printf("%d.. ", i);
            else
                printf("%d...", i);
            t++;
        }
    }
    
    int GameReady() //游戏准备
    {
        system("cls");
        Hide();
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY);//白色
        int s;
        printf("\n\n\n\n\n\n\n");
        printf("         ------------------------------------\n\n");
        printf("\t\t   (1):游戏开始\n\n");
        printf("\t\t   (2):游戏退出\n\n");
        printf("         ------------------------------------\n\n");
        printf("\t\t    请输入序号。\n");
        s = _getch();
        while (s != '1' && s != '2') {
            printf("\t\t输入有误,请重新输入。\n");
            s = _getch();
        }
        return s;
    }
    
    void GameOperate(int Map[][20], int* n, int* m, int* js, int* sum, int* data, int* sl, int* guanshu, char* ch)//游戏函数调用
    {
        while (1)
        {
            clock_t start, end;
            start = clock();
            *js = 0;
            system("cls");//清屏
            Hide();
            *sum = DrawMap(Map, n, m, guanshu);//画图
            *sum -= *sl;
            if (*sum == *data) 
            {
                system("cls");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                printf("\n\n\n\n\n\n\n\n\n\n\n\t\t    恭 喜 通 关!\n\n");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
                printf("\n\t\t 通关所用步数为%d步。\n\n", *bushu);
                end = clock();
                printf("\n\t        通关所用时间为%.3lf秒\n\n", (double)(end - start) / 9.56);
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY);
                printf("\n\t       请稍等,正在创建下一关。\n");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                MyTime();
                *bushu = 0;
                break;
            }
            PlayGame(Map, n, m, ch);//操作函数
            if (*ch == '*') 
            {
                int i = MessageBox(NULL, L"\t\n确定要退出游戏吗?\n\n(提示:退出后重新进入从退出的关卡开始)。", L"退出提示", MB_YESNO);
                if (i == IDYES) 
                {
                    *bushu = 0;
                    *XianShi = 1;
                    *js = 1;
                    break;
                }
                else 
                {
                    *ch = '!';
                    continue;
                }
            }
        }
    }
    
    void EasyGameOperate(int Map[][20], int* n, int* m, int* js, int* sum, int* data, int* sl, int* guanshu, char* ch)//游戏函数调用
    {
        while (1) 
        {
            *js = 0;
            system("cls");//清屏
            Hide();
            *sum = DrawMap(Map, n, m, guanshu);//画图
            *sum -= *sl;
            if (*sum == *data)
            {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                printf("\t\t\t\t    恭 喜 通 关!\n");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                int t = MessageBox(NULL, L"\t      你真棒!!!\n\n\t是否进入下一关?", L"提示", MB_YESNO);
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_GREEN | FOREGROUND_INTENSITY);
                printf("\t\t 通关所用步数为%d步。\n", *bushu);
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_BLUE | FOREGROUND_INTENSITY);
                printf("\t       请稍等,正在创建下一关。");
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                MyTime();
                if (t == IDYES)
                {
                    *bushu = 0;
                    break;
                }
                else 
                {
                    *bushu = 0;
                    *XianShi = 1;
                    *js = 2;
                    break;
                }
            }
            PlayGame(Map, n, m, ch);//操作函数
            if (*ch == '*')
            {
                int i = MessageBox(NULL, L"\t\n确定要退出游戏吗?\n\n(提示:退出后重新进入从退出的关卡开始)。", L"退出提示", MB_YESNO);
                if (i == IDYES)
                {
                    *bushu = 0;
                    *XianShi = 1;
                    *js = 1;
                    break;
                }
                else 
                {
                    *ch = '!';
                    continue;
                }
            }
        }
    }
    
    void EasyGame(char* ch)//简单关卡控制
    {
        int Map[20][20], n, m, js;
        static int guanshu = 1;
        memset(Map, -1, sizeof(Map));
        int sum = 0, data = 0, sl = 0;
        while (1) 
        {
            int t = GameReady();
            if (t == '2')
                break;
            while (1) 
            {
                EasyMap(Map, &n, &m, ch);
                data = BoxData(Map, &n, &m);
                sl = GroundData(Map, &n, &m);
                EasyGameOperate(Map, &n, &m, &js, &sum, &data, &sl, &guanshu, ch);
                int s;
                if (js == 0) 
                {
                    guanshu++;
                    if (guanshu < 11)
                        s = 1;
                    else 
                    {
                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                        printf("恭喜你已经通过全部简单关卡,接下来有中等关卡等待你去挑战\n");
                        Gotoxy(19, 26);
                        printf("!!!!!!");
                    }
                }
                else if (js == 1)
                    break;
                else if (js == 2) {
                    *ch = '*';
                    continue;
                }
                if (s == '2')
                    break;
            }
        }
    }
    
    void MiddleGame(char* ch)//中等关卡控制
    {
        int Map[20][20], n, m, js;
        static int guanshu = 1;
        memset(Map, -1, sizeof(Map));
        int sum = 0, data = 0, sl = 0;
        while (1) 
        {
            int t = GameReady();
            if (t == '2')
                break;
            while (1) 
            {
                MiddleMap(Map, &n, &m, ch);
                data = BoxData(Map, &n, &m);
                sl = GroundData(Map, &n, &m);
                GameOperate(Map, &n, &m, &js, &sum, &data, &sl, &guanshu, ch);
                int s;
                if (js == 0)
                {
                    guanshu++;
                    if (guanshu < 11)
                        s = 1;
                    else 
                    {
                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                        printf("恭喜你已经通过全部中等关卡,接下来有困难关卡等待你去挑战\n");
                        Gotoxy(19, 26);
                        printf("!!!!!!");
                    }
                }
                else if (js == 1)
                    break;
                if (s == '2')
                    break;
            }
        }
    }
    
    void DifficultyGame(char* ch) {//困难关卡控制
        /*
        int Map[20][20],n,m,js;
        static int guanshu=1;
        memset(Map,-1,sizeof(Map));
        int sum=0,data=0,sl=0;
        while(1) {
            int t=gameready();
            if(t=='2')
                break;
            while(1) {
                difficultyMap(Map,&n,&m,ch);
                data=boxdata(Map,&n,&m);
                sl=grounddata(Map,&n,&m);
                gameoperate(Map,&n,&m,&js,&sum,&data,&sl,&guanshu,ch);
                int s;
                if(js==0) {
                    guanshu++;
                    if(guanshu<11)
                        s=1;
                    else {
                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED |FOREGROUND_INTENSITY);
                        printf("恭喜你已经通过全部关卡!\n");
                        gotoxy(19,26);
                        printf("!!!!!!");
                    }
                } else if(js==1)
                    break;
                if(s=='2')
                    break;
            }
        }
        */
        int Map[20][20], n, m, js;
        static int guanshu = 1;
        memset(Map, -1, sizeof(Map));
        int sum = 0, data = 0, sl = 0;
        while (1)
        {
            int t = GameReady();
            if (t == '2')
                break;
            while (1) 
            {
                DifficultyMap(Map, &n, &m, ch);
                data = BoxData(Map, &n, &m);
                sl = GroundData(Map, &n, &m);
                EasyGameOperate(Map, &n, &m, &js, &sum, &data, &sl, &guanshu, ch);
                int s;
                if (js == 0) 
                {
                    guanshu++;
                    if (guanshu < 21)
                        s = 1;
                    else 
                    {
                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
                        printf("恭喜你已经通过全部关卡!\n");
                        Gotoxy(19, 26);
                        printf("!!!!!!");
                    }
                }
                else if (js == 1)
                    break;
                else if (js == 2) 
                {
                    *ch = '*';
                    continue;
                }
                if (s == '2')
                    break;
            }
        }
    }
    
    int main() {//主函数
        char ch = '!';
        system("title 推箱子C语言");//设置标题
        system("mode con cols=55 lines=30");//控制窗口大小
        while (1)
        {
            system("cls");//清除屏幕
            Hide();
            Menu(&ch);//菜单一
           
        }
        return 0;
    }
    
    
    展开全文
  • 推箱子游戏c语言实现

    2017-04-17 11:18:25
    控制台推箱子游戏
  • 这是一个用C语言实现的推箱子游戏的源程序,和大家分享一下啊
  • 这个是地图,要用c语言开发吧。 还行 。 下吧
  • C语言实现推箱子游戏

    万次阅读 多人点赞 2019-09-28 22:57:23
    很早就想过做点小游戏了,但是一直没有机会动手。今天闲来无事,动起手来。过程还是蛮顺利的,代码也不是非常难。今天给大家分享一下~ ...通过wasd键移动,规则的话就是推箱子的规则,也就不多说了。 二、代...

    很早就想过做点小游戏了,但是一直没有机会动手。今天闲来无事,动起手来。过程还是蛮顺利的,代码也不是非常难。今天给大家分享一下~

    一、介绍

    开发语言:C语言
    开发工具:Dev-C++ 5.11
    日期:2019年9月28日
    作者:ZackSock
    

    也不说太多多余的话了,先看一下效果图:
    在这里插入图片描述
    游戏中的人物、箱子、墙壁、球都是字符构成的。通过wasd键移动,规则的话就是推箱子的规则,也就不多说了。

    二、代码实现

    关于代码方面,我尽可能讲的细致。希望大家可以理解~

    (1)方法列表

    //主函数
    void main();
    
    //初始化一些数据
    initData();
    
    //在控制台上打印地图
    drawMap();
    
    //向上移动
    moveUp();
    
    //向左移动
    moveLeft()
    
    //向下移动
    moveDown()
    
    //向右移动
    moveRight();
    

    这几个方法都顾名思义,而且用意也非常明确,就initData可能不知道具体用处,但是没有什么大问题。唯一的问题就是,上左下右的顺序可能会逼死几个强迫症患者,哈哈。

    (2)参数列表

    为了方便,我把include和宏定义也放到参数列表当中

    //导入函数库
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    //宏定义
    #define WIDTH 8
    #define HEIGHT 8
    
    //定义地图数组,二维数组有两个维度,而地图也是二维的矩形
    int map[HEIGHT][WIDTH] = {
    	{0, 0, 1, 1, 1, 0, 0, 0},
    	{0, 0, 1, 4, 1, 0, 0, 0},
    	{0, 0, 1, 0, 1, 1, 1, 1},
    	{1, 1, 1, 3, 0, 3, 4, 1},
    	{1, 4, 0, 3, 2, 1, 1, 1},
    	{1, 1, 1, 1, 3, 1, 0, 0},
    	{0, 0, 0, 1, 4, 1, 0, 0},
    	{0, 0, 0, 1, 1, 1, 0, 0} 
    };
    
    //人的位置,在二维地图中,我们可以用坐标表示一个人的位置,就好比经纬度
    int x, y;
    
    //箱子的个数,推箱子肯定要有箱子嘛。
    int boxs;
    

    这里参数不多,其中横为x,纵为y,另外这里再规定一下map的一些东西:

    /**
    *	0	表示空
    *	1	表示墙
    *	2	表示人
    *	3	表示箱子
    *	4	表示目的地(球)
    *	5	表示已完成的箱子
    */
    

    (3)函数具体分析

    接下来我们一个一个函数来分析。

    1、main函数
    int main(int argc, char *argv[]) {
    	char direction;		//存储键盘按的方向 
    	initData();			//初始化一些数据
    	
    	//开始游戏的循环,这里是个死循环,每按一次按钮循环一次
    	while(1){
    		//每次循环的开始清除屏幕
    		system("cls");
    		//绘画地图
    		drawMap();
    
    		//判断,当boxs的数量0时,!0为真,然后走break跳出循环(结束游戏) 
    		if(!boxs){
    			break;
    		}
    		
    		//键盘输入方向,这里使用getch,因为getch读取字符不会显示在屏幕上
    		direction = getch();
    		
    		//用switch判断用户输入的方向
    		switch(direction){
    			case 'w':
    				//按w时,调用向上移动函数
    				moveUp();
    				break;
    			case 'a':
    				//按a时,调用向左移动函数
    				moveLeft(); 
    				break;
    			case 's':
    				moveDown();
    				break;
    			case 'd':
    				moveRight();
    				break; 
    		}
    	}  
    	//当跳出循环时,运行该语句,游戏结束
    	printf("恭喜你完成游戏!※");
    	return 0;
    }
    

    我大概说一下流程,循环外面没有什么特别的。initData()只是一些简单数据的初始化,不需要太在意。循环中大致流程如下:

    • 清除屏幕
    • 绘制地图
    • 判断游戏是否结束
    • 对用户按下的按钮进行反馈

    进入循环体,先清除屏幕,再绘制地图,然后再判断游戏是否结束。可能大家对这个顺序不是很理解,这里我们先不考虑判断游戏结束的问题。我们把清屏和绘制地图合在一起,简称“重绘地图”,而游戏结束的判断先不考虑,那么流程就简化为“重绘地图 + 响应用户的操作”。简单来说就是,用户按一下按钮,我改变一下地图。

    2、initData()

    void initData(){
    	int i, j;
    	
    	//加载数据时让用户等待,一般情况加载数据比较快
    	printf("游戏加载中,请稍后........."); 
    	
    	//遍历地图中的数据
    	for(i = 0; i < HEIGHT; i++){
    		for(j = 0; j < WIDTH; j++){
    			//遍历到2(人)时,记录人的坐标。x, y是前面定义的全局变量
    			if(map[i][j] == 2){
    				x = j;
    				y = i;
    			} 
    			//遍历到3时,箱子的数目增加。boxs是前面定义的全局变量 
    			if(map[i][j] == 3){
    				boxs++;
    			}
    		}
    	} 
    }
    

    这个方法很简单,就是遍历地图,然后初始化人的位置和箱子的个数。这里有一点要注意一下,就是到底内层循环是WIDTH还是外层循环是WIDTH。在这里插入图片描述
    如图,在遍历过程中。外层循环控制行数,即HEIGHT。那么内层循环应该是WIDTH。

    3、drawMap()

    void drawMap(){
    	int i, j;
    	for(i = 0; i < WIDTH; i++){
    		for(j = 0; j < HEIGHT; 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; 
    			}
    		}
    		printf("\n");
    	}
    }
    

    这里也非常简单,变量map中的元素,然后通过switch判断应该输出的内容。然后内层循环每走完一次就换行。

    4、moveUp()

    这个函数内容有点多,想讲一下大概思路:

    向上移有两种情况
    1、前面为空白
    	这种情况有两个步骤
    	(1)将人当前的位置设置为空白(0),
    	(2)再讲人前面的位置设置为人(22、前面为箱子
    	当前面为箱子时有三种情况
    	1、箱子前面为空白
    		移动人和箱子,这个操作有三个步骤
    		(1)将人当前位置设置为空(0)
    		(2)将箱子位置设置为人(2)
    		(3)将箱子前面设置为箱子(32、箱子前面为墙
    		这种情况不需要做任何操作
    	3、箱子前面为终点
    		这种情况有四个个步骤
    		(1)将人的位置设置为空(0)
    		(2)将箱子的位置设置为人(2)
    		(3)将终点位置设置为★(5)
    		(4)箱子boxs的数量减一
    3、前面为墙
    	这种情况最简单,不需要做任何操作
    4、前面为终点
    	我这里没有考虑太多,这种情况不做操作。(如果更换地图的话可能需要修改代码)
    

    具体代码如下,解析我全写在注释里面:

    void moveUp(){
    	//定义变量存放人物上方的坐标
    	int ux, uy; 
    	
    	//当上方没有元素时,直接return	(其实人不可能在边缘)
    	if(y == 0){
    		return;
    	}
    	
    	//记录上方坐标,x为横,y为纵,所有ux = x, uy = y - 1;
    	ux = x;
    	uy = y - 1; 
    	
    	//上方为已完成的箱子
    	if(map[uy][ux] == 5){
    		return;
    	} 
    	//假设上方为墙,直接return,这个和上面的判断可以合在一起,这里为了看清楚分开写 
    	if(map[uy][ux] == 1){
    		return;
    	}
    	
    	//假设上方为箱子
    	if(map[uy][ux] == 3){
    		//判断箱子上方是否为墙 
    		if(map[uy - 1][ux] == 1){
    			return;
    		}
    		
    		//判断箱子上方是否为终点
    		if(map[uy - 1][ux] == 4){
    			//将箱子上面内容赋值为5★ 
    			map[uy - 1][ux] = 5;
    			map[uy][ux] = 0;
    					
    			//箱子的数目减1	
    			boxs--; 
    		}else{
    			//移动箱子
    			map[uy - 1][ux] = 3;
    		}
    	}
    	//当上面几种return的情况都没遇到,人肯定会移动,移动操作如下
    	map[y][x] = 0;
    	map[uy][ux] = 2;
    	//更新人的坐标
    	y = uy; 
    } 
    

    这是一个方向的,其它方向要考虑的问题也和前面一样,我也就不赘述了。

    6、moveLeft()

    这里大致都和上面一样,就是在记录左边坐标时,应该应该是lx = x - 1。

    void moveLeft(){
    	//定义变量存放人物左边的坐标
    	int lx, ly; 
    	
    	//当左边没有元素时,直接return	
    	if(x == 0){
    		return;
    	}
    	
    	//记录左边坐标
    	lx = x - 1;
    	ly = y; 
    	
    	//左边为已完成方块
    	if(map[ly][lx] == 5){
    		return;
    	} 
    	
    	//假设左边为墙,直接return 
    	if(map[ly][lx] == 1){
    		return;
    	}
    	
    	//假设左边为箱子
    	if(map[ly][lx] == 3){
    		//判断箱子左边是否为墙 
    		if(map[ly][lx - 1] == 1){
    			return;
    		}
    		
    		//判断箱子左边是否为球
    		if(map[ly][lx - 1] == 4){
    			//将箱子左边内容赋值为5★ 
    			map[ly][lx - 1] = 5;
    			map[ly][lx] = 0;
    		
    			//箱子的数目减1 
    			boxs--; 
    		}else{
    			//移动箱子 
    			map[ly][lx - 1] = 3; 
    		}
    	}
    	map[y][x] = 0;
    	map[ly][lx] = 2;
    	x = lx; 
    }
    

    7、moveDown()

    这里在判断边界时,判断的是 y == HEIGHT - 1。

    void moveDown(){
    	//定义变量存放人物下方的坐标
    	int dx, dy; 
    	
    	//当下方没有元素时,直接return	
    	if(y == HEIGHT - 1){
    		return;
    	}
    	
    	//记录下方坐标
    	dx = x;
    	dy = y + 1; 
    	
    	//下方为已完成方块
    	if(map[dy][dx] == 5){
    		return;
    	} 
    	
    	//假设下方为墙,直接return 
    	if(map[dy][dx] == 1){
    		return;
    	}
    	
    	//假设下方为箱子
    	if(map[dy][dx] == 3){
    		//判断箱子下方是否为墙 
    		if(map[dy + 1][dx] == 1){
    			return;
    		}
    		
    		//判断箱子下方是否为球
    		if(map[dy + 1][dx] == 4){
    			//将箱子下面内容赋值为5★ 
    			map[dy + 1][dx] = 5;
    			map[dy][dx] = 0;
    			
    			//箱子的数目减1 
    			boxs--; 
    		}else{
    			//移动箱子
    			map[dy + 1][dx] = 3; 
    		}
    	}
    	map[y][x] = 0;
    	map[dy][dx] = 2;
    	y = dy; 
    }
    

    8、moveRight()

    这里也没什么特别说的:

    void moveRight(){
    	//定义变量存放人物右边的坐标
    	int rx, ry; 
    	
    	//当右边没有元素时,直接return	
    	if(x == WIDTH - 1){
    		return;
    	}
    	
    	//记录右边坐标
    	rx = x + 1;
    	ry = y; 
    	
    	//右边为已完成方块
    	if(map[ry][rx] == 5){
    		return;
    	} 
    	
    	//假设右边为墙,直接return 
    	if(map[ry][rx] == 1){
    		return;
    	}
    	
    	//假设右边为箱子
    	if(map[ry][rx] == 3){
    		//判断箱子右边是否为墙 
    		if(map[ry][rx + 1] == 1){
    			return;
    		}
    		
    		//判断箱子左边是否为球
    		if(map[ry][rx + 1] == 4){
    			//将箱子右边内容赋值为5★ 
    			map[ry][rx + 1] = 5;
    			map[ry][rx] = 0;
    			
    			//箱子的数目减1 
    			boxs--; 
    		}else{
    			//移动箱子 
    			map[ry][rx + 1] = 3; 
    		}
    	}
    	map[y][x] = 0;
    	map[ry][rx] = 2;
    	x = rx; 
    }
    

    三、总结

    现在再回顾开始的运行步骤

    • 清除屏幕
    • 绘制地图
    • 判断游戏是否结束
    • 对用户按下的按钮进行反馈

    这里把判断游戏是否结束放到了重绘图像后面,因为在对用户进行反馈的时候只是改变了map中的数据,实际上最后一个箱子推到终点的图像还没有显示出来,所以要在重绘之后再判断是否结束游戏。

    代码有很多冗余的地方,一方面是想大家更好的理解,还有一方面出于懒。哈哈,代码运行起来没有问题,源码和源程序我会上传,有兴趣的可以下下来,或者直接复制代码运行也是没问题的。
    百度云连接如下:
    链接:https://pan.baidu.com/s/1pwEKt3VTKmssDgU6dLx0pg 提取码:4o9v

    展开全文
  • 推箱子,c语言源代码,小游戏c语言源代码,适合初学者的c语言小游戏源代码 推箱子,c语言源代码,小游戏c语言源代码,适合初学者的c语言小游戏源代码
  • 使用C语言开发的控制台小游戏推箱子,拥有大量的关卡
  • 游戏推箱子c语言

    2021-09-28 22:08:57
    游戏推箱子(c语言)一、项目背景二、设计目的三、项目功能需求1、屏幕绘图输出2、移动箱子3、移动...本章将用C语言实现一个简单的推箱子游戏,旨在介绍推箱子游戏的实现方法,并逐步介绍C语言图形编程的方法和技巧。

    一、项目背景

    ​ 游戏推箱子既能锻炼思维的严密性,又有很多乐趣。本章将用C语言实现一个简单的推箱子游戏,旨在介绍推箱子游戏的实现方法,并逐步介绍C语言图形编程的方法和技巧。

    二、设计目的

    • 如何实现二维数组定义,操作等功能
    • 如何从键盘输入中获取键值信息
    • 如何在图形方式下实现光标的显示和定位
    • 如何对图像函数进行使用
    • 如何通过C语言实现游戏的基本控制操作和相关设置

    三、项目功能需求

    1、屏幕绘图输出

    能够实现绘制城墙,在空地上绘制箱子,在目的地绘制箱子,绘制小人和绘制目的地等功能

    2、移动箱子

    能够实现箱子的移动,包括目的地之间,空地之间和目的地与空地之间的箱子移动等功能

    3、移动小人

    能够实现小人的移动,从而推动箱子到目的地

    4、游戏功能控制

    能够实现根据用户的键盘输入,指定位置状态判断功能和游戏操作等功能

    5、关口选择

    能够实现游戏关卡的选择,游戏共分为4关,以便用户选择所需要的关卡数

    四、系统的功能结构图

    在这里插入图片描述

    五、功能模块介绍

    1、绘制地图模块

    • 绘制出每一关卡的基本地图,包括绘制城墙,在空地上绘制箱子,在目的地绘制箱子,绘制小人和绘制目的地。
    • 根据用户的每次操作绘制出操作后变化的地图信息**。**

    2、移动控制模块

    • 根据用户的输入信息来实现对小人的控制
    • 根据用户的输入信息来判断箱子的移动状态

    3、关口选择模块

    • 根据用户的输入的关卡选择相应的关数,并且在用户过关后自动进入下一关
    • 每关对应不同的地图形状,共分为四关,每关的难度依次增大

    4、游戏操作模块

    • 判断用户游戏是否过关,以及捕获用户的键盘输入信息

    六、详细设计

    1、主函数

    功能设计

    • 用于实现主界面的显示,并响应用户对菜单项的选择。
    • 主菜单为用户提供了3种不同的操作选项,当用户在界面上输入需要的操作选项时,系统会自动执行该选项对应的功能。
    • 个功能执行完之后,还能自动回到主菜单,便于用户进行其他操作。

    主函数程序流程图
    在这里插入图片描述

    2、绘制地图模块

    功能设计

    • 绘制出每一关卡的基本地图。
    • 地图的绘制包括绘制城墙,在空地上绘制箱子,在目的地绘制箱子,绘制小人和绘制目的地等操作。
    • 根据用户的每次操作绘制出操作后变化的地图信息。
    • 模块也包含了对文字颜色的具体设置

    3、移动控制模块

    功能设计

    • 根据用户的键盘输入信息来实现对小人的控制。
    • 需要分情况判断小人的状态,判断用户输入的操作能否被执行**。**
    • 根据用户输入信息来判断箱子的移动状态。

    模块流程图

    在这里插入图片描述

    4、关口选择模块

    功能设计

    • 根据用户的输入的关卡选择相应的关数。
    • 每关对应不同的地图形状,地图由二维数组表示,共分为四关,每关的难度依次增大。
    • 在用户过关后自动进入下一关**。**

    模块流程图

    在这里插入图片描述

    5、游戏操作模块

    功能设计

    • 判断用户游戏是否过关,即与箱子匹配的目的地数目是否等于目的地个数。
    • 捕获用户的键盘输入信息:如用户输入N表示进入下一关,用户输入Q表示返回主界面。
    • 用户输入键盘上下左右键实现控制信息。

    游戏操作模块流程图

    在这里插入图片描述

    七、代码

    /*****推箱子游戏*****/
    #include	<stdio.h>
    #include	<stdlib.h>
    #include	<conio.h>
    #include	<windows.h>
    #define KEY_UP 72
    #define KEY_DOWN 80
    #define KEY_LEFT 75
    #define KEY_RIGHT 77
    
    #define KEY_RETURN 2
    #define KEY_NEXT 4
    
    #define SPACE_OUT 0
    #define WALL 1
    #define SPACE 2
    #define TARGET 3
    #define BOX 4
    #define TARGET_IN 5
    #define PERSON 6
    
    
    /*函数声明*/
    void SelectColor(int iColor);
    void DesignUI();
    int WelcomePage();/*初始界面,每次通关后跳回*/
    void GetLevel1();
    void GetLevel2();
    void GetLevel3();
    void GetLevel4();
    int PlayGame(int aiMap[][16], int aiMap2[][16], int iSum, int iImp);
    int PrintMap(int aiMap[][16], int iImp);
    void MoveBox(int aiMap[][16], int iPlayerX, int iPlayerY, int iSelect, int aiMap2[][16]);
    
    /*主函数*/
    int main() {
    	while (1)
    		DesignUI();
    }
    
    /*文字颜色函数*/
    void  SelectColor(int iColor)                  //颜色函数
    {
    	HANDLE  hConsole =
    		GetStdHandle((STD_OUTPUT_HANDLE));//得到控制台输出设备的句柄
    	SetConsoleTextAttribute(hConsole, iColor);//设置控制台设备的属性
    }
    
    /*主界面函数*/
    void DesignUI()
    {
    	int iCh;
    	char cNum;
    	iCh = WelcomePage();
    	if (iCh == 49)/*键盘输入1,开始第一关游戏*/
    		GetLevel1();
    	else if (iCh == 50){/*键盘输入2,选择1到4关的游戏*/
    		printf("\n\t\t Please input level!(From 1 to 4):");
    		getchar();
    		cNum = getchar();
    		switch (cNum){
    		case '1':
    			GetLevel1();
    			break;
    		case '2':
    			GetLevel2();
    			break;
    		case '3':
    			GetLevel3();
    			break;
    		case '4':
    			GetLevel4();
    			break;
    		default:
    			printf("Enter error!\n");
    			Sleep(1000);
    			exit(0);
    			break;
    		}
    	}
    	else if (iCh == 51){/*键盘输入3,退出游戏*/
    		system("cls");
    		exit(0);
    	}
    }
    
    /*初始欢迎界面*/
    int WelcomePage()
    {
    	int i = 0;
    	system("cls");/*清屏*/
    	system("color 0E");/*设置颜色*/
    	printf("\n\n\t\t Welcome to play box!\n\n");
    	printf("\t\t Person:♀  Wall:▓ Box: ●  Target:○  Reach target:☆\n");
    	printf("\t\t Up:↑\n\t\t Down:↓\n\t\t Left:← \n\t\t Right:→\n\n");
    	printf("\t\t Press number 1 to start new game\n\t\t\n");
    	printf("\t\t Press number 2 to choose level\n\t\t\n");
    	printf("\t\t Press number 3 to quit from game\n\t\t\n");
    	printf("\t\t Press right number to continue:");
    	while (1)
    	{
    		i = getchar();
    		if (i >= 49 && i <= 51)
    			return i;
    	}
    }
    
    /*打印地图函数*/
    int PrintMap(int aiMap[][16], int iImp) {/*参数iImp代表游戏关卡*/
    	int i, j;
    	int iCount = 0;
    	for (i = 0; i<14; i++){
    		for (j = 0; j<16; j++)
    		{
    			switch (aiMap[i][j])
    			{
    			case 0:                /*空地*/
    				printf("  ");
    				break;
    			case 1:
    				SelectColor(14);    /*墙*/
    				printf("▓");
    				break;
    			case 2:                /*内部空地*/
    				printf("  ");
    				break;
    			case 3:
    				SelectColor(11);    /*目的地*/
    				printf("○");
    				break;
    			case 4:                /*箱子*/
    				SelectColor(11);
    				printf("●");
    				break;
    			case 5:                /*箱子推到目的地后显示*/
    				iCount++;
    				SelectColor(9);
    				printf("☆");
    				break;
    			case 6:                /*小人*/
    				SelectColor(10);
    				printf("♀");
    				break;
    			}
    		}
    		printf("\n");
    	}
    	SelectColor(14);
    	printf("\n");
    	printf("\tYou are in Level %d!\t\t\n", iImp);
    	printf("\tPress arrow keys to play the game!\t\n");
    	printf("\tpress N to the next level!\t\n");
    	printf("\tpress Q to return the home page!\t\n");
    	return iCount; /*返回值表示以正确放入的箱子数*/
    }
    
    /*第一关*/
    void  GetLevel1()  {
    	int  aiMap2[14][16];/*表示原始地图*/
    	int  i, j, iSum = 0; /*iSum表示箱子的数量*/
    
    	/*地图形状
    	1代表墙,2代表空地,3代表未放箱子的目标,4代表箱子,5代表以放箱子的目标,6代表小人
    	*/
    	int aiMap[14][16] = {
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 3, 4, 2, 1, 1, 2, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 3, 4, 6, 4, 2, 2, 3, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 3, 2, 4, 2, 4, 3, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    	};
    	for (i = 0; i<14; i++)
    	for (j = 0; j<16; j++){
    		aiMap2[i][j] = aiMap[i][j];
    		if (aiMap[i][j] == TARGET || aiMap[i][j] == TARGET_IN)/*记录箱子个数*/
    			iSum++;
    	}
    
    	/*PlayGame函数返回值为4的情况代表键盘输入Q返回到主界面,
    	其他情况(过关,进入下一关)执行GetLevel2函数,进入第二关
    	*/
    	if (PlayGame(aiMap, aiMap2, iSum, 1) != KEY_RETURN)
    		GetLevel2();
    }
    
    /*第二关*/
    void  GetLevel2()  {
    	int  aiMap2[14][16];/*表示原始地图*/
    	int  i, j, iSum = 0; /*iSum表示箱子的数量*/
    
    	/*地图形状
    	1代表墙,2代表空地,3代表未放箱子的目标,4代表箱子,5代表以放箱子的目标,6代表小人
    	*/
    	int aiMap[14][16] = {
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 2, 1, 1, 2, 2, 2, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 2, 2, 4, 2, 2, 2, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 2, 1, 1, 1, 2, 4, 1, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 1, 3, 3, 3, 1, 2, 1, 0, 0, 0, 0 },
    		{ 0, 0, 1, 1, 2, 1, 3, 3, 1, 1, 2, 1, 1, 0, 0, 0 },
    		{ 0, 0, 1, 2, 4, 2, 2, 4, 2, 2, 4, 2, 1, 0, 0, 0 },
    		{ 0, 0, 1, 2, 2, 2, 2, 2, 2, 2, 6, 2, 1, 0, 0, 0 },
    		{ 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    	};
    
    	for (i = 0; i<14; i++)
    	for (j = 0; j<16; j++){
    		aiMap2[i][j] = aiMap[i][j];
    		if (aiMap[i][j] == TARGET || aiMap[i][j] == TARGET_IN)/*记录箱子个数*/
    			iSum++;
    	}
    
    	/*PlayGame函数返回值为4的情况代表键盘输入Q返回到主界面,
    	其他情况(过关,进入下一关)执行GetLevel3函数,进入第三关
    	*/
    	if (PlayGame(aiMap, aiMap2, iSum, 2) != KEY_RETURN)
    		GetLevel3();
    }
    
    /*第三关*/
    void  GetLevel3()  {
    	int  aiMap2[14][16];/*表示原始地图*/
    	int  i, j, iSum = 0;/*iSum表示箱子的数量*/
    
    	/*地图形状
    	1代表墙,2代表空地,3代表未放箱子的目标,4代表箱子,5代表以放箱子的目标,6代表小人
    	*/
    	int aiMap[14][16] = {
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0 },
    		{ 0, 0, 1, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 0, 0 },
    		{ 0, 0, 1, 2, 4, 2, 1, 1, 1, 1, 4, 2, 2, 1, 0, 0 },
    		{ 0, 0, 1, 2, 2, 4, 3, 3, 3, 3, 2, 4, 2, 1, 0, 0 },
    		{ 0, 0, 1, 1, 2, 2, 2, 2, 1, 2, 6, 2, 1, 1, 0, 0 },
    		{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    	};
    
    	for (i = 0; i<14; i++)
    	for (j = 0; j<16; j++){
    		aiMap2[i][j] = aiMap[i][j];
    		if (aiMap[i][j] == TARGET || aiMap[i][j] == TARGET_IN)/*记录箱子个数*/
    			iSum++;
    	}
    
    	/*PlayGame函数返回值为4的情况代表键盘输入Q返回到主界面,
    	其他情况(过关,进入下一关)执行GetLevel5函数,进入第五关
    	*/
    	if (PlayGame(aiMap, aiMap2, iSum, 3) != KEY_RETURN)
    		GetLevel4();
    }
    
    /*第四关*/
    void  GetLevel4()  {
    	int  aiMap2[14][16];/*表示原始地图*/
    	int  i, j, iSum = 0;/*iSum表示箱子的数量*/
    
    	/*地图形状
    	1代表墙,2代表空地,3代表未放箱子的目标,4代表箱子,5代表以放箱子的目标,6代表小人
    	*/
    	int aiMap[14][16] = {
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 1, 2, 2, 2, 1, 3, 2, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 1, 1, 2, 2, 4, 3, 3, 3, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 1, 2, 2, 4, 2, 1, 5, 3, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 2, 1, 1, 4, 1, 2, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 2, 2, 4, 2, 2, 4, 2, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 0, 0, 0 },
    		{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 6, 2, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
    	};
    	for (i = 0; i<14; i++)
    	for (j = 0; j<16; j++){
    		aiMap2[i][j] = aiMap[i][j];
    		if (aiMap[i][j] == TARGET || aiMap[i][j] == TARGET_IN)/*记录箱子个数*/
    			iSum++;
    	}
    	/*PlayGame函数返回值为4的情况代表键盘输入Q返回到主界面,
    	其他情况(过关,进入下一关)执行GetLevel7函数,进入第七关
    	*/
    	PlayGame(aiMap, aiMap2, iSum, 4);
    }
    
    /*游戏操作函数*/
    int PlayGame(int aiMap[][16], int aiMap2[][16], int iSum, int iImp)/*iSum代表箱子个数*/
    {
    	int i, j;
    	int iPlayerX, iPlayerY;        /*人的位置x,y坐标*/
    	char cOp;                    /*所按下的方向键*/
    	int iNum = 0;               /*箱子推到目的地的个数*/
    
    	while (1)
    	{
    		for (i = 0; i < 14; i++)
    		{
    			for (j = 0; j < 16; j++) /*循环遍历寻找人的位置*/
    			{
    				if (aiMap[i][j] == PERSON)    /*6代表人的位置*/
    					break;
    			}
    			if (j < 16)
    				break;
    		}
    
    		iPlayerX = i;           /*将二维数组中的人的x,y坐标赋值给iPlayerX和iPlayerY*/
    		iPlayerY = j;
    		system("cls");
    		iNum = PrintMap(aiMap, iImp);
    		if (iNum == iSum)
    		{           /*将所有箱子都推到目的地*/
    			printf(" Congratulations!\n");
    			Sleep(3000);
    			return 0;
    		}
    		else
    		{                       /*还有箱子没有推到目的地*/
    			cOp = getch();          /*捕获用户键盘输入*/
    			if ((cOp == 'n') || (cOp == 'N'))/*输入N进入下一关*/
    				return KEY_NEXT;
    			else if ((cOp == 'q') || (cOp == 'Q'))/*输入Q返回主界面*/
    				return KEY_RETURN;
    		}
    		switch (cOp)
    		{          /*用户输入方向键*/
    		case KEY_UP:        /*上箭头*/
    			MoveBox(aiMap, iPlayerX, iPlayerY, 1, aiMap2);
    			break;
    		case KEY_LEFT:        /*左箭头*/
    			MoveBox(aiMap, iPlayerX, iPlayerY, 2, aiMap2);
    			break;
    		case KEY_RIGHT:        /*右箭头*/
    			MoveBox(aiMap, iPlayerX, iPlayerY, 3, aiMap2);
    			break;
    		case KEY_DOWN:        /*下箭头*/
    			MoveBox(aiMap, iPlayerX, iPlayerY, 4, aiMap2);
    			break;
    		default:
    			break;
    		}
    	}
    }
    
    /*方向移动函数*/
    void MoveBox(int aiMap[][16], int iPlayerX, int iPlayerY, int iSelect, int aiMap2[][16]) {
    	int iPlayerX1, iPlayerY1;        /*小人下一个要走的位置坐标*/
    	int iPlayerX2, iPlayerY2;        /*小人下下一个要走的位置坐标*/
    	switch (iSelect) {
    	case 1:        /*向上移动*/
    		iPlayerX1 = iPlayerX - 1;
    		iPlayerY1 = iPlayerY;
    		iPlayerX2 = iPlayerX - 2;
    		iPlayerY2 = iPlayerY;
    		break;
    	case 2:        /*向左移动*/
    		iPlayerX1 = iPlayerX;
    		iPlayerY1 = iPlayerY - 1;
    		iPlayerX2 = iPlayerX;
    		iPlayerY2 = iPlayerY - 2;
    		break;
    
    	case 3:        /*向右移动*/
    		iPlayerX1 = iPlayerX;
    		iPlayerY1 = iPlayerY + 1;
    		iPlayerX2 = iPlayerX;
    		iPlayerY2 = iPlayerY + 2;
    		break;
    
    	case 4:        /*向下移动*/
    		iPlayerX1 = iPlayerX + 1;
    		iPlayerY1 = iPlayerY;
    		iPlayerX2 = iPlayerX + 2;
    		iPlayerY2 = iPlayerY;
    		break;
    	default:
    		break;
    	}
    
    	/*对地图的操作*/
    	switch (aiMap[iPlayerX1][iPlayerY1])/*判断小人下一步要走的位置*/
    	{
    	case WALL:      /*下一位置是墙,不能移动*/
    		break;
    	case SPACE:     /*下一位置为墙内空地和下一位置为空目的地的情况相同处理*/
    	case TARGET: 
    		aiMap[iPlayerX1][iPlayerY1] = PERSON;/*小人移动到下一位置*/
    		if (aiMap2[iPlayerX][iPlayerY] == TARGET || aiMap2[iPlayerX][iPlayerY] == TARGET_IN)
    			/*小人所在位置初始为空目的地或满目的地,小人移动后此处恢复为空目的地*/
    			aiMap[iPlayerX][iPlayerY] = TARGET;
    		else
    			/*小人所在位置初始为墙内空地、箱子或者小人,小人移动后此处恢复为墙内空地*/
    			aiMap[iPlayerX][iPlayerY] = SPACE;
    		break;
    	case BOX: /*下一位置是箱子和下一位置是已放箱子目的地的情况相同处理*/		
    	case TARGET_IN:
    		if (aiMap[iPlayerX2][iPlayerY2] == TARGET)
    		{
    			/*下下位置为空目的地,箱子和小人一起移动,箱子落入目的地*/
    			aiMap[iPlayerX2][iPlayerY2] = TARGET_IN;
    			aiMap[iPlayerX1][iPlayerY1] = PERSON;
    		}
    		else if (aiMap[iPlayerX2][iPlayerY2] == SPACE)
    		{
    			/*下下位置为空地,箱子和小人一起移动,箱子落入空地*/
    			aiMap[iPlayerX2][iPlayerY2] = BOX;
    			aiMap[iPlayerX1][iPlayerY1] = PERSON;
    		}
    		else/*下下位置为墙、箱子或者满目的地,不能移动,直接退出*/
    			break;
    		if (aiMap2[iPlayerX][iPlayerY] == TARGET || aiMap2[iPlayerX][iPlayerY] == TARGET_IN)
    			/*小人所在位置初始为空目的地或满目的地,小人移动后此处恢复为空目的地*/
    			aiMap[iPlayerX][iPlayerY] = TARGET;
    		else/*小人所在位置初始为墙内空地、箱子或者小人,小人移动后此处恢复为墙内空地*/
    			aiMap[iPlayerX][iPlayerY] = SPACE;
    		break;
    	}
    }
    
    展开全文
  • 推箱子游戏C语言实现
  • 推箱子C语言

    2018-10-16 20:08:10
    推箱子游戏,源码,C语言版,界面简易
  • 本文用最简单的C语言语句写个推箱子的程序,分享给大家:/*******************************************用最简单的C语言语句写个推箱子的程序。********************************************/#include #...

    每天学习一点点,每天容易一点点。一个简单的C语言程序,用来复习c语言,代码通俗易懂。有什么问题望各位不吝赐教。

    本文用最简单的C语言语句写个推箱子的程序,分享给大家:

    /*******************************************

    用最简单的C语言语句写个推箱子的程序。

    ********************************************/

    #include

    #include

    #include

    int map[9][11] = {

    {0,1,1,1,1,1,1,1,1,1,0}, //0代表空地

    {0,1,0,0,0,1,0,0,0,1,0}, //1代表墙

    {0,1,0,4,4,4,4,4,0,1,0}, //3代表目的地

    {0,1,0,4,0,4,0,4,0,1,1}, //4代表箱子

    {0,1,0,0,0,0,0,0,4,0,1}, //5代表人

    {1,1,0,1,1,1,1,0,4,0,1},

    {1,0,8,3,3,3,3,1,0,0,1}, //2 3 4 5 6 7 8 9 1 0

    {1,0,3,3,3,3,3,0,0,1,1},

    {1,1,1,1,1,1,1,1,1,1,0} };

    //绘制地图 //二维数组+switch()

    void DrawMap()

    {

    //遍历二维数组 //0 打印空格 //1 墙 //3 目的地 //什么结构?

    for (int i = 0; i < 9; i++)

    {

    for (int j = 0; j < 11; j++)

    {

    //if else switch

    switch (map[i][j])

    {

    case 0:

    printf(" ");

    break;

    case 1:

    printf("■");

    break;

    case 3:

    printf("☆");

    break;

    case 4:

    printf("□");

    break;

    case 5:

    printf("♀"); //5人

    break;

    case 7: //4 + 3 箱子在目的地中

    printf("★");

    break;

    case 8: // 5 + 3 人在目的地当中 人?

    printf("♀");

    break;

    }

    }

    printf("\n");

    }

    }

    void PlayGame()

    {

    int r, c; //人的下标 //

    for (int i = 0; i < 9; i++)

    {

    for (int j = 0; j < 11; j++)

    {

    if (map[i][j] == 5||map[i][j]==8) //i j 人的下标?

    {

    r = i;

    c = j;

    }

    }

    }

    char ch; //字符变量

    ch = getch(); //键盘的输入保存到字符中

    // getch() getchar() 接收键盘字符

    // getch()直接接收 不显示回文 getchar()显示回文可以修改 enter键结束

    //根据不同的按键 改变不同的值. 分支.

    switch (ch)

    {

    case 'W': //W A S D方向 72 80 75 77 虚拟键值 ascii windowVK_UP VK_TAB VK_RETUNE

    case 'w':

    case 72:

    if (map[r - 1][c] == 0|| map[r - 1][c] == 3)

    {

    map[r - 1][c] += 5;

    map[r][c] -= 5;

    }

    else if (map[r - 1][c] == 4 || map[r - 1][c] == 7)

    {

    if (map[r - 2][c] == 0 || map[r - 2][c] == 3)

    {

    map[r - 2][c] += 4;

    map[r - 1][c] += 1;

    map[r][c] -= 5;

    }

    }

    break;

    case 'S': //enter按键的作用 确认 返回

    case 's':

    case 80:

    if (map[r + 1][c] == 0 || map[r + 1][c] == 3)

    {

    map[r + 1][c] += 5;

    map[r][c] -= 5;

    }

    else if (map[r + 1][c] == 4 || map[r+ 1][c] == 7)

    {

    if (map[r + 2][c] == 0 || map[r + 2][c] == 3)

    {

    map[r + 2][c] += 4;

    map[r + 1][c] += 1;

    map[r][c] -= 5;

    }

    }

    break;

    case 'A':

    case 'a':

    case 75:

    if (map[r ][c - 1] == 0 || map[r ][c - 1] == 3)

    {

    map[r ][c - 1] += 5;

    map[r][c] -= 5;

    }

    else if (map[r][c - 1] == 4 || map[r][c - 1] == 7)

    {

    if (map[r ][c - 2] == 0 || map[r ][c - 2] == 3)

    {

    map[r ][c - 2] += 4;

    map[r ][c - 1] += 1;

    map[r][c] -= 5;

    }

    }

    break;

    case 'D':

    case 'd':

    case 77:

    if (map[r][c + 1] == 0 || map[r][c + 1] == 3)

    {

    map[r][c + 1] += 5;

    map[r][c] -= 5;

    }

    else if (map[r][c + 1] == 4 || map[r][c + 1] == 7)

    {

    if (map[r][c + 2] == 0 || map[r][c + 2] == 3)

    {

    map[r][c + 2] += 4;

    map[r][c + 1] += 1;

    map[r][c] -= 5;

    }

    }

    break;

    }

    }

    //

    int main() //主函数

    {

    while (1)

    {

    system("cls");

    DrawMap();

    PlayGame();

    }

    return 0;

    }

    //通过按键来实现游戏 ---> 通过按键来改变二维数组的排列顺序.

    //思考一个问题? 地图是二维数组来决定的. 人在哪里 二维数组来决定?

    /************************************************

    //人推箱子

    可以动. 怎么办. 改变元素

    1.人的前面是空地

    2.人的前面是目的地

    3.人的前面是箱子

    3.1 箱子的前面是空地

    3.2 箱子的前面是目的地

    //盘断二维数组中有几个7

    //没有目的地 不对.. 人站在目的地

    //有没有4.

    ****************************************/

    56025ec6218ce1bbcd634ce42f515a99.png

    b3b10a6f85ee52107c00406de78da53e.png

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • 推箱子游戏(c语言课程设计)推箱子游戏(c语言课程设计)推箱子游戏(c语言课程设计)推箱子游戏(c语言课程设计)
  • 推箱子c语言

    千次阅读 2020-01-22 12:55:52
    推箱子c语言) 基本结构 制作三个地图,用数字分别表示不同的东西(0空1墙2人3箱4终点5人+终6箱+终) 改变a,b的值,实现上下左右; 移动时,要判断移动后的位置原本是什么,有时还要判断如果移动两次之后的...
  • 推箱子游戏课程设计 推箱子游戏源码(C语言) VC源码¦游戏
  • 推箱子C语言源代码

    2014-05-07 23:06:32
    推箱子游戏推箱子C语言源代码推箱子C语言源代码
  • C语言推箱子代码》由会员分享,可在线阅读,更多相关《C语言推箱子代码(4页珍藏版)》请在人人文库网上搜索。1、include#includeint i,j,steps = 0,gk = 1;char command,t,m = 0,n = 0;int map_1811,map811 = 0,0,0...
  • C语言写的推箱子游戏 刚写好的,拿来和大家分享一下
  • 推箱子C语言源代码

    2010-04-07 00:38:08
    此程序是本人大一刚学C时用win-tc做的一个推箱子游戏,希望大家喜欢的就下下来看看。额 需要积分 便上传了。一共只有一百多行代码,主要是希望初学者能够更好的了解C语言的结构和基本语法,并没有多少技术含量。谢谢...
  • 推箱子游戏(C语言课程设计+代码),基于开源的代码和程序设计! 本源码是来自:aiku嵌入式视频教程和项目开发实战
  • VS 控制台程序 可以自己选关的 刚学完C语言自己编的推箱子游戏
  • 该代码属于个人独创,现在分享给大家游戏游戏,现在有80多关。如果需要添加其他关卡,很容易扩展,仅供娱乐学习!
  • 很早就想过做点小游戏了,但是一直没有机会动手。今天闲来无事,动起手来。过程还是蛮顺利的,代码也不是非常难。...通过wasd键移动,规则的话就是推箱子的规则,也就不多说了。二、代码实现关于代码方面,...
  • 推箱子游戏C语言版)

    万次阅读 多人点赞 2019-04-02 16:42:33
    我爱玩游戏,但却玩得很菜,也没有时间去玩,只想玩着过瘾,所以,当我开始玩传奇时, 虽觉得是好玩,但玩盛大的简直是在受罪,晋级慢,没好配备,处处受人欺压。所以,4f是明 智的选择,但进去时也没有好配备,也...
  • 推箱子C语言实现

    2021-07-12 12:02:16
    C语言实现的推箱子初始版本,代码简单,逻辑清晰。
  • C语言写的推箱子游戏C语言写的推箱子游戏C语言写的推箱子游戏C语言写的推箱子游戏

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,486
精华内容 594
关键字:

推箱子游戏c语言

c语言 订阅