/**
* ChuangTaGame.java
* com.oracle.array
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2019年12月9日 17671
*
* Copyright (c) 2019, TNT All Rights Reserved.
*/
package com.oracle.array;
import java.util.Random;
import java.util.Scanner;
/**
* ClassName:闯塔游戏
* Function: TODO ADD FUNCTION
* Reason: TODO ADD REASON
*
* @author 17671
* @version
* @since Ver 1.1
* @Date 2019年12月9日 下午7:18:25
*
* @see
*/
public class ChuangTaGame {
public static int floor=1;
public static Scanner scanner=new Scanner(System.in);
public static void main(String[] args) {
menu();
}
public static void menu() {
boolean flag=true;
while(flag) {
System.out.println("******"+"当前层数"+floor+"**********");
System.out.println("1.战斗");
System.out.println("2.不打了");
System.out.println("****************");
System.out.println("请选择:");
String choice=scanner.nextLine();
switch (choice) {
case "1":
if (getRandom()) {
System.out.println("闯"+floor+"层成功");
floor++;
}else {
System.out.println("闯"+floor+"层失败,再接再厉");
System.out.println("是否继续游戏:1.继续 2.退出");
String choice1=scanner.nextLine();
if (choice1.equals("1")) {
getRandom();
}else {
flag=false;
System.out.println("欢迎下次再玩!");
}
}
break;
case "2":
flag=false;
System.out.println("欢迎下次再玩!");
break;
default:
break;
}
}
}
public static boolean getRandom() {
boolean result=false;
Random random=new Random();
int number=random.nextInt(100);
if (floor<=10) {
if (number<=95) {
result=false;
}
} else if(floor>10&&floor<=20) {
if (number<=85) {
result=true;
}
}else if(floor>20&&floor<=30) {
if (number<=75) {
result=true;
}
}else if(floor>30&&floor<=40) {
if (number<=65) {
result=true;
}
}else {
if (number<=55) {
result=true;
}
}
return result;
}
}
原文地址:https://www.cnblogs.com/aojie/p/12031148.html