Java 如何一次在二维阵列上创建/移动多个对象?

Java 如何一次在二维阵列上创建/移动多个对象?,java,arrays,object,console,2d,Java,Arrays,Object,Console,2d,我们正在尝试创建一个形状并将其放置在基于2d控制台的板上。形状将由二维阵列上的多个点组成。例如,一个三角形看起来像是用户输入的4x3x3 1 1 1 1 1 1 1 1 形状将能够移动和增长/收缩。我们已经有了能够显示其尺寸的形状,以及电路板本身。但事实证明,将它们放在棋盘上并移动(所有的点作为一个整体)是困难的。有什么建议吗?这是我们到目前为止的代码 板代码 public class Board { private int size; public Board(int board

我们正在尝试创建一个形状并将其放置在基于2d控制台的板上。形状将由二维阵列上的多个点组成。例如,一个三角形看起来像是用户输入的4x3x3

   1
 1 1 1
1 1 1 1
形状将能够移动和增长/收缩。我们已经有了能够显示其尺寸的形状,以及电路板本身。但事实证明,将它们放在棋盘上并移动(所有的点作为一个整体)是困难的。有什么建议吗?这是我们到目前为止的代码

板代码

public class Board {

private int size;

public Board(int boardSize){
    this.size = boardSize;
}

public String toString() {

    Playable[][] grid = new Playable [getSize()][getSize()];

    int k = 1;
    while (k <= (grid.length+2)) {
        System.out.print('-');
        k++;
    }

    System.out.println();

    for (Playable[] row : grid) {
        System.out.print("|");
        for (Playable item : row) {
            System.out.print((item == null ? " " : item));
        } System.out.print("| \n");
    }

    k = 1;
    while (k <= (grid.length+2)) {
        System.out.print('-');
        k++;
    }
    return "";
}

public int getSize() {
    return size;
}

public void setSize(int size) {
    this.size = size;
}
 }

每次打印新网格时,您都会将其定义为可播放[][]网格字段,以便存储状态,然后执行以下操作

grid[0][0] = new Playable(){...};//create
grid[1][0] = grid[0][0];//copy to new location
grid[0][0] = null; //remove from old location

在创建(可玩)主体中,您希望看到什么?我知道你在这里做什么,但不确定你希望我做什么。我做了Playable anonymous只是为了让你知道应该有一些实现。您已经有了矩形和四边形,所以我认为您会期望该接口的更多实现。
grid[0][0] = new Playable(){...};//create
grid[1][0] = grid[0][0];//copy to new location
grid[0][0] = null; //remove from old location