www.pudn.com > migongchengxu.rar > Maze.h


/************************************************************ 
模块名:  Maze.h 
   迷宫类的定义 
 
作者: 潘李亮   Heartblue  
                 2002-5-18 
Email:           XheartBlue@etang.com 
 
************************************************************/ 
#ifndef MAZE_H 
#define MAZE_H 
//#define _TRACE_ 
//Maze Size; 
#define  max_x 10 
#define  max_y 10 
//four directory 
#define  RIGHT  0 
#define  UP     1 
#define  LEFT   2 
#define  DOWN   3 
//walker's stauts 
#define  MOVE_NEXT    1 
#define  NEXT_DIR     2 
#define  FIND_EXIT    3 
#define  NO_PATH      4 
#define  TRACE_BACK   5 
 
//maze object 
#define  WALL   0 
#define  CAN_TO 1 
#define  VISIT  2 
#define  PATH   3 
#define  ENTRY  8 
#define  EXIT   9 
  
#include  
#include  
using namespace std; 
 
struct CDirect; 
 
//标志一个walker在迷宫中的位置 
struct CPosition 
{ 
	int _x; 
	int _y; 
	int _next_dir; 
	int _angle; 
	int _dist; 
	CPosition() 
	{ 
		_dist=0; 
		_next_dir=RIGHT; 
		_angle=0; 
	} 
	CPosition operator+(CDirect dir); 
public: 
	void Reset(); 
}; 
 
//方向类,方便位置的相加减 
struct CDirect 
{ 
	int _dx; 
	int _dy; 
	int _angle; 
     
}; 
struct Walker 
{ 
	CPosition         pos;        //walker's position 
	int               stauts;     //walker's stauts  use for FSM  
	int               is_rest;    //to indicate if the walker is in the rest (if you pause!) 
	char              _alert_inf[256];   //for store what the walker want to say to you                   
}; 
extern CDirect g_dir[4]; 
class CMaze   
{ 
public: 
	void Alert(); 
	void SetPause(bool isRest); 
	int GetData(int y,int x); 
	void Alert(char* inf); 
	void MoveNext(); 
	void TraceBack(); 
	void NextDir(); 
	void DrawWalker(); 
	void Draw(); 
	int Action(); 
	bool LoadMaze(char* strFileName); 
	void DrawRect(int x1,int y1,int x2,int y2); 
	CMaze(); 
	virtual ~CMaze(); 
private: 
	stack _path;//For store the path passed  vector used as stack 
	int               _maze[max_y][max_x];//For Store maze data; 
	                                      //0 for wall 
	                                      //1 for can go 
	                                      //2 for had visit 
	                                      //3 for a path 
	Walker _walker; 
}; 
 
#endif