package pkg0;
import java.util.Scanner;//定义了这个用户才能输入
public class GuessNumber {
static Scanner sc;
static int targetNumber, userNumber;
static int count;
static int score;
static String command;
static void Initial() {
count = 0;
score = 0;
targetNumber = (int)(Math.random()*100);
userNumber = 0;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Initial();
System.out.println("1~100猜猜我想的是几");
sc = new Scanner(System.in);//这个就是输入
game: do {
Initial();
while(true) {
command = sc.nextLine();
if (command.equals("cheat")) {
System.out.println(targetNumber);
continue;
}
else if (command.equals("stop"))
break game;
userNumber = Integer.parseInt(command);//将String字符类型数据转换为Integer整型数据
count ++;
if (userNumber == targetNumber) {
//System.out.println("success");
score = 100 - (count - 1) * 5;
if (score >= 80)
System.out.println("你的分数是"+score+" 你这运气是天生的吗");
else if (score >= 40)
System.out.println("你的分数是"+score+" 多加练习啊");
else if (score >= 0)
System.out.println("你的分数是"+score+" 几天不见这么捞了");
else
System.out.println("你的分数是"+score+" 抓紧回家种地吧");
break;
}
else if (userNumber > targetNumber)
System.out.println("Your Number is bigger than i want.");
else
System.out.println("Your Number is less than i want.");
}
}while (true);
System.out.println("游戏结束");
sc.close();
}
}