C++推箱子游戏源码

老廖
2021-04-09 / 29 评论 / 118 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年04月28日,已超过222天没有更新,若内容或图片失效,请留言反馈。

实现人物的移动控制,关卡的选择,撤销,

#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
    int victory=0;
    int Map[3][10][10] = { 
    { //2是人,4是胜利点,3是箱子,1是墙,0是空地
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
        { 1, 0, 2, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 3, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 4, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 4, 3, 4, 0, 0, 1 },
        { 1, 0, 3, 0, 0, 1, 0, 0, 0, 1 },
        { 1, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
        { 1, 0, 1, 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, 0, 2, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 3, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 4, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 3, 0, 4, 0, 1 },
        { 1, 0, 1, 0, 4, 0, 0, 0, 0, 1 },
        { 1, 0, 3, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 1, 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, 0, 2, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 3, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 4, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 1, 3, 1, 4, 0, 1 },
        { 1, 0, 0, 1, 4, 0, 0, 0, 0, 1 },
        { 1, 0, 3, 0, 0, 1, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
        { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
    }
    };
    int changeMap[10][10];
    char getchar;
    int offsetx = 0, offsety = 0;
    int manX= 1, manY= 2;
    int index=0, indey=0;
    bool flag=true;
    for (int k = 0; k <= 2; k++)
    {
        memcpy(changeMap, Map[k], sizeof(Map[k]));
        while (true)
        {
            for (int j = 0; j <= 9; j++)
            {

                for (int h = 0; h <= 9; h++)
                {
                    switch (Map[k][j][h])
                    {
                    case 0:
                        cout << "  ";//注意空格是一个字符,其它的图形是占两个字符
                        break;
                    case 1:
                        cout << "■";
                        break;
                    case 2:
                        cout << "♀";
                        break;
                    case 3:
                        cout << "☆";
                        break;
                    case 4:
                        cout << "◎";
                        break;
                        break;
                    case 6:
                        cout << "♂";
                        break;
                    case 7:
                        cout << "★";
                        break;
                    }
                }
                cout << endl;
            }
            getchar = _getch();//写入一个字符,进行移动操作
            switch (getchar)
            {
            case 's':
            case  'S':
                offsetx += 1, offsety = 0;
                break;
            case 'w':
            case 'W':
                offsetx -= 1, offsety = 0;
                break;
            case 'a':
            case 'A':
                offsetx=0, offsety-=1;
                break;
            case  'd':
            case 'D':
                offsetx = 0, offsety+=1;
                break;
            case 'r':
            case 'R':
                memcpy(Map[k], changeMap, sizeof(changeMap));
                manX = 1, manY = 2;
                break;
            case 'b':
            case 'B':
                
                if (flag)
                {  
                    //撤销人物的位置
                    Map[k][manX - index][manY - indey] += 2;
                    Map[k][manX][manY] -= 2;
                }
                else{
                //箱子和人一起撤销
                    Map[k][manX + index][manY + indey] -= 3;//manX现在是以前箱子在的地方
                    Map[k][manX - index][manY - indey] += 2;
                    Map[k][manX][manY] -= -3 + 2;//现在的位置要变成箱子 a=a-2+3;
                }
                    
                    manX -= index, manY -= indey;
                    index = 0, indey = 0;
                    flag = 0;
                    //flag的true以及false,默认撤销人,防止人在箱子旁边,箱子没动却将箱子给撤销了
                break;

            }
            //当人物进行移动时,空地,以及胜利点
            if (Map[k][manX + offsetx][manY + offsety] == 0 || Map[k][manX + offsetx][manY + offsety]==4)
            {
                flag = true;
                Map[k][manX][manY] -=2;
                Map[k][manX + offsetx][manY + offsety] += 2;
                manX += offsetx, manY += offsety;
            }
            //当前面有箱子时,或者箱子在胜利点上面
            else if ((Map[k][manX + offsetx][manY + offsety] == 3) || (Map[k][manX + offsetx][manY + offsety] == 7))
            {
                //判断箱子能推动的情况
                if (Map[k][manX + offsetx * 2][manY + offsety * 2] == 0 || Map[k][manX + offsetx * 2][manY + offsety * 2] == 4)
                {
                    flag = false;
                    Map[k][manX + offsetx * 2][manY + offsety * 2] += 3;//箱子移动时在的地方
                    Map[k][manX + offsetx][manY + offsety] += -3 + 2;//人前往箱子以前所在的地方,a=a-3+2
                    Map[k][manX][manY] -= 2;
                    manX += offsetx, manY += offsety;
                }//防止撤销步数时,箱子靠墙,按键移动时,位置未发生改变,撤销却能将箱子拉回来
                else{
                    offsetx = 0, offsety = 0;
                }
            }
            index = offsetx, indey = offsety;//为撤销方向进行赋值
            offsetx = 0,offsety = 0;//移动步数清0
            system("CLS");//实现清屏操作,需导入Windows.h包
            //判断是否将所有箱子推到胜利点上去
            for (int j = 0; j <= 9; j++)
            {

                for (int h = 0; h <= 9; h++)
                {
                    if (Map[k][j][h] == 7)
                    {
                        victory++;
                    }
                }
            }
            if (victory == 3)
            {
                manX = 1, manY = 2;//更新下一关的人物坐标
                index = 0, indey = 0;//通关了,则将本关中的撤销步数变为0
                victory = 0;
                break;
            }
            victory = 0;//将本次统计已经到胜利点的箱子个数进行清空
            
        }
    }
    return 0;
}
1

评论 (29)

取消
  1. 头像
    Neurontine
    Windows 10 · Google Chrome

    Viagra Erfahrungen Kaufen

    回复
  2. 头像
    unfomeons
    Windows 10 · Google Chrome

    Neurontine

    回复
  3. 头像
    Fraurry
    Windows 10 · Google Chrome

    http://buyneurontine.com/ - Neurontine

    回复
  4. 头像
    vieviesee
    Windows 7 · Google Chrome

    https://prednisonebuyon.com/ - prednisolone in pregnancy

    回复
  5. 头像
    sefiave
    Windows 8.1 · Google Chrome

    Prednisone

    回复
  6. 头像
    Prednisone
    Windows 10 · Google Chrome

    Online Pharmacy Malegra

    回复
  7. 头像
    Bruinee
    Windows 10 · Google Chrome

    furosemide not working

    回复
  8. 头像
    Lasix
    Windows 7 · Google Chrome

    Keflex Treatment Bladder Infection

    回复
  9. 头像
    Phigreeli
    Windows 10 · Google Chrome

    http://buypriligyhop.com/ - Priligy

    回复
  10. 头像
    stopping plaquenil abruptly
    Windows 10 · Google Chrome

    Cyproheptadine

    回复
  11. 头像
    jimdofreeKab
    Windows 10 · Google Chrome

    We spent a lot of time at her home. Maybe so her mother could keep an eye on us. Mrs. Spencer made sure to be around, offering drinks, snacks, chit chat. I noticed that she was fairly young herself. Granted at my age, anyone over 25 was old, but she was probably mid-30s, divorced. If she was a indiction of how Carley would develop, maybe I should wait. Mrs. Spencer had fuller breasts and a nice butt. She appeared to be in great shape for her "advanced" age. I knew she was keeping an eye on me as much as I was on her and her younger daughter. Her eldest, Sharon was away at college at the time. With Mrs. Spencer around we mostly limited ourselves to holding hands and sneaking in a few light kisses. One day Mrs. Spencer caught us by surprise walking in as I'd slid my hand up from Carley's stomach to rub her right breast through her shirt. She didn't really need a bra yet, so I could feel her nipple, hard, through her shirt. Just this much contact had me hard also.

    https://sites.google.com/view/tFoFpvk2KC9nDPy9 https://sites.google.com/view/uzPq2ZDeFM3FgdW5

    回复
  12. 头像
    nestionna
    Windows 10 · Google Chrome

    Plaquenil

    回复
  13. 头像
    can you buy priligy in usa
    Windows 10 · Google Chrome

    Cialis Professional Wikipedia

    回复
  14. 头像
    CeaxVally
    Windows 10 · Google Chrome

    http://buylasixshop.com/ - Lasix

    回复
  15. 头像
    Prahdeeds
    Windows 7 · Google Chrome

    http://buyzithromaxinf.com/ - zithromax for sale

    回复
  16. 头像
    Snopism
    Windows 7 · Google Chrome

    priligy online pharmacy

    回复
  17. 头像
    AgrItow
    Windows 7 · Google Chrome

    azithromycin 250mg canada

    回复
  18. 头像
    reddit buy zithromax online united states
    Windows 10 · Google Chrome

    cialis paypal

    回复
  19. 头像
    unodemn
    Windows 8.1 · Google Chrome

    http://buystromectolon.com/ - ivermectin dosage

    回复
  20. 头像
    Cialis
    Windows 8.1 · Google Chrome

    Propecia Merck

    回复
  21. 头像
    Viagra
    Windows 7 · Google Chrome

    levitra experience

    回复
  22. 头像
    admique
    Windows 10 · Google Chrome

    cialis pills for sale

    回复
  23. 头像
    Stromectol
    Windows 10 · Google Chrome

    Buy Diflucan Online Cheap

    回复
  24. 头像
    FlierlY
    Windows 10 · Google Chrome

    https://buytadalafshop.com/ - buy generic cialis online cheap

    回复
  25. 头像
    Chusiabuh
    Windows 10 · Google Chrome

    https://buysildenshop.com/ - Viagra

    回复
  26. 头像
    Edipuct
    Windows 10 · Google Chrome

    cheapest propecia uk

    回复
  27. 头像
    Punteetry
    Windows 10 · Google Chrome

    Stromectol

    回复
  28. 头像
    propecia erectile dysfunction
    Windows 10 · Google Chrome

    generic isotretinoin skin health low price

    回复
  29. 头像
    qjdeceyj
    Windows XP · Internet Explore

    C 推箱子游戏源码 - 老廖&&Games
    qjdeceyj http://www.g36r80x72ly0kh5if07dw0l4qn031k8hs.org/
    [url=http://www.g36r80x72ly0kh5if07dw0l4qn031k8hs.org/]uqjdeceyj[/url]
    aqjdeceyj

    回复