title: Minesweeper Code C++
body: <p>I'm having trouble writing the part of my code for minesweeper that occurs when you click on a blank space and it kind of cascades outward and results in a ring of numbers. I have an array set up for numbers and an array for bombs. In the numbers array, zero means there is nothing there. I first check if the spot clicked was a bomb, if not then if there is a number, and then the else statement must result in the cascade and ring of numbers. Basically I go through four while loops up, down, left, and right of the box clicked until I find a number. From there I have eight for loops, going along each of these lines in increasing and decreasing order of x and y until a number is found. Once a number is found, I attempt to return back to the original point, but by checking the boarders of the path I took to get there, by increasing the coordinate value by one and decreasing the coordinate value by one. For some reason I can't get my code to work. Here is an example of my while loop. "checkx" and "checky" are the coordinates of the array. "revealxposition" and "revealyposition" are the coordinates in the graphics window.</p>
  
  <pre><code>int i=0;
  
           while(i == 0 &amp;&amp; checkx &lt; length &amp;&amp; checky &lt; length)//right
           {
           if(numbers[checkx][checky] != 0)
           {
               revealxposition = (checkx*20) + 5;
               revealyposition = (checky*20) + 3;
               showNumber(revealxposition, revealyposition, numbers[checkx][checky]);
               xmax = checkx;
               i = 1;
           }
           else
           {
               if(checkx == (length - 1))
               {
                   i = 1;
                   xmax = length;
                   a = checkx*20;
                   b = checky*20;
                   c = a+20;
                   d = b+20;
                   line(a,b,c,d);
                   line(a,d,c,b);
               }
               else
               {
                   a = checkx*20;
                   b = checky*20;
                   c = a+20;
                   d = b+20;
                   line(a,b,c,d);
                   line(a,d,c,b);
  
                   checkx++;             
                }
           }
           }
  </code></pre>
  
  <p>This is an example of one of my for loops:</p>
  
  <pre><code> for(int xx = checkx; xx &lt; xmax; xx++)
   {
           int z = 0;
           int xxx = xx;
           while(z == 0 &amp;&amp; checky &lt; length)
           {
           if(numbers[xx][checky] != 0)
           {
               revealxposition = (xx*20) + 5;
               revealyposition = (checky*20) + 3;
  
               int originalxposition = revealxposition;
               int originalyposition = revealyposition;
  
               showNumber(revealxposition, revealyposition, numbers[xx][checky]);
  
               //reveal diagonals and back
               while(bombs[xx][checky] != 1 &amp;&amp; checky &gt;= originaly)
               {
                 counter++;
                 revealxposition = originalxposition - 20;
                 xx = xxx - 1;
                   showNumber(revealxposition, revealyposition, numbers[xx][checky]);
                   checky--;
                   revealyposition -= 20;
               }
               xx = xxx;
               checky = originaly;
               revealxposition = originalxposition;
               revealyposition = originalyposition;
               counter = 0;
  
               while(bombs[xx][checky] != 1 &amp;&amp; checky &gt;= originaly)
               {
                 counter++;
                 revealxposition = originalxposition + 20;
                 xx = xxx + 1;
                   showNumber(revealxposition, revealyposition, numbers[xx][checky]);
                   checky--;
                   revealyposition -= 20;
               }
               xx = xxx;
               z = 1;
               counter = 0;
           }    
           else
           {
               a = xx*20;
               b = checky*20;
               c = a+20;
               d = b+20;
               line(a,b,c,d);
               line(a,d,c,b);
               checky++;
           }
           } 
           checky = originaly;
   }
  </code></pre>