我正在制作一个Android工作室应用程序来玩哈希益智游戏。我想以网格形式输出一个二维数组,如果在决斗迭代中有一个0,我想输出一个带有0的椭圆,如果在迭代中它等于1,它将输出一个带有1等的椭圆等。但是当我运行应用程序时,它只在第一个位置输出1个椭圆。
public class boardView extends View {
public int IslandX;
public int IslandY;
private Canvas canvas;
public boardView(Context context) {
super(context);
}
int gameBoard[][] = {{0, 0, 0, 0, 1}, {0, 2, 0, 0, 2}, {2, 0, 3, 0, 1}, {0, 0, 0, 0, 0}, {0, 0, 2, 0, 2}};
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void onDraw(Canvas canvas){
Paint Blue = new Paint();
Blue.setStyle(Paint.Style.FILL);
Blue.setColor(Color.BLUE);
for (int i = 0; i < 4; i++) {
for (int R = 0; R < 4; R++) {
if (gameBoard[i][R] == 1) {
// if the iteration = 1 then..
IslandX = i;
IslandY = R;
}else if (gameBoard[i][R]==0){
IslandX = i;
IslandY = R;
}else if (gameBoard[i][R]==2){
IslandX = i;
IslandY = R;
}
canvas.drawOval(IslandX, IslandY, 50, 50, Blue);
}
}
}
}