对于DNF强化操作的个人写法(有待改进)

关于(地下城与勇士(DNF)的装备强化过程):

  1. DNF装备强化在+1~+3 不会失败;
  2. +4~+7,失败后物品原有强化等级降低1级;
  3. +8~+10,失败后掉3级;
    10上11或以上就爆了。
public void win(int targetLevel, int nowLevel) {
		if (targetLevel > nowLevel) {
			System.out.println("恭喜你强化成功,当前等级:" + targetLevel);
		} else {
			System.out.println("强化失败,当前等级:" + targetLevel);
		}
	}

	public void intensify(int nowLevel) {
		int rate = (int) (Math.random() * 100);
		int targetLevel;
		switch (nowLevel) {
		case 0:
		case 1:
		case 2:
			targetLevel = nowLevel + 1;
			System.out.println("恭喜你强化成功,当前等级:" + targetLevel);
			break;

		case 3:
			targetLevel = (rate <= 95 ? nowLevel + 1 : nowLevel - 1);
			win(targetLevel, nowLevel);
			break;

		case 4:
			targetLevel = rate <= 90 ? nowLevel + 1 : nowLevel - 1;
			win(targetLevel, nowLevel);
			break;

		case 5:
			targetLevel = rate <= 80 ? nowLevel + 1 : nowLevel - 1;
			win(targetLevel, nowLevel);
			break;

		case 6:
			targetLevel = rate <= 75 ? nowLevel + 1 : nowLevel - 1;
			win(targetLevel, nowLevel);
			break;

		case 7:
			targetLevel = rate <= 62 ? nowLevel + 1 : nowLevel - 3;
			win(targetLevel, nowLevel);
			break;

		case 8:
			targetLevel = rate <= 53 ? nowLevel + 1 : nowLevel - 3;
			win(targetLevel, nowLevel);
			break;

		case 9:
			targetLevel = rate <= 41 ? nowLevel + 1 : nowLevel - 3;
			win(targetLevel, nowLevel);
			break;

		case 10:
			if (rate <= 33) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;

			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		case 11:
			if (rate <= 28) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;
			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		case 12:
			if (rate <= 20) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;
			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		case 13:
			if (rate <= 17) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;
			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		case 14:
			if (rate <= 13) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;
			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		case 15:
			if (rate <= 10) {
				targetLevel = nowLevel + 1;
				win(targetLevel, nowLevel);
				break;
			} else {
				System.out.println("很遗憾,强化失败,装备损坏");
			}
			break;
		}
	}

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		DnfDemo d = new DnfDemo();
		Scanner sc = new Scanner(System.in);

		System.out.println("强输入物品强化的初始等级:");
		int nowLevel = sc.nextInt();

		d.intensify(nowLevel);
	}

代码实现效果:

手动输入一个初始等级进行强化,根据强化概率强化成功或者强化失败,实现DNF强化效果

  • 结论:该题型涉及到对switch分支结构和随机数写法的熟练运用 *
©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页