Monday, August 8, 2022
HomeGame Developmentjava - Calculate index of backside left block on a mxn grid

java – Calculate index of backside left block on a mxn grid


I’m engaged on a board sport that requires me to paint the underside left nook of the board with random variety of rows and columns a unique colour from the opposite blocks. Given an m x n grid, how do I calculate the index of the underside left block?
On a 4×4 block, the index is 12, on a 3×3 block the index 6, on a 2×2 block the index is 2, on a 3×4 block the index is 8, and on a 4×3 block the index is 9. Thanks prematurely for the assistance!

I attempted the next nevertheless it colours the highest left field as a substitute of the underside left:

for(int r = 0; r < numRow; r++){
              for(int c=0; c < numCol; c++){
                  if(r==numRow-1 && c==0){
                      buttons[c].setBackground(new Shade(250, 0, 0));
                      buttons[c].setEnabled(false);
                  }
              }
          }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments