destiny 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/bin/destiny +25 -25
- data/lib/destiny.rb +95 -101
- data/lib/game_mechanics.rb +316 -250
- data/lib/mobs.rb +153 -74
- data/lib/places.rb +159 -96
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NGIyNWQzNGJkNGYwMmRhMzVkNzM3NTQyZTIyODAyYzI3MGE5Y2UxZA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2c5215d9d7540304babc503b8933c77806e27d9
|
4
|
+
data.tar.gz: b08fabfdc0ef6d28de5dc098ce0dc9b8b7d71f8f
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OGRiNTc1Mzk3OWRhYWUwMjBiZGQ5ZWExMTRmNDkwZTkxZjE3NGZmOWUwMDQy
|
11
|
-
NjQwMWMxM2UwN2QxM2MxMTdlZDRjNmMxNGFkN2I3MDI5OGU1NjQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MDU4YjE2OGRmYzc1ZDY5YWIzMWZhYTU3ZmM1MTY1YTBmY2ZlNmI0NjNiN2Ez
|
14
|
-
NTFhYmQ1OGVjMTEwZmJiMDhkOTJjMjFjZTg1ZGM0MTczYmM2ZTg1NGM3ZDU1
|
15
|
-
MWYzODdjYjQwZjBiMTcwZmFlNDkwZjU3M2Q2ZjA5NDlmZWU0ZDI=
|
6
|
+
metadata.gz: 37634c3daac134cbdbb50d8588fc1149cebdcdaf0b3f83e514d224578e1d078b01d49c92cd87679b8f5cb316531ee20db77b7fe625ed5b5499bcee2d908c1d8e
|
7
|
+
data.tar.gz: 6deb1bdf99cd97851e8dc3e1bb1836a229200f64250534488fd7c5ed7fe844088cf87d33648d3b6be82bac5f2f3b24076addc50f99fe391c459ecd2b88da1a8a
|
data/bin/destiny
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
Dir.chdir(File.dirname(__FILE__))
|
4
|
-
|
5
|
-
require 'destiny'
|
6
|
-
|
7
|
-
puts # formatting
|
8
|
-
puts " " + "_"*53
|
9
|
-
puts "|" + " "*53 + "|"
|
10
|
-
puts "| Welcome to the exciting world of Destiny! |"
|
11
|
-
puts "|" + " "*53 + "|"
|
12
|
-
puts " " + "-"*53
|
13
|
-
puts # formatting
|
14
|
-
puts # formatting
|
15
|
-
puts "Selectable options will normally be enclosed in []'s."
|
16
|
-
puts # formatting
|
17
|
-
if File.exists?('../lib/save_game.json')
|
18
|
-
puts "Would you like to start a new game?"
|
19
|
-
GameSelect.new.outcome
|
20
|
-
puts # formatting
|
21
|
-
else
|
22
|
-
GameSelect.new("yes").outcome
|
23
|
-
end
|
24
|
-
Town.new.choices
|
25
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
Dir.chdir(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'destiny'
|
6
|
+
|
7
|
+
puts # formatting
|
8
|
+
puts " " + "_"*53
|
9
|
+
puts "|" + " "*53 + "|"
|
10
|
+
puts "| Welcome to the exciting world of Destiny! |"
|
11
|
+
puts "|" + " "*53 + "|"
|
12
|
+
puts " " + "-"*53
|
13
|
+
puts # formatting
|
14
|
+
puts # formatting
|
15
|
+
puts "Selectable options will normally be enclosed in []'s."
|
16
|
+
puts # formatting
|
17
|
+
if File.exists?('../lib/save_game.json')
|
18
|
+
puts "Would you like to start a new game?"
|
19
|
+
GameSelect.new.outcome
|
20
|
+
puts # formatting
|
21
|
+
else
|
22
|
+
GameSelect.new("yes").outcome
|
23
|
+
end
|
24
|
+
Town.new.choices
|
25
|
+
|
data/lib/destiny.rb
CHANGED
@@ -1,101 +1,95 @@
|
|
1
|
-
require "json"
|
2
|
-
require "game_mechanics"
|
3
|
-
require "mobs"
|
4
|
-
require "places"
|
5
|
-
|
6
|
-
include GameMechanics
|
7
|
-
|
8
|
-
def choose_name
|
9
|
-
puts #formatting
|
10
|
-
puts "Please enter your new character's name:"
|
11
|
-
prompt; gets.chomp
|
12
|
-
end
|
13
|
-
|
14
|
-
def read_one_line(file_name, line_number)
|
15
|
-
File.open(file_name) do |file|
|
16
|
-
current_line = 1
|
17
|
-
file.each_line do |line|
|
18
|
-
return line.chomp if line_number == current_line
|
19
|
-
current_line += 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class GameSelect
|
25
|
-
attr_accessor :game_select
|
26
|
-
|
27
|
-
def initialize default="default"
|
28
|
-
#rspec with user input is more tricky, this allows me to test
|
29
|
-
@default = default
|
30
|
-
return @
|
31
|
-
yes_no
|
32
|
-
end
|
33
|
-
|
34
|
-
def outcome
|
35
|
-
if @
|
36
|
-
# this is purely for rspec
|
37
|
-
# return "Starting a new game, please answer the following questions:" if @default != "default"
|
38
|
-
begin
|
39
|
-
puts # formatting
|
40
|
-
puts "_"*50
|
41
|
-
puts "Starting a new game, please answer the following questions:"
|
42
|
-
puts "Whould you like to play as a knight or
|
43
|
-
puts "[1]. Knight"
|
44
|
-
puts "[2]. Wizard"
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
puts
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
@player =
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
|
71
|
-
puts #
|
72
|
-
puts
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
# Here I will display both save slots with the character names.
|
97
|
-
"Please select a game to load:"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
1
|
+
require "json"
|
2
|
+
require "game_mechanics"
|
3
|
+
require "mobs"
|
4
|
+
require "places"
|
5
|
+
|
6
|
+
include GameMechanics
|
7
|
+
|
8
|
+
def choose_name
|
9
|
+
puts #formatting
|
10
|
+
puts "Please enter your new character's name:"
|
11
|
+
prompt; gets.chomp
|
12
|
+
end
|
13
|
+
|
14
|
+
def read_one_line(file_name, line_number)
|
15
|
+
File.open(file_name) do |file|
|
16
|
+
current_line = 1
|
17
|
+
file.each_line do |line|
|
18
|
+
return line.chomp if line_number == current_line
|
19
|
+
current_line += 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class GameSelect
|
25
|
+
attr_accessor :game_select
|
26
|
+
|
27
|
+
def initialize default="default"
|
28
|
+
#rspec with user input is more tricky, this allows me to test
|
29
|
+
@default = default
|
30
|
+
return @yes_no = @default if @default != "default"
|
31
|
+
yes_no
|
32
|
+
end
|
33
|
+
|
34
|
+
def outcome
|
35
|
+
if @yes_no == "yes"
|
36
|
+
# this is purely for rspec
|
37
|
+
# return "Starting a new game, please answer the following questions:" if @default != "default"
|
38
|
+
begin
|
39
|
+
puts # formatting
|
40
|
+
puts "_"*50
|
41
|
+
puts "Starting a new game, please answer the following questions:"
|
42
|
+
puts "Whould you like to play as a knight, wizard, cleric, or rogue?"
|
43
|
+
puts "[1]. Knight"
|
44
|
+
puts "[2]. Wizard"
|
45
|
+
puts "[3]. Cleric"
|
46
|
+
puts "[4]. Rogue"
|
47
|
+
prompt; class_choice = gets.chomp
|
48
|
+
end while not (class_choice == "1" or class_choice == "2" or class_choice == "3" or class_choice == "4")
|
49
|
+
begin
|
50
|
+
player_name = choose_name
|
51
|
+
puts #formatting
|
52
|
+
puts "You have chosen #{player_name} as your character's name. Is this correct?"
|
53
|
+
puts "Please enter [yes] to confirm."
|
54
|
+
prompt; confirm_name = STDIN.gets.chomp.downcase
|
55
|
+
end while not (confirm_name == "yes")
|
56
|
+
if class_choice == "1"
|
57
|
+
@player = Knight.new
|
58
|
+
elsif class_choice == "2"
|
59
|
+
@player = Wizard.new
|
60
|
+
elsif class_choice == "3"
|
61
|
+
@player = Cleric.new
|
62
|
+
elsif class_choice == "4"
|
63
|
+
@player = Rogue.new
|
64
|
+
end
|
65
|
+
# Set player name, write attributes to save file, then return player to binary
|
66
|
+
@player.name = "#{player_name}"
|
67
|
+
save_data
|
68
|
+
# Intro for new players
|
69
|
+
puts #formatting
|
70
|
+
puts "Prepare ye, #{@player.name} for great adventure!"
|
71
|
+
puts "Ye are a young #{@player.class} with magnificent deeds ahead of ye!"
|
72
|
+
puts # formatting
|
73
|
+
@player
|
74
|
+
elsif @yes_no == "no"
|
75
|
+
# for rspec
|
76
|
+
return "Loading the existing game." if @default != "default"
|
77
|
+
puts # formatting
|
78
|
+
puts "Loading the existing game."
|
79
|
+
puts # formatting
|
80
|
+
@player = load_data
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
class NewGame
|
87
|
+
# Not using this right now. Later, I hope to support multiple characters and then
|
88
|
+
# I will move the newgame stuff into here. Need a save file with multiple lines support first
|
89
|
+
attr_accessor :save_slot, :char_name
|
90
|
+
|
91
|
+
def initialize new_game
|
92
|
+
@new_game = new_game
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
data/lib/game_mechanics.rb
CHANGED
@@ -1,251 +1,317 @@
|
|
1
|
-
module GameMechanics
|
2
|
-
|
3
|
-
@@save_file = '../lib/save_game.json'
|
4
|
-
|
5
|
-
def prompt
|
6
|
-
print ">> "
|
7
|
-
end
|
8
|
-
|
9
|
-
def yes_no
|
10
|
-
#restrict input to valid answers, but don't worry about case
|
11
|
-
begin
|
12
|
-
puts "Please enter [yes] or [no]:"
|
13
|
-
prompt; @
|
14
|
-
end while not (@
|
15
|
-
end
|
16
|
-
|
17
|
-
def save_data
|
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
|
-
@player.
|
63
|
-
@player.
|
64
|
-
@player.
|
65
|
-
@player
|
66
|
-
|
67
|
-
|
68
|
-
#
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def
|
87
|
-
"
|
88
|
-
end
|
89
|
-
|
90
|
-
def
|
91
|
-
#
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
puts
|
148
|
-
#
|
149
|
-
@player.
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
puts "
|
171
|
-
puts
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
puts
|
176
|
-
puts #
|
177
|
-
puts
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
1
|
+
module GameMechanics
|
2
|
+
|
3
|
+
@@save_file = '../lib/save_game.json'
|
4
|
+
|
5
|
+
def prompt
|
6
|
+
print ">> "
|
7
|
+
end
|
8
|
+
|
9
|
+
def yes_no
|
10
|
+
#restrict input to valid answers, but don't worry about case
|
11
|
+
begin
|
12
|
+
puts "Please enter [yes] or [no]:"
|
13
|
+
prompt; @yes_no = STDIN.gets.chomp.downcase
|
14
|
+
end while not (@yes_no == "yes" or @yes_no == "no")
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_data
|
18
|
+
# increase level as player gets more xp!
|
19
|
+
case
|
20
|
+
when (0..1000).include?(@player.xp)
|
21
|
+
@player.lvl = 1
|
22
|
+
when (1001..2500).include?(@player.xp)
|
23
|
+
@player.lvl = 2
|
24
|
+
when (2501..5000).include?(@player.xp)
|
25
|
+
@player.lvl = 3
|
26
|
+
when (5001..8000).include?(@player.xp)
|
27
|
+
@player.lvl = 4
|
28
|
+
when (8001..11500).include?(@player.xp)
|
29
|
+
@player.lvl = 5
|
30
|
+
when (11501..15000).include?(@player.xp)
|
31
|
+
@player.lvl = 6
|
32
|
+
when (15001..19000).include?(@player.xp)
|
33
|
+
@player.lvl = 7
|
34
|
+
end
|
35
|
+
save_info = {
|
36
|
+
role: @player.class,
|
37
|
+
cur_hp: @player.cur_hp,
|
38
|
+
cur_mana: @player.cur_mana,
|
39
|
+
xp: @player.xp,
|
40
|
+
lvl: @player.lvl,
|
41
|
+
coin: @player.coin,
|
42
|
+
name: @player.name
|
43
|
+
}
|
44
|
+
File.open(@@save_file, "w") do |f|
|
45
|
+
f.write(save_info.to_json)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_data
|
50
|
+
load_info = JSON.parse(File.read(@@save_file))
|
51
|
+
role = load_info['role']
|
52
|
+
if role == "Knight"
|
53
|
+
@player = Knight.new
|
54
|
+
elsif role == "Wizard"
|
55
|
+
@player = Wizard.new
|
56
|
+
elsif role == "Cleric"
|
57
|
+
@player = Cleric.new
|
58
|
+
elsif role == "Rogue"
|
59
|
+
@player = Rogue.new
|
60
|
+
end
|
61
|
+
# Set stats based off information in load_info
|
62
|
+
@player.lvl = load_info['lvl']
|
63
|
+
@player.xp = load_info['xp']
|
64
|
+
@player.coin = load_info['coin']
|
65
|
+
@player.name = load_info['name']
|
66
|
+
@player.cur_hp = load_info['cur_hp']
|
67
|
+
@player.cur_mana = load_info['cur_mana']
|
68
|
+
# Adjust stats based off of player level
|
69
|
+
@player.hp = @player.hp*@player.lvl
|
70
|
+
@player.mana = @player.mana*@player.lvl
|
71
|
+
@player.dmg = @player.dmg*@player.lvl
|
72
|
+
@player
|
73
|
+
# I was trying to do the above assignments with iteration, there has to be a way!
|
74
|
+
# load_info.each do |attribute, value|
|
75
|
+
# @player.#{attribute} = value unless attribute == "role"
|
76
|
+
# end
|
77
|
+
end
|
78
|
+
|
79
|
+
def restore_player
|
80
|
+
# heal the player when they choose to rest in the tavern
|
81
|
+
@player.cur_hp = @player.hp
|
82
|
+
@player.cur_mana = @player.mana
|
83
|
+
save_data
|
84
|
+
end
|
85
|
+
|
86
|
+
def bar_top
|
87
|
+
"_"*27 + " STATS " + "_"*27
|
88
|
+
end
|
89
|
+
|
90
|
+
def stat_bar name, xp, lvl, coin, cur_hp, cur_mana
|
91
|
+
" Name: #{name} | XP: #{xp} | Lvl: #{lvl} | Coin: #{coin} | HP: #{cur_hp} | Mana: #{cur_mana}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def bar_low
|
95
|
+
"-"*61
|
96
|
+
end
|
97
|
+
|
98
|
+
def player_croaks
|
99
|
+
puts # formatting
|
100
|
+
puts "It happens to the best of us #{@player.name}."
|
101
|
+
puts "Fortunately for you, the game of Destiny never ends."
|
102
|
+
puts "The game will exit now and you can restart in town."
|
103
|
+
puts # formatting
|
104
|
+
puts "Better luck next time, eh?"
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
|
108
|
+
def combat bad_guy
|
109
|
+
# create an opponent
|
110
|
+
@bad_guy = bad_guy.new
|
111
|
+
# scale power of opponent to level of player
|
112
|
+
@bad_guy.cur_hp = @bad_guy.hp*@player.lvl
|
113
|
+
@bad_guy.cur_mana = @bad_guy.mana*@player.lvl
|
114
|
+
@bad_guy.dmg = @bad_guy.dmg*@player.lvl
|
115
|
+
puts @bad_guy.name + " says, you kill my father, now you will die!!" unless (@bad_guy.name == "Giant Rat" or @bad_guy.name == "Skeleton")
|
116
|
+
move = 0
|
117
|
+
until move == "2"
|
118
|
+
begin
|
119
|
+
puts # formatting
|
120
|
+
puts bar_low + "--"
|
121
|
+
puts " #{@player.name} - HP: #{@player.cur_hp} - Mana: #{@player.cur_mana} | - VS - | #{@bad_guy.name} - HP: #{@bad_guy.cur_hp} - Mana: #{@bad_guy.cur_mana}"
|
122
|
+
puts bar_low + "--"
|
123
|
+
puts # formatting
|
124
|
+
puts "#{@bad_guy.name} vs. #{@player.name}, what will you do?"
|
125
|
+
puts "[1]. Attack."
|
126
|
+
puts "[2]. Run."
|
127
|
+
prompt; move = gets.chomp
|
128
|
+
end while not (move == "1" or move == "2")
|
129
|
+
case
|
130
|
+
when move == "1"
|
131
|
+
puts # formatting
|
132
|
+
if @player.class.to_s == "Knight"
|
133
|
+
puts "#{@player.name} swings the mighty sword at the #{@bad_guy.name}!"
|
134
|
+
puts # formatting
|
135
|
+
dmg_mod = (@player.str-10)/2 # knights use their str for damage mod
|
136
|
+
@dmg_dlt = dice(@player.dmg) + dmg_mod
|
137
|
+
elsif @player.class.to_s == "Wizard"
|
138
|
+
begin
|
139
|
+
puts "How many magic darts will you shoot?"
|
140
|
+
puts "[1]."
|
141
|
+
puts "[2]." if @player.cur_mana - 2*@player.lvl >= 0
|
142
|
+
puts "[3]." if @player.cur_mana - 3*@player.lvl >= 0
|
143
|
+
prompt; darts = gets.chomp.to_i
|
144
|
+
darts = 4 if darts == 2 and @player.cur_mana - 2*@player.lvl < 0
|
145
|
+
darts = 4 if darts == 3 and @player.cur_mana - 3*@player.lvl < 0
|
146
|
+
end while not (darts == 1 or darts == 2 or darts == 3)
|
147
|
+
puts # formatting
|
148
|
+
puts "#{@player.name} conjures #{darts} magic dart that zips toward the #{@bad_guy.name}." if darts == 1
|
149
|
+
puts "#{@player.name} conjures #{darts} magic darts that zip toward the #{@bad_guy.name}." if darts > 1
|
150
|
+
dmg_mod = (@player.int-10)/2 # wizards use their int for damage mod
|
151
|
+
@dmg_dlt = dice(@player.dmg) + darts*@player.lvl + dmg_mod# more darts more damage, scales with level
|
152
|
+
@player.cur_mana = @player.cur_mana - darts*@player.lvl # more darts more mana spent, scales with level
|
153
|
+
# prevent negative mana, but always allow wizard to shoot at least one dart, no matter what
|
154
|
+
@player.cur_mana = 0 if @player.cur_mana < 0
|
155
|
+
elsif @player.class.to_s == "Cleric"
|
156
|
+
puts "#{@player.name} brings the holy mace thundering down upon #{@bad_guy.name}!"
|
157
|
+
puts # formatting
|
158
|
+
dmg_mod = (@player.str-10)/2 # clerics use their str for damage mod
|
159
|
+
@dmg_dlt = dice(@player.dmg) + dmg_mod + 2 # placeholder holy damage until I get heals in the game.
|
160
|
+
elsif @player.class.to_s == "Rogue"
|
161
|
+
puts "#{@player.name} whirls the razor daggers and strikes at #{@bad_guy.name}!"
|
162
|
+
puts # formatting
|
163
|
+
dmg_mod = (@player.str-10)/2 + (@player.agi-10)/2 # rogues use their str AND agi for damage mod to help
|
164
|
+
@dmg_dlt = dice(@player.dmg) + dmg_mod # make up for lower armor and health points
|
165
|
+
end
|
166
|
+
miss_chance = dice(100)
|
167
|
+
agi_boost = (@bad_guy.agi-10)*2 + @bad_guy.dodge
|
168
|
+
if (1..agi_boost).include?(miss_chance)
|
169
|
+
puts # formatting
|
170
|
+
puts @bad_guy.name + " jumps out of the way, avoiding being hit by " + @player.name + "!"
|
171
|
+
puts # formatting
|
172
|
+
else
|
173
|
+
@dmg_dlt = @dmg_dlt - @bad_guy.armor/4
|
174
|
+
@dmg_dlt = 0 if @dmg_dlt < 1
|
175
|
+
puts #formatting
|
176
|
+
puts "You deal #{@dmg_dlt} damage to the #{@bad_guy.name}." unless @dmg_dlt < 1
|
177
|
+
puts # formatting
|
178
|
+
@bad_guy.cur_hp = @bad_guy.cur_hp - @dmg_dlt
|
179
|
+
end
|
180
|
+
if @bad_guy.cur_hp <= 0
|
181
|
+
puts "You have slain the #{@bad_guy.name} and won the day!"
|
182
|
+
# rewards for winning the battle!
|
183
|
+
@player.xp = @player.xp + @bad_guy.xp
|
184
|
+
@player.coin = @player.coin + @bad_guy.coin
|
185
|
+
save_data
|
186
|
+
return
|
187
|
+
else
|
188
|
+
puts "#{@bad_guy.name} viciously attacks #{@player.name}!"
|
189
|
+
puts # formatting
|
190
|
+
miss_chance = dice(100)
|
191
|
+
agi_boost = (@player.agi-10)*2 + @player.dodge
|
192
|
+
if (1..agi_boost).include?(miss_chance)
|
193
|
+
puts @player.name + " totally leaps out of the way, avoiding being hit by " + @bad_guy.name + "!"
|
194
|
+
else
|
195
|
+
dmg_taken = dice(@bad_guy.dmg) - @player.armor/4
|
196
|
+
dmg_taken = 0 if dmg_taken < 1
|
197
|
+
@player.cur_hp = @player.cur_hp - dmg_taken
|
198
|
+
puts "#{@bad_guy.name} hits YOU for #{dmg_taken} damage!" unless dmg_taken < 1
|
199
|
+
puts "OUCH!" unless dmg_taken < 1
|
200
|
+
end
|
201
|
+
puts #formatting
|
202
|
+
end
|
203
|
+
if @player.cur_hp <= 0
|
204
|
+
puts "You were killed by the #{@bad_guy.name}."
|
205
|
+
puts "Killed dead."
|
206
|
+
player_croaks
|
207
|
+
end
|
208
|
+
when move == "2"
|
209
|
+
puts # formatting
|
210
|
+
puts "Sometimes the right thing to do is run."
|
211
|
+
puts "This is one of those times."
|
212
|
+
puts # formatting
|
213
|
+
puts "You shout what is that? and point frantically in the opposite direction."
|
214
|
+
puts "The #{@bad_guy.name} turns to look and you high tail it away!"
|
215
|
+
puts # formatting
|
216
|
+
run_away = dice(10)
|
217
|
+
case
|
218
|
+
when (1..8).include?(run_away)
|
219
|
+
# you got away this time
|
220
|
+
puts "You escape from the #{@bad_guy.name} while it foolishly looks away."
|
221
|
+
when (9..10).include?(run_away)
|
222
|
+
# not so lucky this time
|
223
|
+
puts "#{@bad_guy.name} says, do you think I was spawned yesterday?"
|
224
|
+
puts # formatting
|
225
|
+
puts "#{@bad_guy.name} viciously attacks #{@player.name}!"
|
226
|
+
puts # formatting
|
227
|
+
miss_chance = dice(100)
|
228
|
+
agi_boost = (@player.agi-10)*2 + @player.dodge
|
229
|
+
if (1..agi_boost).include?(miss_chance)
|
230
|
+
puts @player.name + " totally leaps out of the way, avoiding being hit by " + @bad_guy.name + "!"
|
231
|
+
else
|
232
|
+
dmg_taken = dice(@bad_guy.dmg) - @player.armor/4
|
233
|
+
dmg_taken = 0 if dmg_taken < 1
|
234
|
+
@player.cur_hp = @player.cur_hp - dmg_taken
|
235
|
+
puts "#{@bad_guy.name} hits YOU for #{dmg_taken} damage!" unless dmg_taken < 1
|
236
|
+
puts "OUCH!" unless dmg_taken < 1
|
237
|
+
end
|
238
|
+
puts #formatting
|
239
|
+
if @player.cur_hp <= 0
|
240
|
+
puts "You knew when to fold em, but the #{@bad_guy.name} got the better of you anyway."
|
241
|
+
player_croaks
|
242
|
+
end
|
243
|
+
puts "You manage to accidentally stick a boot firmly in the #{@bad_guy.name}'s face"
|
244
|
+
puts "allowing you to escape!"
|
245
|
+
puts # formatting
|
246
|
+
end
|
247
|
+
save_data
|
248
|
+
return
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
end
|
253
|
+
|
254
|
+
def dice(sides=6,&block)
|
255
|
+
if block_given?
|
256
|
+
block.call(rand(1..sides))
|
257
|
+
else
|
258
|
+
rand(1..sides)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def random_encounter
|
263
|
+
chance = dice(20)
|
264
|
+
case
|
265
|
+
when (1..2).include?(chance)
|
266
|
+
puts # formatting
|
267
|
+
puts "You get the feeling you are being watched..."
|
268
|
+
puts # formatting
|
269
|
+
when (3..4).include?(chance)
|
270
|
+
puts # formatting
|
271
|
+
puts "You notice a coin stuck in the dirt, pry it"
|
272
|
+
puts "loose, and place the coin in your wallet."
|
273
|
+
puts # formatting
|
274
|
+
puts "Today must be your lucky day, #{@player.name}!"
|
275
|
+
@player.xp = @player.xp + @player.lvl*100
|
276
|
+
@player.coin = @player.coin + @player.lvl*2
|
277
|
+
puts # formatting
|
278
|
+
when (5..8).include?(chance)
|
279
|
+
puts #format
|
280
|
+
puts "A small goblin springs from the shadows and attacks!!"
|
281
|
+
puts #format
|
282
|
+
combat(Goblin)
|
283
|
+
when (9..11).include?(chance)
|
284
|
+
puts #format
|
285
|
+
puts "You hear squeeking sounds. BIG squeeking sounds!"
|
286
|
+
puts #format
|
287
|
+
combat(GiantRat)
|
288
|
+
when (12..15).include?(chance)
|
289
|
+
puts #format
|
290
|
+
puts "A kobold peers out of a hole in the wall and then snarls."
|
291
|
+
puts #format
|
292
|
+
combat(Kobold)
|
293
|
+
when (16..18).include?(chance)
|
294
|
+
puts #format
|
295
|
+
puts "Although you have never heard bones scrape across a floor"
|
296
|
+
puts "before, you know without a doubt what approaches..."
|
297
|
+
puts #format
|
298
|
+
combat(Skeleton)
|
299
|
+
when (19..20).include?(chance)
|
300
|
+
puts # formatting
|
301
|
+
trip_event = dice(3)
|
302
|
+
trip_part = "knee" if trip_event == 1
|
303
|
+
trip_part = "elbow" if trip_event == 2
|
304
|
+
trip_part = "hands" if trip_event == 3
|
305
|
+
trip_damage = @player.lvl
|
306
|
+
puts "You stumble and scrape your #{trip_part}."
|
307
|
+
puts "You take #{trip_damage} damage."
|
308
|
+
puts # formatting
|
309
|
+
@player.cur_hp = @player.cur_hp - trip_damage
|
310
|
+
if @player.cur_hp <= 0
|
311
|
+
puts "You have tripped and died."
|
312
|
+
player_croaks
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
251
317
|
end
|