1.随机生成一张地图,黑方块为禁区,白方块为活动区
2.随机在活动区找两个块,红方块为起点,蓝方块为终点。
3.生成该地图。
4.上CODE.
//alex.shoal@gmail.com //latest update:2012-06-19 //sourse code location:..\CB_CODE\GL_TREE #include <windows.h> #include <time.h> #include <gl/gl.h> #define N 50 #define WIDTH 800 #define UNIT 2.0f/N int MAP[N][N]; LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); void EnableOpenGL(HWND hwnd, HDC*, HGLRC*); void DisableOpenGL(HWND, HDC, HGLRC); void draw_rectfill() { glColor4f(0.0, 0.0, 0.0, 0.5);// 绘制矩形 glRectf(-0.2, -0.2, 0.2, 0.2); glEnd(); } void init_field() { for (int i=0; i<N; i++) for (int j=0; j<N; j++) MAP[i][j]=0; } void set_block() { srand(time(NULL)); for(int i=0; i<800; i++) { int x=rand()%N; int y=rand()%N; MAP[x][y]=1; } } void set_positon() { int num=0; srand(time(NULL)); while (num<2) { int i=rand()%N; int j=rand()%N; if(MAP[i][j]==0) { MAP[i][j]=2+num++; // MAP[][]==2,MEANS THIS IS A START POSITION. } } } void draw_PickPOS() { glColor4f(0.0, 0.0, 0.0, 0.5);// 绘制矩形 for(int i=0; i<N; i++) for (int j=0; j&