java语言 解决设计游戏类小问题

img


该图片为本题的相关要求点,回答需要源代码和编译框和输入框一起的图片截图 语句中有适当注释

public class Person {
    //生命值
    private int lifeValue;
    //攻击力
    private int attackPower;
    //消耗资源数
    private int needResourse;
    //进攻
    public void attack() {
        System.out.println("进攻");
    }
}

public class Sapper extends Person {
    //创建建筑
    public void createConstruction(){}
    //采集资源
    public void collectResource(){}
}

public class Nurse extends Person {
    //疗伤
    public void cure(){}
}

public class Construction {
    //生命值
    private int lifeValue;
    //消耗资源数
    private int needResourse;
}

public class Player {
    //玩家名称
    private String playerName;
    //玩家资源值
    private int playerResource;
    //玩家拥有人口
    private Person person;
    //玩家拥有建筑
    private Construction construction;

    public Player(String playerName, int playerResource, Person person, Construction construction) {
        this.playerName = playerName;
        this.playerResource = playerResource;
        this.person = person;
        this.construction = construction;
    }

    public Person getPerson() {
        return person;
    }

    public Construction getConstruction() {
        return construction;
    }
}

public class RandomTest {

    public static void main(String[] args) {
        Player player1 = new Player("玩家1", 100, new Person(),
                new Construction());
        Player player2 = new Player("玩家2", 100, new Person(),
                new Construction());
        player1.getPerson().attack();
        player2.getPerson().attack();
    }


}

img