package com.junbao.learn;
import java.util.Random;
import java.util.Scanner;
public class ArrayDemo5 {
public static void main(String[] args) {
System.out.println("欢迎来到王者荣耀!");
System.out.println("请选择英雄");
System.out.println("1.猴子");
System.out.println("2.韩信");
System.out.println("3.澜");
System.out.println("4.孙尚香");
Scanner scanner = new Scanner(System.in);
int i = scanner.nextInt();
switch (i){
case 1:
System.out.println("选择 猴子 成功!");
break;
case 2:
System.out.println("选择 韩信 成功!");
break;
case 3:
System.out.println("选择 澜 成功!");
break;
case 4:
System.out.println("选择 孙尚香 成功!");
break;
}
System.out.println("请选择敌方英雄");
System.out.println("1.镜");
System.out.println("2.百里守约");
System.out.println("3.妲己");
System.out.println("4.李信");
Scanner scanner1 = new Scanner(System.in);
int i1 = scanner1.nextInt();
if (i1 == 1){
System.out.println("敌方选择 孙尚香 成功!");
}else if (i1 == 2){
System.out.println("敌方选择 百里守约 成功!");
}else if (i1 == 3){
System.out.println("敌方选择 妲己 成功!");
}else if (i1 == 4){
System.out.println("敌方选择 李信 成功!");
}
//定义英雄血量
//定义蓝方英雄血量 100
int my = 100;
//定义敌方英雄血量 100
int you = 100;
//定义变量 ,判断循环
boolean isDead = true;
while (isDead){
//每次攻击 的伤害 0-20之间
int nextInt = new Random().nextInt(20);
if (my > 0){
System.out.println("我方英雄攻击敌方英雄");
if (you - nextInt > 0){
you = you - nextInt;
}else {
you = 0;
isDead = false;
}
System.out.println("敌方英雄受到"+nextInt+"点伤害,剩余血量"+you);
if (you == 0){
System.out.println("恭喜你,获得胜利");
System.out.println("游戏结束,我方胜利");
}
}
if (you > 0){
System.out.println("敌方英雄攻击我方英雄");
int nextInt1 = new Random().nextInt(20);
if (my - nextInt1 > 0){
my = my - nextInt1;
}else {
my = 0;
isDead = false;
}
System.out.println("我方英雄受到"+nextInt1+"点伤害,剩余血量"+my);
if (my == 0){
System.out.println("很遗憾,继续努力");
System.out.println("游戏结束,敌方方胜利");
}
}
System.out.println("===============");
}
//谁的血为 0 ,就代表输了
}
}
讲课「2」java基础版王者荣耀
最新推荐文章于 2023-11-28 12:41:49 发布