基本上,我正在用 java 创建一个棋盘游戏,并设法使用数组创建单元格,使其看起来像 10x10 网格。现在我已经对它们进行了编号,它们从左到右从上到下(如图所示)
我正在创建一个类似于蛇和梯子游戏的游戏,但有自己的特色。
问题是:如何创建类似于蛇梯板的锯齿板?
That's how it currently looks:
下面的代码是创建数组、打印数组并对其进行编号所需的代码。
名为游戏的对象:
private Cell[][] cell = new Cell[10][10];
public Game(String nameIt)
{
super(nameIt);
JPanel x = new JPanel();
x.setLayout(new GridLayout(10, 10, 2, 2));
for (int r = 0; ir< 10; r++)
for (int c= 0; c < 10; c++)
x.add(cell[r][c] = new Cell(r, c, this));
}
名为单元格的对象:
private int row;
private int col;
private int cellNum;
static int count = 0;
public Cell(int row, int column, Game guy)
{
this.ro = row;
this.col = column;
this.parent = guy;
count = count+1;
cellNum = count;
setBorder(new LineBorder(Color.BLUE, 1)); // Set cell's border
}
protected void paintComponent(Graphics p)
{
super.paintComponent(p);
p.drawString(String.valueOf(" " + cellNo), 24, 24);
}