java佩恩沃星球打怪掉血实现

public int[] daguai(int arr[]) {
		System.out.println("Do You Want To Play Now(1.yes-2.no)");
		int a = new Scanner(System.in).nextInt();
		int pblood = arr[0];
		int pattack = arr[1];
		int pdefase = arr[2];
		int mblood = arr[3];
		int mattack = arr[4];
		int mdefase = arr[5];
		if (a == 1) {
			System.out.println("玩家的生命值" + pblood + "玩家的攻击力" + pattack
					+ "玩家的防御力" + pdefase);
			System.out.println("怪物的生命值" + mblood + "怪物的攻击力" + mattack
					+ "怪物的防御力" + mdefase);
			System.out.println("Monster Is Right|attacking nums?(times)");
			while (mblood > 0 || pblood > 0) {
				System.out.println("请输入攻击次数");
				int b = new Scanner(System.in).nextInt();
				int rand = new Random().nextInt();
				for (int i = 0; i < 2 * b; i++) {
					// 这是玩家打怪物
					if (i % 2 != 1) {
						// 随机出来玩家的伤害
						System.out.println("*************");
						try {
							Thread.sleep(40);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						int randp = new Random().nextInt(2) + 5;
						// System.out.println(randp+"随机数");
						pblood = pblood - randp * (1 - pdefase / 100);
						System.out.println("--玩家在流血" + pblood);
						if (pblood < 0) {
							System.out.println("--玩家死了" + pblood);
							break;
						}
					} else if (i % 2 == 1) {// 这是玩家被怪物打
						try {
							Thread.sleep(40);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						int randm = new Random().nextInt(2) + 5;
						mblood = mblood - randm * (1 - mdefase / 100);
						// System.out.println(randm+"随机数");
						System.out.println("怪物正在流血" + mblood);
						if (mblood < 0) {
							System.out.println("--怪物死了" + mblood);
							break;
						}
					}
				}
				int resb[] = { pblood, pattack, pdefase, mblood, mattack,
						mdefase };
				for (int i = 0; i < resb.length; i++) {
					System.out.print("%" + resb[i]);
				}
				// System.out.println("()"+pblood+"**"+pattack+"**"+pdefase);
				// System.out.println(mblood+"**"+mattack+"**"+mdefase);
				return resb;
			}
		}

		return null;
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值