我可以在java中的数组索引中添加多个相同类型的项目吗?我正在尝试用 java 制作一个双陆棋程序,但我不知道如何创建棋盘。我需要在一个位置存储“检查器”,5 个检查器。我可以在一个索引中存储 5 个项目吗?例如。array[1] = {a,b,c,d,e}
. 如果我不能用数组做到这一点,有没有其他方法可以做到这一点。
这就是我所拥有的:(我现在没有颜色。只有变量 homeWhite 表示白人,homeBlack 表示黑人)
//other methods omitted
/**
* a method to set the default board design and layout of the game.
*/
private void newBoard()
{
homeWhite = 0;
homeBlack = 0;
barWhite = 0;
barBlack = 0;
private int [] stoneCounts = new int[25];
stoneCounts[0] = 5*homeWhite;
stoneCounts[11] = 2*homeWhite;
stoneCounts[16] = 3*homeWhite;
stoneCounts[18] = 5*homeWhite;
stoneCounts[23] = 5*homeBlack;
stoneCounts[12] = 2*homeBlack;
stoneCounts[7] = 5*homeBlack;
stoneCounts[5] = 3*homeBlack;
stoneCounts[24] = barWhite = barBlack;
System.out.println(stoneCounts[0]+"===="+ stoneCounts[1]+"===="+stoneCounts[2]+"===="+stoneCounts[3]+"===="+ stoneCounts[4]+"===="+stoneCounts[5]+"===="+
stoneCounts[6]+"===="+stoneCounts[7]+"===="+stoneCounts[8]+"===="+stoneCounts[9]+"===="+ stoneCounts[10]+"===="+stoneCounts[11]);
System.out.println("");
System.out.println("");
System.out.println("Bar: " + stoneCounts[24]);
System.out.println("");
System.out.println("");
System.out.println(stoneCounts[12]+"===="+ stoneCounts[13]+"===="+stoneCounts[14]+"===="+ stoneCounts[15]+"===="+stoneCounts[16]+"===="+ stoneCounts[17]+"===="
+stoneCounts[18]+"===="+stoneCounts[19]+"===="+stoneCounts[20]+"===="+ stoneCounts[21]+"===="+stoneCounts[22]+"===="+stoneCounts[23]);
}