/
Vini1979
/
Java_OOP
Обзор
Документация
Войти
/
Vini1979
/
Java_OOP
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
Lecture_01/Ex007/BaseHero.java
49 строк
1 KB
Evgeny
HW 2/5
28 мар 2023, 22:50
28 мар 2023, 22:50
54764ff
Код
Авторство
О чём код?
package Lecture_01.Ex007; import java.util.Random; public class BaseHero { protected static int number; protected static Random r; protected String name; protected int hp; protected int maxHp; static { BaseHero.number = 0; BaseHero.r = new Random(); } public BaseHero(String name, int hp) { this.name = name; this.hp = hp; this.maxHp = hp; } public BaseHero() { this(String.format("Hero_Priest #%d", ++BaseHero.number), BaseHero.r.nextInt(100, 200)); } public String getInfo() { return String.format("Name: %s Hp: %d Type: %s", this.name, this.hp, this.getClass().getSimpleName()); } public void healed(int Hp) { this.hp = Hp + this.hp > this.maxHp ? this.maxHp : Hp + this.hp; } public void GetDamage(int damage) { if (this.hp - damage > 0) { this.hp -= damage; } // else { die(); } } public void Attack(BaseHero target) { int damage = BaseHero.r.nextInt(10, 20); target.GetDamage(damage); } }