/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/ruby/ruby-511-102-001/main.rb
38 строк
791 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
class Unit attr_accessor :name, :intel, :agility, :strength, :health, :mana, :level def initialize @name = "Имя" @intel = 10 @agility = 10 @strength = 10 @health = 100 @mana = 50 @level = 1 end def damage (@intel + @agility + @strength) + (@level * 2) end def attack(target) puts "#{@name} атакует #{target.name} и наносит #{damage} единиц урона." target.health -= damage puts "#{target.name} теперь имеет #{target.health} здоровья." end end warrior = Unit.new warrior.name = "Воин" warrior.intel = 5 warrior.agility = 15 warrior.strength = 30 mage = Unit.new mage.name = "Маг" mage.intel = 35 mage.agility = 10 mage.strength = 5 warrior.attack(mage) mage.attack(warrior)