Java - Change one element in the grid presentation -


the code have prints out grid made array:

//some code generates array gamecards[] = {'a','a','a','a','b','b','b','b'} //n size/length of array  public string boardtostring(){      int gridcount = 1;     int cardcount = 0;     char[][] showboard = new char[n/4][4];     while (cardcount < n){         for(int row = 0; row < (n/4); row++){             for(int column = 0; column < 4; column++){                 showboard[row][column] = gamecards[cardcount]; // how can use gamecards if it's generated in method within same class?                 system.out.print("x (" + gridcount + ") ");                 gridcount++;                 cardcount++;             }             if ((n/4) > 1) system.out.println();         }     } } 

it print out this:

// if n = 8 x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) 

the presentation of grid corresponds order of elements in original array. if want achieve this:

a(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) 

or

a(1) x(2) x(3) x(4) x(5) b(6) x(7) x(8) 

how should write loop can print out of masked grid , showing 1 actual element (maximum element need reveal 2)?

basically have store coordinates of card user picked. when printing card check if card user picked. if is, print letter instead of x. remember first choice , repeat process second card. after second round clear 2 cards stored , repeat.

for(int column = 0; column < 4; column++){     showboard[row][column] = gamecards[cardcount]; // how can use gamecards if it's generated in method within same class?     if (pickedrow1 == row && pickedcol1 == column || pickedrow2 == row && pickedcol2 == column) {         system.out.print(card_letter + " (" + gridcount + ") ");     } else {                 system.out.print("x (" + gridcount + ") ");     }     gridcount++;     cardcount++; } 

for second question. when generate gamecards in other method, either pass boardtostring parameter or can store instance variable , later access in boardtostring method.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -