C/C++实现老鼠走迷宫

该博客介绍了一个自制迷宫游戏,玩家可用上下左右操纵老鼠,在规定时间内走到粮仓算成功。代码分为main.cpp、play.h、play.cpp三个文件,包含游戏开始、编辑、查看路径等功能,还涉及地图生成、老鼠移动、最短路径计算等实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

老鼠形象可以辨认,可以用上下左右操纵老鼠;正确检测结果,若老鼠在规定的时间内走到粮仓,提示成功,否则提示失败。代码分为3个文件:main.cpp、play.h、play.cpp。

main.cpp:

#include <iostream>
#include <windows.h>
#include "play.h"
#include <stdio.h>
using namespace std;
/* run this program using the console pauser or add your own _getch, system("pause") or input loop */

int main()
{
    int Count = 0;
    cout << "欢迎使用自制迷宫游戏,Are you ready?";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << ".";
    Sleep(500);
    cout << ".";

    //    system("cls");
    //    cout<<"\t\t*************************************************"<<endl;
    //    cout<<"\t\t*                                               *"<<endl;
    //    cout<<"\t\t*                   1.开始游戏                  *"<<endl;
    //    cout<<"\t\t*                                               *"<<endl;
    //    cout<<"\t\t*                   2.编辑游戏                  *"<<endl;
    //    cout<<"\t\t*                                               *"<<endl;
    //    cout<<"\t\t*                   3.退出游戏                  *"<<endl;
    //    cout<<"\t\t*                                               *"<<endl;
    //    cout<<"\t\t*************************************************"<<endl;

    Player play_1(11, 11);
    Player play_2(13, 13);
    Player play_3(15, 15);

    int Menu;
    while (1)
    {
        if (Count < 1)
        {
            system("cls");
            cout << "\t\t*************************************************" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   1.开始游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   2.编辑游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   3.查看最短路径与所有路径    *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   4.退出游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*************************************************" << endl;
        }
        else if (Count >= 1)
        {
            system("cls");
            cout << "\t\t*************************************************" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   1.开始游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   2.编辑游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*                   3.退出游戏                  *" << endl;
            cout << "\t\t*                                               *" << endl;
            cout << "\t\t*************************************************" << endl;
        }


        cin >> Menu;
        system("cls");
        if (Menu == 1)
        {
            cout << "*******************************游戏说明*****************************" << endl;
            cout << "请使用键盘↑↓←→移动老鼠,在规定时间内用尽量少的步骤帮老鼠找到粮仓" << endl;

            system("cls");
            cout << "\t\t                     第一关                       " << endl;
            Sleep(500);

            play_1.show_Map();
            play_1.Move();
            play_1.KeepMap();

            cout << "\t\t              请进行你的选择               " << endl;
            cout << "\t\t              1.继续游戏                   " << endl;
            cout << "\t\t              2.结束游戏                   " << endl;
            int choice, choice2;
            cin >> choice;
            if (choice == 1)
            {
                cout << "\t\t                    第二关                       " << endl;
                Sleep(500);

                play_2.show_Map();
                play_2.Move();
                play_2.KeepMap();
                cout << "\t\t              请进行你的选择               " << endl;
                cout << "\t\t              1.继续游戏                   " << endl;
                cout << "\t\t              2.结束游戏                   " << endl;
                cin >> choice2;
                if (choice2 == 1)
                {
                    cout << "\t\t                    第三关                       " << endl;
                    cout << "\t\t              请进行你的选择               " << endl;
                    cout << "\t\t              1.继续游戏                   " << endl;
                    cout << "\t\t              2.结束游戏                   " << endl;
                    Sleep(500);
                    play_3.show_Map();
                    play_3.Move();
                    play_3.KeepMap();
                    cout << "您已通关,感谢使用" << endl;
                    break;

                }
                else if (choice2 == 2)
                {
       &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

2193410903

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值