1 回答
TA贡献1883条经验 获得超3个赞
感谢老程序员:
更改“人类玩家[i] = new Human();” 到“player[i] = new Human();”等
了解派生类的工作原理非常重要,我很高兴这就是它的工作原理。非常感谢你,我希望这可以帮助将来的人。这是我更新的代码以进行全面说明:
int highestScore = 0;
Player[] player = new Player[2];
Scanner userInput = new Scanner (System.in);
for (int i = 0; i < 2; i++)
{
System.out.println ("Choose a type of player:");
System.out.println ("1: Human");
System.out.println ("2: Computer (Threshold = 20)");
System.out.println ("3. Computer (Custom)");
System.out.print ("? : ");
playerType = Integer.valueOf(userInput.nextLine());
switch (playerType)
{
case 1:
player[i] = new Human();
case 2:
player[i] = new Computer();
case 3:
player[i] = new Karen();
}
}
添加回答
举报