1 回答

TA貢獻1883條經(jīng)驗 獲得超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();
}
}
添加回答
舉報