/**
* 游戏开始
* @author LENOVO
*
*/
public class Game_Start {
public static void main(String[] args) {
//创建线程
GameWoldThread gt = new GameWoldThread();
System.out.println("========================GameWorld========================");
System.out.println("======== 请登录 ========");
Scanner sc = new Scanner(System.in);
System.out.println("输入用户名:");
String uName = sc.nextLine();
//启动线程
new Thread(gt,uName).start();
}
}
/**
* 游戏大厅
* @author LENOVO
* @version 1.0
*/
public class GameWoldThread implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("Game准备ing.........");
isSleep(3000);
System.out.println("稍等片刻......");
isSleep(1500);
System.out.println("===是否进入大厅?Y?N==");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String userName = null;
boolean flag = true;
if(isTrue(str)) {
System.out.println("正在进入大厅......");
isSleep(600);
System.out.println("进入大厅成功");
isSleep(600);
userName = this.getName();
System.out.println(userName+"欢迎您!");
do{
System.out.println("============请选择游戏============");
System.out.println("1、猜拳\t\t2、猜数字\t3、几几乘法表\n" +
" over、结束游戏");
String choice = sc.nextLine();
switch (choice) {
case "1":
PrintStarGame();
CaiQuan cq = new CaiQuan();
cq.run();
PrintEndGame();
EnterGameWold();
break;
case "2":
PrintStarGame();
CaiShuZi csz = new CaiShuZi();
csz.run();
PrintEndGame();
EnterGameWold();
break;
case "3":
PrintStarGame();
JiuJiu jj = new JiuJiu();
jj.run();
PrintEndGame();
EnterGameWold();
break;
case "over":
flag = false;
System.out.println("您已退出GameWorld!欢迎下次来玩^_^!");
break;
default:
PrintException();
EnterGameWold();
break;
}
}while(flag);
} else {
System.out.println("您已退出GameWorld!欢迎下次来玩^_^!");
}
}
/**
* 获取线程名
* @return
*/
public String getName(){
return Thread.currentThread().getName();
}
/**
* 判断是否
* @param str 输入结果
* @return True or false
*/
public boolean isTrue(String str) {
if(str.equals("Y")|str.equals("y"))
return true;
else
return false;
}
/**
* 设置睡眠时间
* @param time
*/
public void isSleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 输出:正在进入大厅
*/
public void EnterGameWold() {
System.out.println("正在进入大厅...");
isSleep(500);
}
/**
* 输出开始游戏
*/
public void PrintStarGame() {
System.out.println("游戏开始");
}
/**
* 游戏结束提示
*/
public void PrintEndGame() {
System.out.println("游戏结束!");
}
/**
* 输入错误提示
*/
public void PrintException() {
System.out.println("您的选择不正确");
}
}
/**
* 猜数字
* @author LENOVO
*
*/
public class CaiShuZi{
public void run() {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
Random rand = new Random();
boolean flag = true,isStart = true;
do {
System.out.println("=================猜数规则:=================\n" +
"系统随机生成一个数!请您猜出这个数!\n" +
"如果您给的这个数大于系统给出的则提示:大了\n" +
"如果您给的这个数小于系统给出的则提示:小了\n" +
"如果您给的这个数等于系统给出的则提示:恭喜您!猜对了\n");
System.out.println("--------------------------------------------");
//定义变量
int uScan,cRand,numStart = 0,numEnd = 0,i=0;
System.out.println("输入您想猜的数的范围");
System.out.println("范围开始值:");
numStart = sc.nextInt();
System.out.println("范围结束值:");
numEnd = sc.nextInt();
cRand = rand.nextInt(numEnd-numStart)+numStart+1;
System.out.println("开始猜数!Go...");
while(isStart){
System.out.println("请输入您猜的数:");
//我猜的数
uScan = sc.nextInt();
if(uScan > cRand){
System.out.println("你猜的数大了");
}
if(uScan < cRand) {
System.out.println("您猜的数小了");
}
if(uScan == cRand) {
System.out.println("恭喜您猜对了");
isStart = false;
flag = false;
}
i++;
System.out.println("您一共猜了"+i+"次");
}
}while(flag);
}
}
/**
* 猜拳
* @author LENOVO
*
*/
public class CaiQuan{
public void run() {
// TODO Auto-generated method stub
boolean flag = true;
do {
System.out.println("=======猜拳规则:=======\n1、石头\t2、剪刀\t3、布\n4、结束猜拳游戏");
System.out.println("猜拳开始\n请您出拳:");
Scanner sc = new Scanner(System.in);
Random rand = new Random();
int uPrint,cPrint;
String u = null;
//我出拳
uPrint = sc.nextInt();
switch (uPrint) {
case 1:
u = "石头";
break;
case 2:
u = "剪刀";
break;
case 3:
u = "布";
break;
case 4:
flag = false;
break;
default:
u = "选择错误!视为您不出!为输!";
break;
}
System.out.println(new GameWoldThread().getName()+"出:"+u);
//电脑出拳
cPrint = rand.nextInt(3)+1;
switch (cPrint) {
case 1:
u = "石头";
break;
case 2:
u = "剪刀";
break;
case 3:
u = "布";
break;
}
System.out.println("电脑出:"+u);
if(uPrint == cPrint){
System.out.println("您们平局!");
}else if((uPrint==1&&cPrint==2)||(uPrint==2&&cPrint==3)||(uPrint==3&&cPrint==1)){
System.out.println(new GameWoldThread().getName()+"您赢了");
}else {
System.out.println("您输了");
}
}while(flag);
new GameWoldThread().isSleep(500);
}
}
|