1616
1717using namespace cv ;
1818
19+ void drawGreenSquare (Mat *img, int x, int y)
20+ {
21+ // draw square
22+ Mat greenSquare (MAZE_WIDTH*PX_PER_UNIT, MAZE_HEIGHT*PX_PER_UNIT, CV_8UC3, Scalar (0 ,0 ,0 ));
23+ rectangle (greenSquare, Point (x*PX_PER_UNIT+PX_PER_UNIT/6 , MAZE_HEIGHT_PX-(y*PX_PER_UNIT+PX_PER_UNIT/6 )), Point (x*PX_PER_UNIT+PX_PER_UNIT-PX_PER_UNIT/6 ,MAZE_HEIGHT_PX-(y*PX_PER_UNIT+PX_PER_UNIT-PX_PER_UNIT/6 )), CV_RGB (131 ,255 ,89 ), CV_FILLED);
24+ // merge square to frame
25+ *img += greenSquare;
26+ }
27+
28+ void highlightFinish (Mat *img, struct baseMapNode maze[][MAZE_HEIGHT])
29+ {
30+ int found = false ;
31+ for (int i=0 ; i<MAZE_HEIGHT && !found; i++)
32+ {
33+ for (int j=0 ; j<MAZE_WIDTH && !found; j++)
34+ {
35+ if (maze[i][j].right != NULL )
36+ {
37+ if (maze[i][j].right ->top != NULL )
38+ {
39+ if (maze[i][j].right ->top ->left != NULL )
40+ {
41+ if (maze[i][j].right ->top ->left ->bottom == &(maze[i][j]))
42+ {
43+ found = true ;
44+ drawGreenSquare (img, i, j);
45+ drawGreenSquare (img, i, j+1 );
46+ drawGreenSquare (img, i+1 , j);
47+ drawGreenSquare (img, i+1 , j+1 );
48+ }
49+ }
50+ }
51+
52+ }
53+ }
54+ }
55+ }
56+
1957struct callbackWrapper
2058{
2159 struct baseMapNode (*startNode)[MAZE_HEIGHT];
@@ -145,6 +183,9 @@ void redrawMaze(Mat *img, struct baseMapNode startNode[][MAZE_HEIGHT], struct mo
145183 }
146184 }
147185
186+ // highlight finish
187+ highlightFinish (img, startNode);
188+
148189 // draw mouse
149190 Point tmp[3 ] = {Point (mouse->posData ->x *PX_PER_UNIT-PX_PER_UNIT/2 ,MAZE_HEIGHT_PX-mouse->posData ->y *PX_PER_UNIT+PX_PER_UNIT/2 ),
150191 Point (mouse->posData ->x *PX_PER_UNIT-PX_PER_UNIT/4 ,MAZE_HEIGHT_PX-mouse->posData ->y *PX_PER_UNIT+PX_PER_UNIT/8 ),
@@ -259,7 +300,7 @@ void mouseCallBackFunc(int event, int x, int y, int flags, void* ptr)
259300 //
260301 if (x%PX_PER_UNIT>=PX_PER_UNIT/2 )
261302 {
262- if ((int )(x/PX_PER_UNIT) != MAZE_WIDTH)
303+ if ((int )(x/PX_PER_UNIT) != MAZE_WIDTH - 1 )
263304 {
264305 data->startNode [(int )(x/PX_PER_UNIT)+1 ][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].wallLeft = true ;
265306 data->startNode [(int )(x/PX_PER_UNIT)+1 ][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].left = NULL ;
@@ -301,7 +342,7 @@ void mouseCallBackFunc(int event, int x, int y, int flags, void* ptr)
301342 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].wallTop = true ;
302343 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].top = NULL ;
303344
304- if ((MAZE_HEIGHT_PX-y)/PX_PER_UNIT != MAZE_HEIGHT)
345+ if ((( MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+ 1 != MAZE_HEIGHT)
305346 {
306347 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+1 ].wallBottom = true ;
307348 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+1 ].bottom = NULL ;
@@ -321,7 +362,7 @@ void mouseCallBackFunc(int event, int x, int y, int flags, void* ptr)
321362 //
322363 if (x%PX_PER_UNIT>=PX_PER_UNIT/2 )
323364 {
324- if ((int )(x/PX_PER_UNIT) != MAZE_WIDTH)
365+ if ((int )(x/PX_PER_UNIT) != MAZE_WIDTH - 1 )
325366 {
326367 data->startNode [(int )(x/PX_PER_UNIT)+1 ][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].wallLeft = false ;
327368 data->startNode [(int )(x/PX_PER_UNIT)+1 ][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].left = &(data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)]);
@@ -361,7 +402,7 @@ void mouseCallBackFunc(int event, int x, int y, int flags, void* ptr)
361402 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].wallTop = false ;
362403 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)].top = &(data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+1 ]);
363404
364- if ((MAZE_HEIGHT_PX-y)/PX_PER_UNIT != MAZE_HEIGHT)
405+ if ((( MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+ 1 != MAZE_HEIGHT)
365406 {
366407 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+1 ].wallBottom = false ;
367408 data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)+1 ].bottom = &(data->startNode [(int )(x/PX_PER_UNIT)][(int )((MAZE_HEIGHT_PX-y)/PX_PER_UNIT)]);
0 commit comments