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
|
# File 'lib/battle.rb', line 3
def fight
mon = Game::MON_LIST[Game::ROOM_ATTR[Game::PLAYER_ATTR[:player_location_id]][:monster_id]]
puts mon[:monster_intro]
puts "\nFight to survive!"
while mon[:monster_hp] > 0
prompt.keypress("Press space or enter to attack!".red, keys: [:space, :return])
attack = rand(Game::PLAYER_ATTR[:player_attack])
mon[:monster_hp] -= attack
unless mon[:monster_hp] < 0
puts "\n#{mon[:name].upcase.red} - HP #{mon[:monster_hp]}/#{mon[:monster_hp_max]}"
else
puts "\n#{mon[:name].upcase.red} - HP 0/#{mon[:monster_hp_max]}"
end
puts "Using your #{'PAW'.light_green}, you boop the snoot of #{mon[:name].upcase.red} doing #{attack} damage."
if mon[:monster_hp] < 1
break
end
puts mon[:monster_attack_text]
puts "\nYou feel slightly demoralised."
end
Game::ROOM_ATTR[Game::PLAYER_ATTR[:player_location_id]][:monster_defeat?] = true
puts mon[:monster_defeat_text]
puts "\n#{'Victory!'.blue}"
unless mon[:loot].nil?
Game::PLAYER_ATTR[:inventory] << Game::ITEM_LIST[mon[:loot]]
puts "\n#{mon[:name].upcase.red} dropped #{Game::ITEM_LIST[mon[:loot]][:name].upcase.light_green}. You add it to your bag."
end
prompt.keypress("Press space or enter to continue".green, keys: [:space, :return])
unless mon[:monster_defeat_effect].nil?
mon[:monster_defeat_effect].call
end
end
|