没有文件或目录,就是include"maze.h"
/maze.h
ifndef MAZE_H
define MAZE_H
include
include
include
using namespace std;
const int SEC = CLOCKS_PER_SEC;
static const int row = 20;//迷宫大小
static const int column = 20;
enum{north=1,south=2,west=3,east=4};
enum{fast=1,slow=2};
enum{wall='0',road=' ',eage='1'};
enum{turnRight,turnLeft,turnBack};
class mazePerson
{
private:
char name;
int startx;//开始位置
int starty;
int px;//当前位置
int py;
int dir;//小人的朝向
public:
mazePerson(char name,int sx,int sy,int d);
~mazePerson();
void setDir(int turn);
char getName(){return name;};
int getStartx(){return startx;}
int getStarty(){return starty;}
int getPx(){return px;};
int getPy(){return py;};
int getDir(){return dir;};
void moveFront();
};
class Maze
{
char map[row][column];
mazePerson per;
public:
Maze(char arr[row][column],char p,int sx,int sy,int d);
Maze();
~Maze();
void changeMap();
bool move();
bool isStartxy();
bool isExit();//是否到达出口
char getRight();//读取右边信息
char getLeft();//读取左边信息
char getFront();//读取前方信息
//char getRear();
void disMap();
void start(int speed);
};
endif // MAZE_H
//maze.cpp
include "maze.h"
static int steps = 0;
//结构函数,初始化小人
mazePerson::mazePerson(char n,int sx,int sy,int d)
{
name = n;
startx = sx;
starty = sy;
px = startx;
py = starty;
dir = d;
}
mazePerson::~mazePerson()
{
}
//重新设置小人方向(turnLeft左转, turnBack向后转,else右转
void mazePerson::setDir(int turn)
{
switch(dir)
{
case north:
if(turn == turnLeft)
dir = west;
else if(turn == turnBack)
dir = south;
else
dir = east;
break;
case south:
if(turn == turnLeft)
dir = east;
else if(turn == turnBack)
dir = north;
else
dir = west;
break;
case west:
if(turn == turnLeft)
dir = south;
else if(turn == turnBack)
dir = east;
else
dir = north;
break;
case east:
if(turn == turnLeft)
dir = north;
else if(turn == turnBack)
dir = west;
else
dir = south;
break;
}
}
//往前移动
void mazePerson::moveFront()
{
switch(dir)
{
case north:px--;
break;
case south:px++;
break;
case west:py--;
break;
case east:py++;
break;
}
}
//结构函数,初始化迷宫
Maze::Maze(char arr[row][column],char name,int sx,int sy,int d):
per(name,sx,sy,d)
{
int i,j;
for(i=0;i |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|