// When the panel in which the Grid of squares is being drawn is hit with a Paint event, // then we call drawGrid to redraw the maze. private void panel1_Paint(object sender, PaintEventArgs e) { paper = e.Graphics; blackPen = new Pen(Color.Black); yellowPen = new Pen(Color.Yellow); if (resetflag == true) { grid = new Grid(); grid.drawGrid(paper); currentBrush = yellowbrush; } if (resetflag == false) { // if (startflag == true) // { // drawTrail(oldspot.First, oldspot.Second, greyBrush); // grid.gridRec[rw, cl].setCrumbs(false); // } if (victory) { victally++; int rnd1 = ran.Next(40); if (rnd1 == 20) { int rnd2 = ran.Next(6); switch (rnd2) { case 0: currentBrush = redbrush; break; case 1: currentBrush = bluebrush; break; case 2: currentBrush = yellowbrush; break; case 3: currentBrush = pinkbrush; break; case 4: currentBrush = orangebrush; break; case 5: currentBrush = brownbrush; break; } } oldrect = new Rectangle(x + 3, y + 3, 14, 14); paper.FillEllipse(currentBrush, oldrect); } // end of if (victory) else { int locx = ran.Next(15); int locy = ran.Next(15); switch (direction) { case 0: // up oldrect = new Rectangle(x+3,y+3, 14, 14); newrect = new Rectangle(x+3, y-17, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(currentBrush, newrect); // crumbloc = new Pair<int,int>(x+locx,y+locy); // trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); drawTrail(x + locx, y + locy, currentBrush); drawWall(x, y-20, blackPen); drawWall(x, y, blackPen); rw--; y = y - 20; break; case 1: // down oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+3, y + 23, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(currentBrush, newrect); // crumbloc = new Pair<int,int>(x+locx,y+locy); // trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); drawTrail(x+locx, y+locy, currentBrush); drawWall(x, y + 20, blackPen); drawWall(x, y, blackPen); rw++; y = y + 20; break; case 2: // left oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x-17, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(currentBrush, newrect); // crumbloc = new Pair<int,int>(x+locx,y+locy); // trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); drawTrail(x + locx, y + locy, currentBrush); drawWall(x-20, y, blackPen); drawWall(x, y, blackPen); cl--; x = x - 20; break; case 3: // right oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+23, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(currentBrush, newrect); // crumbloc = new Pair<int,int>(x+locx,y+locy); // trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); drawTrail(x + locx, y + locy, currentBrush ); drawWall(x+20, y, blackPen); drawWall(x, y, blackPen); cl++; x = x + 20; break; } // end of switch if ((rw == 24) & (cl == 24)) { victory = true; victally = 0; } } // if (victory) } // if resetflag == false resetflag = false; }
// When the panel in which the Grid of squares is being drawn is hit with a Paint event, // then we call drawGrid to redraw the maze. private void panel1_Paint(object sender, PaintEventArgs e) { paper = e.Graphics; SolidBrush bluebrush = new SolidBrush(Color.Blue); SolidBrush yellowbrush = new SolidBrush(Color.Yellow); SolidBrush greyBrush = new SolidBrush(Color.DimGray); blackPen = new Pen(Color.Black); yellowPen = new Pen(Color.Yellow); if (resetflag == true) { grid = new Grid(); grid.drawGrid(paper); } if (resetflag == false) { if (startflag == true) { drawTrail(oldspot.First, oldspot.Second, greyBrush); grid.gridRec[rw, cl].setCrumbs(false); } int locx = ran.Next(15); int locy = ran.Next(15); int yelflag = ran.Next(14); switch (direction) { case 0: // up oldrect = new Rectangle(x+3,y+3, 14, 14); newrect = new Rectangle(x+3, y-17, 14, 14); paper.FillEllipse(greyBrush, oldrect); if (yelflag == 3) paper.FillEllipse(yellowbrush, newrect); else paper.FillEllipse(bluebrush, newrect); drawWall(x, y-20, blackPen); drawWall(x, y, blackPen); crumbloc = new Pair<int,int>(x+locx,y+locy); trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); if (yelflag == 3) drawTrail(x + locx, y + locy, yellowbrush); else drawTrail(x + locx, y + locy, bluebrush); rw--; y = y - 20; break; case 1: // down oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+3, y + 23, 14, 14); paper.FillEllipse(greyBrush, oldrect); if (yelflag == 3) paper.FillEllipse(yellowbrush, newrect); else paper.FillEllipse(bluebrush, newrect); drawWall(x, y + 20, blackPen); drawWall(x, y, blackPen); crumbloc = new Pair<int,int>(x+locx,y+locy); trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); if (yelflag == 3) drawTrail(x + locx, y + locy, yellowbrush); else drawTrail(x+locx, y+locy, bluebrush); rw++; y = y + 20; break; case 2: // left oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x-17, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); if (yelflag == 3) paper.FillEllipse(yellowbrush, newrect); else paper.FillEllipse(bluebrush, newrect); drawWall(x-20, y, blackPen); drawWall(x, y, blackPen); crumbloc = new Pair<int,int>(x+locx,y+locy); trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); if (yelflag == 3) drawTrail(x + locx, y + locy, yellowbrush); else drawTrail(x + locx, y + locy, bluebrush); cl--; x = x - 20; break; case 3: // right oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+23, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); if (yelflag == 3) paper.FillEllipse(yellowbrush, newrect); else paper.FillEllipse(bluebrush, newrect); drawWall(x+20, y, blackPen); drawWall(x, y, blackPen); crumbloc = new Pair<int,int>(x+locx,y+locy); trail.Enqueue(crumbloc); grid.gridRec[rw, cl].setCrumbs(true); if (yelflag == 3) drawTrail(x + locx, y + locy, yellowbrush); else drawTrail(x + locx, y + locy, bluebrush); cl++; x = x + 20; break; } // end of switch } // if resetflag == false resetflag = false; }
// When the panel in which the Grid of squares is being drawn is hit with a Point event, // then we call drawGrid to redraw the maze. private void panel1_Paint(object sender, PaintEventArgs e) { paper = e.Graphics; grid = new Grid(); grid.drawGrid(paper); }
// When the panel in which the Grid of squares is being drawn is hit with a Paint event, // then we call drawGrid to redraw the maze. private void panel1_Paint(object sender, PaintEventArgs e) { paper = e.Graphics; SolidBrush bluebrush = new SolidBrush(Color.Blue); SolidBrush yellowbrush = new SolidBrush(Color.Yellow); SolidBrush greyBrush = new SolidBrush(Color.DimGray); blackPen = new Pen(Color.Black); yellowPen = new Pen(Color.Yellow); if (resetflag == true) { grid = new Grid(); grid.drawGrid(paper); } if (resetflag == false) { switch (direction) { case 0: // up oldrect = new Rectangle(x+3,y+3, 14, 14); newrect = new Rectangle(x+3, y-17, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(bluebrush, newrect); drawWall(x, y-20, yellowPen); drawWall(x, y, yellowPen); rw--; y = y - 20; break; case 1: // down oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+3, y + 23, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(bluebrush, newrect); drawWall(x, y + 20, yellowPen); drawWall(x, y, yellowPen); rw++; y = y + 20; break; case 2: // left oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x-17, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(bluebrush, newrect); drawWall(x-20, y, yellowPen); drawWall(x, y, yellowPen); cl--; x = x - 20; break; case 3: // right oldrect = new Rectangle(x+3, y+3, 14, 14); newrect = new Rectangle(x+23, y+3, 14, 14); paper.FillEllipse(greyBrush, oldrect); paper.FillEllipse(bluebrush, newrect); drawWall(x+20, y, yellowPen); drawWall(x, y, yellowPen); cl++; x = x + 20; break; } // end of switch } // if resetflag == false resetflag = false; }