//创建玩家
public void creatPlayer(){
System.out.println("-----------开始创建玩家-------------");
Player newplayer = new Player();
for(int i= 1 ;i<3 ; i++) {
System.out.println("请输入第" + i + "位玩家的ID和姓名");
while (true) {
try {
System.out.println("输入ID");
int id = console.nextInt();
for (Player player : playerList) {
if (player.getId()==(id)) {
System.out.println("该ID已被占用,请重新输入");
throw new Exception();
}
}
newplayer.setId(id);
break;
} catch (InputMismatchException e) {
console.next();
System.out.println("输入错误,请重新输入");
} catch (Exception e) {
continue;
}
}
System.out.println("请输入姓名");
String name = console.next();
newplayer.setName(name);
playerList.add(newplayer);
//i++;
}
for(int j =0 ; j<playerList.size();j++){
System.out.println("欢迎玩家" + playerList.get(j).getName());
}
}