假设我有一个 Player 类,例如:
public class Player {
String name;
int chips;
int betVal;
}
以下代码对于创建玩家数组是否正确?
public static void main(String[] args) {
int playerCount;
int startingChip;
out.print("How many players? ");
playerCount = myScanner.nextInt();
Player[] aPlayer = new Player[playerCount + 1];
for (int i = 0; i < playerCount + 1; i++){
aPlayer[i] = new Player();
}
out.print("Enter starting chip amount: ");
startingChip = myScanner.nextInt();
}
如果是这样,我将如何为每个玩家分配姓名、筹码金额和下注值?以后如何在代码中访问和更改它们?
编辑:将播放器作为对象或数组(名称,筹码,betVal)以便以后访问它会更容易吗?