-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmob.rb
More file actions
41 lines (34 loc) · 756 Bytes
/
mob.rb
File metadata and controls
41 lines (34 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require './char.rb'
class Mob < Character
attr_reader :alive
def initialize(name, hp, max_damage, weapon, death = "The #{name} falls quietly to his death.")
super(name)
@hp = hp
@weapon = weapon
@death = death
@alive = true
@max_damage = max_damage
end
def attack(target)
rnd = Random.new(Time.now.to_i)
damage = rnd.rand(@max_damage)
if damage > 0
puts "The #{@name} uses his #{@weapon}!"
target.defend(damage, @name, @weapon)
else
puts "The #{@name} displays his #{@weapon}, but doesn't attack you."
end
end
def defend(damage)
@hp = @hp - damage
if @hp <= 0
die
else
puts "The #{@name} takes #{damage} damage, but has #{@hp} remaining!"
end
end
def die
puts @death
@alive = false
end
end