Java实现——地下城与勇士DNF武器强化(+0——+16)
DNF中强化装备能够为装备增加攻击力,从而增加角色的攻击力。强化的等级越高,增加的攻击越高,但强化装备有着一定的失败
1.运行样例
- 强化规则
0~3不会失败
4-7失败不会掉等级
8-10失败掉一级
10→11失败掉7
11→12失败掉8
12以后失败炸
- 强化几率
1-3 —— 1
3-4 ——0.95
4-5 ——0.9
5-6 —— 0.8
6-7 ——0.75
7-8 ——0.621
8-9 ——0.537
9-10 —— 0.414
10-11 ——0.339
11-12 ——0.207
12-13 ——0.28
13-14 —— 0.173
14-15 —— 0.136
15-16 —— 0.101
2.强化方法(实现强化)
publicstaticintqianghua(intlever) { switch (lever) { case0: case1: case2: lever++; break; case3: if (Math.random() <=0.95) { ++lever; } break; case4: if (Math.random() <=0.90) { ++lever; } break; case5: if (Math.random() <=0.8) { ++lever; } break; case6: if (Math.random() <=0.75) { ++lever; } break; case7: if (Math.random() <=0.621) { ++lever; } break; case8: if (Math.random() <=0.537) ++lever; else--lever; break; case9: if (Math.random() <=0.414) ++lever; else--lever; break; case10: if (Math.random() <=0.339) { ++lever; } elselever-=3; break; case11: if (Math.random() <=0.28) { ++lever; } elselever-=3; break; case12: if (Math.random() <=0.207) { ++lever; } elselever=0; break; case13: if (Math.random() <=0.173) { ++lever; } elselever=0; break; case14: if (Math.random() <=0.136) { ++lever; } elselever=0; break; case15: if (Math.random() <=0.101) { ++lever; } elselever=0; break; } returnlever; }
源码
importjava.util.Scanner; /*地下城强化*/publicclassTest { publicstaticvoidmain(String[] args) { intlever; booleanflag=false; Scannerscan=newScanner(System.in); System.out.println("------------------------"); System.out.println("--------强------化-------"); System.out.println("------------------------"); while (true) { System.out.println("武器自身强化等级:"); lever=scan.nextInt(); if (lever==16) { System.out.println("武器强化到顶"+"+16"); } elseif (lever>16||lever<0) { System.out.println("输入不合法,请重新输入"); } else { flag=true; break; } } if (flag) { System.out.println("要强化武器吗?Y/N"); if ("Y".equals(scan.next())) { while (flag) { System.out.println("------开始强化------"); if(flag==false){ System.out.println("武器已破碎,请放入武器"); } intn=lever; lever=qianghua(lever); if (lever==0) { flag=false; System.out.println("强化失败,武器破碎"); } elseif(n>=lever){ System.out.println("强化失败:+"+lever); }elseif(n<lever){ System.out.println("强化成功:+"+lever); } if(flag){ System.out.println("要继续强化吗?y/n"); if ("n".equals(scan.next())){ System.out.println("退出强化"); break; } }else { System.out.println("武器已破碎"); break; } } } } } publicstaticintqianghua(intlever) { switch (lever) { case0: case1: case2: lever++; break; case3: if (Math.random() <=0.95) { ++lever; } break; case4: if (Math.random() <=0.90) { ++lever; } break; case5: if (Math.random() <=0.8) { ++lever; } break; case6: if (Math.random() <=0.75) { ++lever; } break; case7: if (Math.random() <=0.621) { ++lever; } break; case8: if (Math.random() <=0.537) ++lever; else--lever; break; case9: if (Math.random() <=0.414) ++lever; else--lever; break; case10: if (Math.random() <=0.339) { ++lever; } elselever-=3; break; case11: if (Math.random() <=0.28) { ++lever; } elselever-=3; break; case12: if (Math.random() <=0.207) { ++lever; } elselever=0; break; case13: if (Math.random() <=0.173) { ++lever; } elselever=0; break; case14: if (Math.random() <=0.136) { ++lever; } elselever=0; break; case15: if (Math.random() <=0.101) { ++lever; } elselever=0; break; } returnlever; } }