-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspike.rb
75 lines (66 loc) · 2.12 KB
/
spike.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'io/console'
require_relative 'lib/action.rb'
require_relative 'lib/attack_action.rb'
require_relative 'lib/dicepool.rb'
require_relative 'lib/flee_action.rb'
require_relative 'lib/hero.rb'
require_relative 'lib/monster.rb'
hero = Hero.new(strenght: 5, stealth: 5, health: 15, actions: { attack: AttackAction.new, flee: FleeAction.new })
kills = 0
flees = 0
5.times do |number|
toughness = 1 + rand(3)
notice = 1 + rand(2)
damage = 1 + rand(4)
mult = 1 + rand(3)
monster = Monster.new toughness: toughness, notice: notice, damage: damage, exp: toughness * mult, gold: damage * mult
puts "\n\n\n"
puts "=================================="
puts "You're fighting MONSTER #{number + 1 } with:"
puts "\t toughness: #{monster.toughness}"
puts "\t notice: #{monster.notice}"
puts "\t What do you do? (a) for attack, (f) for flee"
puts "==================================="
battle_is_over = false
until battle_is_over
if STDIN.getch == 'a'
hero.activate_action :attack, monster
if monster.dead?
puts "You Won"
puts "You gained #{monster.exp} experience"
puts "You gained #{monster.gold} gold"
puts "============================"
battle_is_over = true
kills+=1
else
puts "You Missed"
puts "Monster deal #{monster.damage} to you"
puts "You are current health is #{hero.health}"
battle_is_over = true if hero.dead?
end
else
hero.activate_action :flee, monster
if hero.fled?
puts "You Coward"
puts "============================="
battle_is_over = true
flees += 1
else
puts "You could not flee"
puts "Monster deal #{monster.damage} to you"
puts "You are current health is #{hero.health}"
puts "============================="
battle_is_over = true if hero.dead?
end
end
end
break if hero.dead?
hero.reset_flee
end
if hero.dead?
puts "\n\n You could not make it"
else
puts "\n\n You WON"
puts "You earned #{hero.gold} gold and #{hero.exp} experience"
puts "You killed monster #{kills} and fled from #{flees}"
end