Minesweeper number of mines java
<p>Hi so I am almost done with this program that creates the class minesweeper game. It compiles and runs perfectly and the game shows up in the GUI client program, but one problem occurs.</p>

<p>When playing, sometimes the a 1 will appear when it has more than 1 adjacent mine, or a 0 when there is actually a mine in one of the eight squares surrounding it. Any help/suggestions are gladly appreciated!</p>

<pre><code>private void countAdjacentMines()
{        
    // TO DO: STUDENT CODE HERE
    for (int i = 0; i &lt; mineField.length; i++)
    {
        for (int j = 0; j &lt; mineField.length; j++)
        {
            if (!(mineField[i][j].getIsMine()))
            {
                int count = 0;                    
                for (int p = i -1; p &lt;= i + 1; p++)
                {          
                    for (int q = j - 1; q &lt; j + 1; q++)
                    {
                        if (0 &lt;= p &amp;&amp; p &lt; mineField.length &amp;&amp; 0 &lt;= q &amp;&amp; q &lt; mineField.length)
                        {
                            if (mineField[p][q].getIsMine())
                                count++;
                        } // end if
                    } // end for
                } // end for

            mineField[i][j].setAdjacentMines(count);
            } // end if

        } // end for loop rows
    } // end for loop columns
} // end countAdjacentMines
</code></pre>
