public class Zombie{ private int health; //僵尸的生命值 private int attack; //僵尸的攻击力 private String name; //僵尸的名字 private boolean alive; //僵尸是否存活

public Zombie(String name, int health, int attack){
    this.name = name;
    this.health = health;
    this.attack = attack;
    this.alive = true;
}

public void attack(Plant plant){
    //僵尸攻击植物
    plant.setHealth(plant.getHealth() - this.attack);
}

public void setHealth(int health){
    this.health = health;
    if (this.health <= 0) {
        this.alive = false;
    }
}

public int getHealth(){
    return this.health;
}

public int getAttack(){
    return this.attack;
}

public String getName(){
    return this.name;
}

public boolean isAlive(){
    return this.alive;
}

}

Java 代码实现植物大战僵尸 - 僵尸类

原文地址: https://www.cveoy.top/t/topic/lgRT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录