/** 二、创建两名玩家
*玩家至少要有ID、姓名、手牌等属性,手牌为扑克牌的集合
*/
public void addPlayers(){
System.out.println("-------------创建玩家-----------------");
int i = 1;
while(true){
System.out.println("请输入第"+i+"位玩家的ID和姓名:");
try {
System.out.println("输入ID:");
int id = input.nextInt();
Players pl = players.get(id);
if( pl == null){
System.out.println("输入姓名:");
String name = input.next();
Players player = new Players(id,name);
players.put(id, player);
System.out.println("成功添加玩家:"+players.get(id).name+"\n");
i++;
}
else{
System.out.println("该ID以已被占用!");
continue;
}
if(i > 2)
break;
} catch (InputMismatchException e) {
System.out.println("请输入整数类型的ID!");
input.next();//这句话是什么意思呢
continue;
}
}
System.out.println("---------------玩家创建完成----------------");
Set<Integer> keySet = players.keySet();
for (Integer integer : keySet) {
System.out.println(" ---------欢迎玩家:"+players.get(integer).name+"----------");
}
System.out.println();
Goraidh
末日泣歌
相关分类