本帖最后由 何亚辉 于 2016-5-22 14:45 编辑
import java.util.Scanner;
class TypeLetter {
static int end =0;
static int time =0;
public static void main(String[] args) {
System.out.println("欢迎来到玉梅打字游戏");
System.out.println("请选择");
System.out.println("1. 英文字母");
System.out.println("2, 中文汉字");
Scanner sc = new Scanner(System.in);
int a =sc.nextInt();
boolean b = true;
int typeNumber=1;
char[] getType = new char[30];
char[] standard = {'黎','玉','梅','我','爱','你','永','远','一','生','不','变','天','长','地','久','有','时','尽','此','恨','延','绵','无','绝','期'};
if (a==1) {
standard=new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','U','V','W','X','Y','O','P','Q','R','S','T','Z'};
}
int wrongNumber=0;
String s;
Time t = new Time();
new Thread(t).start();
A: while (true) {
if (b) {
while (true) {
if (typeNumber%31==0) {
System.out.println("\n"+"请输入上面的字母");
b=false;
continue A;
}
getType[typeNumber %31-1]= standard[(int)(standard.length*Math.random())];
System.out.print(getType[typeNumber %31 -1]);
try {
Thread.sleep(100);
}
catch (Exception e) {
}
typeNumber++;
}
}
if (!b) {
Scanner s0 = new Scanner(System.in);
s= s0.nextLine();
System.out.println();
if (s.length()==30&&typeNumber<63) {
for (int i=0;i<=29 ;i++ ) {
if (!(s.charAt(i)==(getType))) {
wrongNumber++;
}
}
b=true;
s="";
typeNumber++;
if (typeNumber==63) {
if (wrongNumber >=5) {
System.out.println("您一共输入错误"+wrongNumber +"个字母, 太差了");
}else if (wrongNumber==0) {
System.out.println("你太厉害了,一个都没错哦");
}else {
System.out.println("您一共输入错误"+wrongNumber +"个字母, 还需努力");
}
end=1;
break;
}
continue A;
}
}
}
}
}
class Time extends TypeLetter implements Runnable {
public void run(){
while (true) {
if (end ==1) {
System.out.println("您一共用时"+time +"秒");
return;
}
try {
Thread.sleep(1000);
time++;
}
catch (Exception e) {
}
}
}
}
|
|