日期:2014-05-20 浏览次数:20792 次
package src.com.refine; public class Refine { /** * @param args */ public static void main(String[] args) { // TODO 自动生成方法存根 getTimesByLever(12); } /** * 获取炼器成功几率 * */ public static double getSuccess(int level){ double successPercent=0.00; if(level==0){successPercent=0.90;} if(level==1){successPercent=0.80;} if(level==2){successPercent=0.70;} if(level==3){successPercent=0.60;} if(level==4){successPercent=0.55;} if(level==5){successPercent=0.50;} if(level==6){successPercent=0.45;} if(level==7){successPercent=0.40;} if(level==8){successPercent=0.35;} if(level==9){successPercent=0.30;} if(level==10){successPercent=0.25;} if(level==11){successPercent=0.20;} if(level==12){successPercent=0.18;} if(level==13){successPercent=0.15;} if(level==14){successPercent=0.12;} if(level==15){successPercent=0.10;} return successPercent; } /** * 根据精炼等级炼器是否成功 * 返回boolean */ public static boolean successOrNot(int level){ boolean isOrNot=true; double successPercent=0.00; double mathRandom=0.00; //通过等级获取成功率 successPercent=getSuccess(level); //随机获取几率 mathRandom=Math.random(); //输出成功几率 System.out.println("成功几率:"+successPercent); System.out.println("随机数:"+mathRandom); if(mathRandom<successPercent){ isOrNot=true; //成功 }else{ isOrNot=false; } return isOrNot; } /** * 通过精炼等级获取炼器要达到的次数 * @param lever */ public static void getTimesByLever(int level){ int times=0; for (int i = 0; i <= level; i++) { times=times+1; System.out.println("当前精炼等级:"+"+"+(i-1)); boolean isOrNot=successOrNot(i); System.out.println("是否成功:"+isOrNot+"\n"); if(isOrNot==false){ i-=2; if(i<0){ i=0; } } } System.out.println("一共消费: "+times+" 个完毕"); System.out.println("当前精炼等级:"+"+"+level); } }
public static double getSuccess(int level) { double[] successPercent= new double[] { 0.90, /* 0 */ 0.80, /* 1 */ 0.70, /* 2 */ 0.60, /* 3 */ 0.55, /* 4 */ 0.50, /* 5 */ 0.45, /* 6 */ 0.40, /* 7 */ 0.35, /* 8 */ 0.30, /* 9 */ 0.25, /* 10 */ 0.20, /* 11 */ 0.18, /* 12 */ 0.15, /* 13 */ 0.12, /* 14 */ 0.10 /* 15 */ }; return (level>=0 && level<successPercent.length) ? successPercent[level] : 0.00; }