/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/php/php-507-18-001/main.php
38 строк
961 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
<?php class Unit { public $name = "Имя"; public $intel = 10; public $agility = 10; public $strength = 10; public $health = 100; public $mana = 50; public $level = 1; public function getDamage() { return ($this->intel + $this->agility + $this->strength) + ($this->level * 2); } public function attack($target) { echo $this->name . " атакует " . $target->name . " и наносит " . $this->getDamage() . " единиц урона." . PHP_EOL; $target->health -= $this->getDamage(); echo $target->name . " теперь имеет " . $target->health . " здоровья." . PHP_EOL; } } $warrior = new Unit(); $warrior->name = "Воин"; $warrior->intel = 5; $warrior->agility = 15; $warrior->strength = 30; $mage = new Unit(); $mage->name = "Маг"; $mage->intel = 35; $mage->agility = 10; $mage->strength = 5; $warrior->attack($mage); $mage->attack($warrior); ?>