#include<iostream>
#include<windows.h>
#include<stdlib.h>
#include<conio.h>
#include<fstream>
#include<iomanip>
using namespace std;
const int roomsize = 9;//设计房子内部为正方形,边长为9
int map[roomsize + 2][roomsize + 2]; //推箱子房子布局的数据结构:二维数组
int followmap[1000];
int data;//记录最短步骤数目
int times = 0;
int array[2] = { 100, 100 }; //记录最好成绩
char String[30] = "开始比赛...........";
//以下为前几轮游戏房子中细节布局的数据结构:二维数组的实际内容
int map1[roomsize + 2][roomsize + 2] =
{ //0,1,2,3,4,5,6,7,8,9,10
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, //0
{ -1, 0, 0, 0, 0, 1, 1, 1, 1, 1, -1 }, //1
{ -1, 0, 0, 0, 0, 1, 2, 0, 0, 1, -1 }, //2
{ -1, 1, 1, 1, 0, 1, 0, 3, 0, 1, -1 }, //3
{ -1, 1, 2, 1, 0, 1, 0, 0, 0, 1, -1 }, //4
{ -1, 1, 2, 1, 0, 1, 0, 3, 0, 1, -1 }, //5
{ -1, 1, 2, 1, 1, 1, 0, 3, 0, 1, -1 }, //6
{ -1, 1, 0, 0, 0, 0, 3, 4, 0, 1, -1 }, //7
{ -1, 1, 0, 0, 1, 0, 0, 0, 0, 1, -1 }, //8
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1 }, //9
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } //10
};
int map2[roomsize + 2][roomsize + 2] =
{ //0,1,2,3,4,5,6,7,8,9,10
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//0
{ -1, 0, 1, 1, 1, 1, 1, 0, 0, -1, -1 }, //1
{ -1, 0, 1, 4, 0, 0, 1, 1, 0, -1, -1 }, //2
{ -1, 0, 1, 0, 3, 0, 0, 1, 0, -1, -1 }, //3
{ -1, 1, 1, 1, 0, 1, 0, 1, 1, -1, -1 }, //4
{ -1, 1, 2, 1, 0, 1, 0, 0, 1, -1, -1 }, //5
{ -1, 1, 2, 3, 0, 0, 1, 0, 1, -1, -1 }, //6
{ -1, 1, 2, 0, 0, 0, 3, 0, 1, -1, -1 }, //7
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }, //8
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//9
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } //10
};
int map3[roomsize + 2][roomsize + 2] =
{ //0,1,2,3,4,5,6,7,8,9,10
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//0
{ -1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1 }, //1
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }, //2
{ -1, 1, 1, 0, 0, 0, 0, 1, 1, -1, -1 }, //36
{ -1, 1, 0, 3, 0, 3, 3, 0, 1, -1, -1 }, //4
{ -1, 1, 2, 2, 2, 2, 2, 2, 1, -1, -1 }, //5
{ -1, 1, 0, 3, 3, 0, 3, 0, 1, -1, -1 }, //6
{ -1, 1, 1, 1, 0, 1, 1, 1, 1, -1, -1 }, //7
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }, //8
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//9
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } //10
};
int map4[roomsize + 2][roomsize + 2] =
{ //0,1,2,3,4,5,6,7,8,9,10
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//0
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }, //1
{ -1, 1, 0, 0, 0, 0, 0, 0, 1, -1, -1 }, //2
{ -1, 1, 0, 3, 0, 1, 1, 1, 1, -1, -1 }, //3
{ -1, 1, 0, 0, 0, 2, 2, 1, 1, -1, -1 }, //4
{ -1, 1, 0, 0, 1, 2, 1, 1, 1, -1, -1 }, //5
{ -1, 1, 0, 3, 0, 4, 3, 0, 1, -1, -1 }, //6
{ -1, 1, 0, 0, 0, 0, 0, 0, 1, -1, -1 }, //7
{ -1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1 }, //8
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },//9
{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } //10
};
class node
{
public:
int data[1000];
int positionL;//位置左
int positionH;//位置
node *next;
};
/*
*队列
*/
class linkqueue//定义队列类
{
private://定义私有数据成员
node *front;
int count;
public://定义公有数据成员
linkqueue();
~linkqueue();
void insert(int item[]);//定义公有成员函数
void out(int item[]);
void clearqueue(void);
int getcount();
};
linkqueue::linkqueue()//定义相同类名的派生类
{
front = new node;//将定义的变量赋值给队头
front->next = NULL;//队头指向空节点
count = 0;
}
linkqueue::~linkqueue()
{
clearqueue();
count = 0;
}
void linkqueue::out(int item[])//出队列
{
node *searchp;
searchp = front->next;//将队头元素赋值给指针
for (int i = 0; i<(roomsize + 2)*(roomsize + 2); i++)//使i的值小于正方形滴边长
item[i] = searchp->data[i];
front->next = searchp->next;//队头接收searchp
delete searchp;
count--;
}
void linkqueue::insert(int item[])//进队
{
node *newnodep = new node, *searchp = front;
while (searchp->next != NULL)//循环使searchp节点不为空
searchp = searchp->next;
for (int i = 0; i<121; i++)
newnodep->data[i] = item[i];
newnodep->next = searchp->next;
searchp->next = newnodep;
count++;
}
void linkqueue::clearqueue(void)//定义依据于linkequeue的派生类
{
if (front->next == NULL)//若头结点为空。则返回
return;
while (front->next != NULL)//若队头结点不为空,则将头结点赋值给指针
{
node *searchp;
searchp = front->next;
front->next = searchp->next;
delete searchp;
}
count = 0;
}
int linkqueue::getcount()//定义依据于linkequeue的派生类用来返回count滴值
{
return count;
}
/*
*栈
*/
class seqstack//定义类
{
public://设定公有成员函数
seqstack();
~seqstack();
void clearseqstack(void);
void push(int item[], int &line, int &lie);//括号内为只接收变量滴地址
void pop(int item[], int &line, int &lie);
private:
node *top;
};
seqstack::seqstack()
{
top = new node;
top->next = NULL;
}
seqstack::~seqstack()
{}
void seqstack::push(int item[], int &line, int &lie)//定义以seqtack类滴push(推)的类,用来记录推动箱子的地址和位置
{
node *newnodep, *searchp = top;
newnodep = new node;
for (int i = 0; i<(roomsize + 2)*(roomsize + 2); i++)
newnodep->data[i] = item[i];
newnodep->positionH = line;//将地址进行返回
newnodep->positionL = lie;//将地址进行返回
newnodep->next = searchp->next;
searchp->next = newnodep;
}
void seqstack::pop(int item[], int &line, int &lie)
{
node *newnodep, *searchp = top;
if (searchp->next != NULL)
{
newnodep = top->next;
for (int i = 0; i<(roomsize + 2)*(roomsize + 2); i++)
item[i] = newnodep->data[i];
line = newnodep->positionH;
lie = newnodep->positionL;
top->next = newnodep->next;
delete newnodep;
}
}
void seqstack::clearseqstack(void)
{
if (top->next == NULL)
return;
while (top->next != NULL)
{
node *searchp;
searchp = top->next;
top->next = searchp->next;
delete searchp;
}
}
//对象:箱子
class box//记录人位置滴函数
{
int positionh;//人的位置纵坐标
int positionl;//人的位置横坐标
int flag;//标志位,记录人在目标位置上
int gate;//这个变量是记录关数
int count;//这个变量是记录步数
seqstack st;
linkqueue linkqu;
public:
box();
void begin();//开始界面
void choose_gate();//选关提示
void choose();//游戏时c选项的提示
void replay();//重玩
void playing();//玩游戏时界面
void display();//显示地图
void left();//左方向
void right();//右方向
void down();//下方向
void up();//上方向
void test_flag();//过关提示
void record();//这段函数为排行榜
void travers();
void returnpush();
void returninseart();
//void random();//这段函数为随机生成室内布局,暂时没有提供
};
box::box()
{
positionh = 0;
positionl = 0;
flag = 0;
count = 0;
gate = 0;
}
void box::begin()
{
system("color 17");
/*******************************输出游戏主界面***********************************/
cout << " ╭────────────-─────────────────-──╮" << endl <<//1 "<<endl<<//1
" │ │" << endl <<//2
" │ ★☆★ 推箱子游戏 ★☆★ │" << endl <<//3
" │★☆★★☆★★☆★★☆★★☆★★☆★★☆★★☆★★☆★★☆★★☆★│" << endl <<//4
" │ 游戏介绍 │" << endl <<//5
" │ │" << endl <<//6
" │怎么玩这个游戏呢?我来介绍一下:这是小人人(♀)小星星就是箱子啦(★)│" << endl <<//7
" │你要把星星放在这个地方喔(○),等到有了㊣.你就赢咯!快来挑战吧!! │" << endl <<//8
" │ │" << endl <<//9