开发者

2d int array Drawing Canvas

开发者 https://www.devze.com 2022-12-25 12:22 出处:网络
How do you print out the contents of a 2d int array Ive code written in java for a sudoku game and im trying to create a game on the android using the same code

How do you print out the contents of a 2d int array

Ive code written in java for a sudoku game and im trying to create a game on the android using the same code

My code in java reads in a text file(sudoku grid)

i see canvas.drawText will 开发者_StackOverflowread in a string, but how do you do it for a 2d int array, so it prints out in a grid?


This is a pseudo-code, no reference has been made to any java classes. This is just to get an idea flowing:

int[][] my2dArray;

for (int i = 0; i < my2dArray.length; i++) {
  for (int j = 0; j < my2dArray[i].length; j++) {
   //Draw block
   canvas.drawRect(x, y, width, height);
   canvas.drawText(Integer.toString(my2dArray[i][j]), textX, textY);
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消