int menuoptions;
String userinput;
String usercheck="";
String username="user";
String password;
int intCounter=0;
con.println("TYPING GAME\n");
con.println("1. Sign in");
con.println("2. Create a new account");
menuoptions = con.readInt();
con.clear();
if(menuoptions==1){
while(!username.equals(usercheck) && intCounter==0){
con.println("Please type in your username.");
userinput = con.readLine();
con.clear();
TextInputFile infile = new TextInputFile("logins.txt");
while(infile.eof() == false && intCounter==0){
usercheck=infile.readLine();
infile.readLine();
if(username.equals(usercheck)){
intCounter=intCounter+1;
}
}
if(!userinput.equals(usercheck) && intCounter==0){
con.println("No such username.");
pause(2000);
con.clear();
}
else if(userinput.equals(usercheck)){
intCounter = intCounter+1;
}
}
con.println("What is your password?");
}
if(menuoptions==2){
con.println("What will be your username?");
username = con.readLine();
con.clear();
con.println("What will be your password?");
password = con.readLine();
con.clear();
TextOutputFile outfile = new TextOutputFile("logins.txt", true);
outfile.println(username);
outfile.println(password);
}
}
public static void pause (int intMS){
try{Thread.sleep(intMS);
}catch(InterruptedException y){}}
在 logins.txt 中,我在一行中有“voidturbulence”,在下一行中,我有“80”。当我输入“voidturbulence”时,它会跳转到“找不到用户名”,此时它应该要求输入密码。
但是,如果 userinput (voidturbulence) 等于 usercheck(第一行 [voidturbulence]),那么它不应该跳出循环并询问我的密码吗?