老鼠形象可以辨认,可以用上下左右操纵老鼠;正确检测结果,若老鼠在规定的时间内走到粮仓,提示成功,否则提示失败。代码分为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)
{
&