-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.rb
60 lines (51 loc) · 1.33 KB
/
game.rb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class Character
attr_accessor :hp, :str, :magic
def initialize(hp, str, magic)
@hp = hp
@str = str
@magic = magic
end
def stab
rand(10) + @str / 2
end
def spell
rand(10) + @magic / 2
end
def take_damage(damage)
@hp = @hp - damage
puts "The attack did #{damage} damage!"
end
end
class Player < Character
end
class Enemy < Character
end
block = "================================================"
player = Player.new(100, 20, 20)
orc1 = Enemy.new(30, 10, 0)
orc2 = Enemy.new(30, 10, 0)
puts block
puts "You're sitting in a dark bar with a pint of mead. Two orcs glare at you from across the room; they don't look nice."
puts "Type: [attack], [cast] or [leave]"
puts block
choice = gets.chomp
puts
if choice == "leave"
puts "How boring."
elsif choice == "attack"
orc1.take_damage(player.stab)
puts "That bastard is down to #{orc1.hp} health!"
elsif choice == "cast"
orc1.take_damage(player.spell)
puts "That bastard is down to #{orc1.hp} health!"
else
puts "You're terrible at following directions. Type one of the words between the square brackets."
end
puts
puts "The first orc attacked you!"
player.take_damage(orc1.stab)
puts
puts "The second orc attacked you!"
player.take_damage(orc2.stab)
puts
puts "you are down to #{player.hp} health!"