如何从2d数组输出椭圆网格

时间:2017-01-04 18:55:35

标签: java android arrays loops nested

我试图在4x4网格中输出椭圆形网格,我希望根据数组中的数字对椭圆进行着色,我希望椭圆位于正确的网格位置。但是,当我运行我的项目时,它只输出左上角的第一个?

public class boardView extends View {

public int IslandX;
public int IslandY;

private Canvas canvas;

public boardView(Context context) {
    super(context);
}
int gameBoard[][] = {{1, 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 DrawBoard(Canvas canvas){
    Paint Island = new Paint();
    Island.setStyle(Paint.Style.FILL);
    for (int i = 0; i < 4; i++) {
        for (int R = 0; R < 4; R++) {
            IslandX=i*500;
            IslandY=R*500;
            switch (gameBoard[i][R]){
                case 0:
                    Island.setColor(Color.BLUE);

                    canvas.drawOval(IslandX, IslandY, 50, 50, Island);
                    break;
                case 1:
                    Island.setColor(Color.BLACK);
                    canvas.drawOval(IslandX, IslandY, 50, 50, Island);
                    break;
                case 2:
                    Island.setColor(Color.YELLOW);
                    canvas.drawOval(IslandX, IslandY, 50, 50, Island);
                    break;
                case 3:
                    Island.setColor(Color.GREEN);
                    canvas.drawOval(IslandX, IslandY, 50, 50, Island);
            }
        }

    }

}}

0 个答案:

没有答案