猜数03

来源:互联网 发布:上海大学网络选课系统 编辑:程序博客网 时间:2024/06/11 07:19
 

private Boolean ShowYourJudge(int[] guess) {

  Scanner sc = null;
  A = getInput(sc, "A");
  B = getInput(sc, "B");
  while (A + B > 4) {
   System.out.println("输入有误,请重新输入!");
   A = getInput(sc, "A");
   B = getInput(sc, "B");
  }
  if (ls.size() == 1 && A != 4) {
   System.out.println("输入错误游戏结束!");
   return false;
  } else if (A == 4) {
   int count = computers.size();
   int[] finalNum = computers.get(count).getGuess();
   System.out.println("猜出来了,你心里想的数字是:\t" + toString(finalNum)
     + " ,电脑进行了 " + count + " 次猜测!");
   return false;
  } else {
   filterList(ls, temp, guess, A, B);
   return true;
  }
 }

 private int getInput(Scanner sc, String type) {
  sc = new Scanner(System.in);
  int num = 0;
  try {
   if ("A".equalsIgnoreCase(type))
    System.out.print("数对位置也对:\t");
   else if ("B".equalsIgnoreCase(type))
    System.out.print("数对位置不对:\t");
   num = sc.nextInt();
   if (num < 0 || num > 4) {
    throw new InputMismatchException();
   }
  } catch (InputMismatchException e) {
   System.out.println("输入有误,请重新输入!");
   num = getInput(sc, type);
  }

  return num;
 }

}

原创粉丝点击