import java.util.Scanner;
import java.lang.Object;
class GameTest
{
public static void main(String[] args)
{
User user =new User();
user.setUsername("金小白");
user.setPassWord("屌丝最帅");
for (int x = 0;x<3;x++ )
{
Scanner sc = new Scanner(System.in);
System.out.println("请问尊姓大名");
String name =sc.nextLine();
System.out.println("跪求密码");
String pwd = sc.nextLine();
if(user.isLogin(name,pwd)){
System.out.println("恭喜亲,登录成功了");
break;
}else{
if ((2-x)==0)
{
System.out.println("账号被锁定,请与金小白联系");
}else{
System.out.println("登录失败,你还有"+(2-x)+"次机会,亲要珍惜啊!");
}
}
}
System.out.println("你准备好了吗?");
System.out.println("开始游戏吧");
Guessnumber g =new Guessnumber();
g.playGame();
}
}
class Guessnumber
{
public void playGame()
{
Scanner s = new Scanner(System.in);
int number = (int)(Math.random()*100000000)+1;
while(true)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数据(1——100000000)");
int guessNumber =sc.nextInt();
if (guessNumber>number)
{
System.out.println("你猜的数"+guessNumber+"大了");
}else if (guessNumber<number)
{
System.out.println("你猜的数"+guessNumber+"小了");
}else
{
System.out.println("恭喜亲猜中了,快去买彩票吧!");
break;
}
}
}
}
class User
{
String username;
String password;
public void user(){};
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return username;
}
public void setPassWord(String password)
{
this.password=password;
}
public String getPassword()
{
return password;
}
public boolean isLogin(String username,String password){
return this.username.equals(username)&&this.password.equals(password);
}
} |
|