Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m creating a minesweeper game in Java, this piece of code counts the number o

ID: 3805833 • Letter: I

Question


I'm creating a minesweeper game in Java, this piece of code counts the number of mines adjacent to a square. How do I count the mines adjacent to a square that are in the border of the grid without having an out of array error? If you can answer whith the little piece of code I gave you.

ce Debug Minesweeper/srchMyPanel Java Eclipse Source Refactor Navigate Search Project Run Window Help "MyPanel java ouse Adapter Java for (int x 1; x TOTAL COLUNNS for (int y 1 y TOTAL RONS; y++) int numCount 0; if (bombAri -11 numCount++; if(bomb Array[x][y-11- 1) numCount++ numCount if(bombArray[x][y+1] -1)( num Count++; if(bombArray[x+1] numCount++; if (bombArray[x+1][y+1] -1){ num Count +i nun Count++; nur Count++i adjacent Bombs[x][y) s nuecounti tava Applicationl caprogram Files Javaudk180 121 bin avaw exe (Mar 27 2017.5 17 4 PM

Explanation / Answer

Start 'for' loop of 'x' and 'y' for 0. Like

for(x=0; x<TOTAL_COLUMNS;x++)

{

for(y=0; y<TOTAL_ROWS;y++)

{

//Add this if condition

if(y>=0 && y<TOTAL_ROWS && x>=0 && x<TOTAL_COLUMNS && bombArray[x][y]==1)

{

numcount++;

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote