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.
Files changed (7) hide show
  1. checksums.yaml +5 -13
  2. data/bin/destiny +25 -25
  3. data/lib/destiny.rb +95 -101
  4. data/lib/game_mechanics.rb +316 -250
  5. data/lib/mobs.rb +153 -74
  6. data/lib/places.rb +159 -96
  7. metadata +3 -3
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YmJkMmRiZDJhNDNiYjk5ZTdkNzhjZTViY2VmNDc2ZjA0NDkyZDYzZA==
5
- data.tar.gz: !binary |-
6
- NGIyNWQzNGJkNGYwMmRhMzVkNzM3NTQyZTIyODAyYzI3MGE5Y2UxZA==
2
+ SHA1:
3
+ metadata.gz: a2c5215d9d7540304babc503b8933c77806e27d9
4
+ data.tar.gz: b08fabfdc0ef6d28de5dc098ce0dc9b8b7d71f8f
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZjUzMzcwMGMzNGNkYWZiMTFlZWNkMDRhMjYyZjA2YWY2YTU4ZWJjNWVjOWEz
10
- OGRiNTc1Mzk3OWRhYWUwMjBiZGQ5ZWExMTRmNDkwZTkxZjE3NGZmOWUwMDQy
11
- NjQwMWMxM2UwN2QxM2MxMTdlZDRjNmMxNGFkN2I3MDI5OGU1NjQ=
12
- data.tar.gz: !binary |-
13
- MDU4YjE2OGRmYzc1ZDY5YWIzMWZhYTU3ZmM1MTY1YTBmY2ZlNmI0NjNiN2Ez
14
- NTFhYmQ1OGVjMTEwZmJiMDhkOTJjMjFjZTg1ZGM0MTczYmM2ZTg1NGM3ZDU1
15
- MWYzODdjYjQwZjBiMTcwZmFlNDkwZjU3M2Q2ZjA5NDlmZWU0ZDI=
6
+ metadata.gz: 37634c3daac134cbdbb50d8588fc1149cebdcdaf0b3f83e514d224578e1d078b01d49c92cd87679b8f5cb316531ee20db77b7fe625ed5b5499bcee2d908c1d8e
7
+ data.tar.gz: 6deb1bdf99cd97851e8dc3e1bb1836a229200f64250534488fd7c5ed7fe844088cf87d33648d3b6be82bac5f2f3b24076addc50f99fe391c459ecd2b88da1a8a
@@ -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
+
@@ -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 @game_select = @default if @default != "default"
31
- yes_no
32
- end
33
-
34
- def outcome
35
- if @game_select == "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 or wizard?"
43
- puts "[1]. Knight"
44
- puts "[2]. Wizard"
45
- prompt; class_choice = gets.chomp
46
- end while not (class_choice == "1" or class_choice == "2")
47
- begin
48
- player_name = choose_name
49
- puts #formatting
50
- puts "You have chosen #{player_name} as your character's name. Is this correct?"
51
- puts "Please enter [yes] to confirm."
52
- prompt; confirm_name = STDIN.gets.chomp.downcase
53
- end while not (confirm_name == "yes")
54
- if class_choice == "1"
55
- @player = Knight.new
56
- elsif class_choice == "2"
57
- @player = Wizard.new
58
- end
59
- # Set player name, write attributes to save file, then return player to binary
60
- @player.name = "#{player_name}"
61
- save_data
62
- # Intro for new players
63
- puts #formatting
64
- puts "Prepare ye, #{@player.name} for great adventure!"
65
- puts "Ye are a young #{@player.class} with magnificent deeds ahead of ye!"
66
- puts # formatting
67
- @player
68
- elsif @game_select == "no"
69
- # for rspec
70
- return "Loading the existing game." if @default != "default"
71
- puts # formatting
72
- puts "Loading the existing game."
73
- puts # formatting
74
- @player = load_data
75
- end
76
- end
77
-
78
- end
79
-
80
- class NewGame
81
- attr_accessor :save_slot, :char_name
82
-
83
- def initialize new_game
84
- @new_game = new_game
85
- end
86
-
87
- def answer_was game_select="yes"
88
- @game_select = game_select
89
- #should probably be a case statement that verifies that only yes, y, no, or n was entered
90
- # and ignores caps (lower and upper are valid)
91
- if @game_select == "yes"
92
- puts # formatting
93
- puts "Starting a new game, please enter character name:"
94
- # @character_name = gets
95
- else
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
@@ -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; @game_select = STDIN.gets.chomp.downcase
14
- end while not (@game_select == "yes" or @game_select == "no")
15
- end
16
-
17
- def save_data
18
- case
19
- when (0..1000).include?(@player.xp)
20
- @player.lvl = 1
21
- when (1001..2500).include?(@player.xp)
22
- @player.lvl = 2
23
- when (2501..5000).include?(@player.xp)
24
- @player.lvl = 3
25
- when (5001..8000).include?(@player.xp)
26
- @player.lvl = 4
27
- when (8001..11500).include?(@player.xp)
28
- @player.lvl = 5
29
- when (11501..15000).include?(@player.xp)
30
- @player.lvl = 6
31
- end
32
- save_info = {
33
- role: @player.class,
34
- cur_hp: @player.cur_hp,
35
- cur_mana: @player.cur_mana,
36
- xp: @player.xp,
37
- lvl: @player.lvl,
38
- coin: @player.coin,
39
- name: @player.name
40
- }
41
- File.open(@@save_file, "w") do |f|
42
- f.write(save_info.to_json)
43
- end
44
- end
45
-
46
- def load_data
47
- load_info = JSON.parse(File.read(@@save_file))
48
- role = load_info['role']
49
- if role == "Knight"
50
- @player = Knight.new
51
- elsif role == "Wizard"
52
- @player = Wizard.new
53
- end
54
- # Set stats based off information in load_info
55
- @player.lvl = load_info['lvl']
56
- @player.xp = load_info['xp']
57
- @player.coin = load_info['coin']
58
- @player.name = load_info['name']
59
- @player.cur_hp = load_info['cur_hp']
60
- @player.cur_mana = load_info['cur_mana']
61
- # Adjust stats based off player level
62
- @player.hp = @player.hp*@player.lvl
63
- @player.mana = @player.mana*@player.lvl
64
- @player.dmg = @player.dmg*@player.lvl
65
- @player
66
- # I was trying to do the above assignments with iteration, there has to be a way!
67
- # load_info.each do |attribute, value|
68
- # @player.#{attribute} = value unless attribute == "role"
69
- # end
70
- end
71
-
72
- def restore_player
73
- @player.cur_hp = @player.hp
74
- @player.cur_mana = @player.mana
75
- save_data
76
- end
77
-
78
- def bar_top
79
- "_"*27 + " STATS " + "_"*27
80
- end
81
-
82
- def stat_bar name, xp, lvl, coin, cur_hp, cur_mana
83
- " Name: #{name} | XP: #{xp} | Lvl: #{lvl} | Coin: #{coin} | HP: #{cur_hp} | Mana: #{cur_mana}"
84
- end
85
-
86
- def bar_low
87
- "-"*61
88
- end
89
-
90
- def combat bad_guy
91
- # create an opponent
92
- @bad_guy = bad_guy.new
93
- # scale power of opponent to level of player
94
- @bad_guy.cur_hp = @bad_guy.hp*@player.lvl
95
- @bad_guy.cur_mana = @bad_guy.mana*@player.lvl
96
- @bad_guy.dmg = @bad_guy.dmg*@player.lvl
97
- puts @bad_guy.name + " says, you kill my father, now you will die!!" unless (@bad_guy.name == "ROUS" or @bad_guy.name == "Skeleton")
98
- move = 0
99
- until move == "2"
100
- begin
101
- puts # formatting
102
- puts bar_low + "--"
103
- 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}"
104
- puts bar_low + "--"
105
- puts # formatting
106
- puts "#{@bad_guy.name} vs. #{@player.name}, what will you do?"
107
- puts "[1]. Attack."
108
- puts "[2]. Run."
109
- prompt; move = gets.chomp
110
- end while not (move == "1" or move == "2")
111
- case
112
- when move == "1"
113
- puts # formatting
114
- if @player.class.to_s == "Knight"
115
- puts "#{@player.name} swings the mighty sword at the #{@bad_guy.name}."
116
- puts # formatting
117
- dmg_mod = (@player.str-10)/2 # knights use their str for damage mod
118
- @dmg_dlt = dice(@player.dmg) + dmg_mod
119
- elsif @player.class.to_s == "Wizard"
120
- begin
121
- puts "How many magic darts will you shoot?"
122
- puts "[1]."
123
- puts "[2]."
124
- puts "[3]."
125
- prompt; darts = gets.chomp.to_i
126
- end while not (darts == 1 or darts == 2 or darts == 3)
127
- puts # formatting
128
- puts "#{@player.name} conjures #{darts} magic darts that zip toward the #{@bad_guy.name}."
129
- dmg_mod = (@player.int-10)/2 # wizards use their int for damage mod
130
- @dmg_dlt = dice(@player.dmg) + darts*@player.lvl + dmg_mod# more darts more damage, scales with level
131
- @player.cur_mana = @player.cur_mana - darts*@player.lvl # more darts more mana spent, scales with level
132
- end
133
- miss_chance = dice(100)
134
- agi_boost = (@bad_guy.agi-10)*2 + @bad_guy.dodge
135
- if (1..agi_boost).include?(miss_chance)
136
- puts @bad_guy.name + " jumps out of the way, avoiding being hit by " + @player.name + "!"
137
- puts # formatting
138
- else
139
- @dmg_dlt = @dmg_dlt - @bad_guy.armor/4
140
- @dmg_dlt = 0 if @dmg_dlt < 1
141
- puts #formatting
142
- puts "You deal #{@dmg_dlt} damage to the #{@bad_guy.name}." unless @dmg_dlt < 1
143
- puts # formatting
144
- @bad_guy.cur_hp = @bad_guy.cur_hp - @dmg_dlt
145
- end
146
- if @bad_guy.cur_hp <= 0
147
- puts "You have slain the #{@bad_guy.name} and won the day!"
148
- # rewards for winning the battle!
149
- @player.xp = @player.xp + @bad_guy.xp
150
- @player.coin = @player.coin + @bad_guy.coin
151
- save_data
152
- return
153
- else
154
- puts "#{@bad_guy.name} viciously attacks #{@player.name}!"
155
- puts # formatting
156
- miss_chance = dice(100)
157
- agi_boost = (@player.agi-10)*2 + @player.dodge
158
- if (1..agi_boost).include?(miss_chance)
159
- puts @player.name + " totally leaps out of the way, avoiding being hit by " + @bad_guy.name + "!"
160
- else
161
- dmg_taken = dice(@bad_guy.dmg) - @player.armor/4
162
- dmg_taken = 0 if dmg_taken < 1
163
- @player.cur_hp = @player.cur_hp - dmg_taken
164
- puts "#{@bad_guy.name} hits YOU for #{dmg_taken} damage!" unless dmg_taken < 1
165
- puts "OUCH!" unless dmg_taken < 1
166
- end
167
- puts #formatting
168
- end
169
- if @player.cur_hp <= 0
170
- puts "You were killed by the #{@bad_guy.name}."
171
- puts "Killed dead."
172
- puts # formatting
173
- puts "It happens to the best of us #{@player.name}."
174
- puts "Fortunately for you, the game of Destiny never ends."
175
- puts "The game will exit now and you can restart in town."
176
- puts # formatting
177
- puts "Better luck next time, eh?"
178
- exit
179
- end
180
- when move == "2"
181
- puts # formatting
182
- puts "Sometimes the right thing to do is run."
183
- puts "This is one of those times."
184
- puts # formatting
185
- puts "You shout what is that? and point frantically in the opposite direction."
186
- puts "The #{@bad_guy.name} turns to look and you high tail it away!"
187
- save_data
188
- return
189
- end
190
- end
191
-
192
- end
193
-
194
- def dice(sides=6,&block)
195
- if block_given?
196
- block.call(rand(1..sides))
197
- else
198
- rand(1..sides)
199
- end
200
- end
201
-
202
- def random_encounter
203
- chance = dice(20)
204
- case
205
- when (1..2).include?(chance)
206
- puts # formatting
207
- puts "You get the feeling you are being watched..."
208
- puts # formatting
209
- when (3..4).include?(chance)
210
- puts # formatting
211
- puts "You notice a coin stuck in the dirt, pry it loose,"
212
- puts "and place the coin in your wallet."
213
- puts "Today must be your lucky day, #{@player.name}!"
214
- @player.xp = @player.xp + 50
215
- @player.coin = @player.coin + 1
216
- puts # formatting
217
- when (5..8).include?(chance)
218
- puts #format
219
- puts "A small goblin springs from the shadows and attacks!!"
220
- puts #format
221
- combat(Goblin)
222
- when (9..11).include?(chance)
223
- puts #format
224
- puts "You hear squeeking sounds. BIG squeeking sounds!"
225
- puts #format
226
- combat(GiantRat)
227
- when (12..15).include?(chance)
228
- puts #format
229
- puts "A kobold peers out of a hole in the wall and then snarls."
230
- puts #format
231
- combat(Kobold)
232
- when (16..18).include?(chance)
233
- puts #format
234
- puts "Although you have never heard bones scrape across a floor"
235
- puts "before, you know without a doubt what approaches..."
236
- puts #format
237
- combat(Skeleton)
238
- when (19..20).include?(chance)
239
- puts # formatting
240
- trip_event = dice(3)
241
- trip_part = "knee" if trip_event == 1
242
- trip_part = "elbow" if trip_event == 2
243
- trip_part = "hands" if trip_event == 3
244
- puts "You stumble and scrape your #{trip_part}."
245
- puts "You take 1 damage."
246
- puts # formatting
247
- @player.cur_hp = @player.cur_hp - 1
248
- end
249
- end
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