编辑代码

class Main {
	public class Elf{
        string name;//姓名
        long hp;//血量
        long atk;//攻击力

        public Elf(string name, long hp, long atk){
            this.name = name;
            this.hp = hp;
            this.atk = atk;
        }
        public boolean attack(Elf e){
            long a = (long)(Math.random()*(atk-0+1));
            e.hp -=a;
            System.out.println("攻击信息:"+name+"发起攻击、造成"+a+"点伤害");
            return e.f();
        }
        public boolean f(){
            if (hp<0){
                System.out.println("防守信息:"+name+"死亡");
                return false;
            }
            else {
                System.out.println("防守信息:"+name+"被攻击、剩余血量"+hp);
                return true
            }
        }
    }