Skip to content

Commit bfc5f20

Browse files
committed
changed the way that that finish is highlighted
Fixed it so that the green squares don't stack if there are multiple open squares next to each other. Runs faster too since I removed the intermediary frame.
1 parent e413692 commit bfc5f20

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

gui.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ using namespace cv;
1919
void drawGreenSquare(Mat *img, int x, int y)
2020
{
2121
//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;
22+
rectangle(*img, 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);
2623
}
2724

2825
void highlightFinish(Mat *img, struct baseMapNode maze[][MAZE_HEIGHT])
2926
{
30-
int found = false;
31-
for(int i=0; i<MAZE_HEIGHT && !found; i++)
27+
28+
for(int i=0; i<MAZE_HEIGHT; i++)
3229
{
33-
for(int j=0; j<MAZE_WIDTH && !found; j++)
30+
for(int j=0; j<MAZE_WIDTH; j++)
3431
{
3532
if(maze[i][j].right != NULL)
3633
{
@@ -40,7 +37,6 @@ void highlightFinish(Mat *img, struct baseMapNode maze[][MAZE_HEIGHT])
4037
{
4138
if(maze[i][j].right->top->left->bottom == &(maze[i][j]))
4239
{
43-
found = true;
4440
drawGreenSquare(img, i, j);
4541
drawGreenSquare(img, i, j+1);
4642
drawGreenSquare(img, i+1, j);

mmSim.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include"mazeConst.h"
1212
#include"gui.h"
1313
#include"studentAi.h"
14+
#include"time.h"
1415

1516
#define win32 1
1617

@@ -185,11 +186,11 @@ int main()
185186
else if(userInput == 'm')
186187
{
187188
resetMouse(&mouse, &(start[0][0]));
188-
while(mouse.foundFinish != true)
189+
while(mouse.foundFinish != true && waitKey(100) == -1)
189190
{
190191
studentAi(&mouse);
191192
redrawMaze(&image, start, &mouse);
192-
if(waitKey(90) == 'q')
193+
if(waitKey(10) == 'q')
193194
{
194195
break;
195196
}

0 commit comments

Comments
 (0)