繁体   English   中英

无法声明数组大小

[英]Can't declare array size

我正在创建一个井字游戏,我正在使用 2D 数组来跟踪每个方格中的内容。 问题是数组没有采用第二个列的大小。

package TicTacToePrj;

import java.awt.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Random;

public class SuperTicTacToeGame {
    private Cell[][] cBoard;
    private GameStatus status;
    private Cell turn;
    private int connections;

    int r = 3;
    int c = 3;

    public int getR() {
        return r;
    }

    public void setR(int r) {
        this.r = r;
    }

    public int getC() {
        return c;
    }

    public void setC(int c) {
        this.c = c;
    }

    private static final boolean AI = true;

    private ArrayList<Point> backup = new ArrayList<Point>();

    public SuperTicTacToeGame(int r, int c) {
        status = GameStatus.IN_PROGRESS;
        cBoard = new Cell[this.r][this.c];
        reset();
    }
}

该数组正在使用这些枚举器对象,这是我唯一的怀疑。

package TicTacToePrj;

public enum Cell {
X, O, EMPTY
}

Your constructor ignores the parameters ( r , c ) and uses the fields instead ( this.r , this.c ) to initialise the matrix.

如果要保留这些字段,要修复代码,您需要先将参数分配给字段。

此外,您的set方法可能无法正常工作,因为您更改了矩阵大小而不是矩阵本身。 您要么应该删除这些方法,要么在调用 setter 时对矩阵做一些事情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM