/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/js-501-22-007/main.js
36 строк
888 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class Unit { constructor() { this.name = "Имя"; this.intel = 10; this.agility = 10; this.strength = 10; this.health = 100; this.mana = 50; this.level = 1; } get damage() { return (this.intel + this.agility + this.strength) + (this.level * 2); } attack(target) { console.log(`${this.name} атакует ${target.name} и наносит ${this.damage} единиц урона.`); target.health -= this.damage; console.log(`${target.name} теперь имеет ${target.health} здоровья.`); } } const warrior = new Unit(); warrior.name = "Воин"; warrior.intel = 5; warrior.agility = 15; warrior.strength = 30; const mage = new Unit(); mage.name = "Маг"; mage.intel = 35; mage.agility = 10; mage.strength = 5; warrior.attack(mage); mage.attack(warrior);