destiny 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2495d4b0effe8a244327c9b09c6c0aec2f613e36
4
- data.tar.gz: c8b5259d2475af0a3f21d2fa3921971111a98467
3
+ metadata.gz: 71528913273e887206aa8b6c88d484b3665c5886
4
+ data.tar.gz: b4fc818bc75a7fc1b5fef413d9e806c260d054b2
5
5
  SHA512:
6
- metadata.gz: 96cff8084be0603aff5066b8fbd1c01430961f634be55d83745a141c3f955eb717e4300bce641b98b746ae9dd0a63dfd19900c108c1e78bf1614138e8c318096
7
- data.tar.gz: 351e328f3821e4265f4b9031f665ede5b88a6675a3790ee36a750eaa247ff27d70d7eafc16b764251a3526307dfb679f75c5a7b1db5586e2bf5d54ea445ddb2b
6
+ metadata.gz: 44afd297308dafc321fb6cd8caf1d13ace7e254eb3af10ebe6baf793ab69e0da59a84e4ac61dbc7316fac2757c97cbe34cb4a7ae99c082402607d6401d3f14ed
7
+ data.tar.gz: 421c2281bcc2d434a8cc6fc27ad0d79f7395d01ed373139f89573045b0c6c758bc3bf9832c91b14a1c6560738307b960c2ce5209becf02d3610e5b25103eb404
@@ -7,12 +7,12 @@ require 'destiny'
7
7
  puts # formatting
8
8
  puts " " + "_"*53
9
9
  puts "|" + " "*53 + "|"
10
- puts "| Welcome to the exciting world of Destiny! |"
10
+ puts "| " + "Welcome to the exciting world of Destiny!".yellow + " |"
11
11
  puts "|" + " "*53 + "|"
12
12
  puts " " + "-"*53
13
13
  puts # formatting
14
14
  puts # formatting
15
- puts "Selectable options will normally be enclosed in []'s."
15
+ puts "Selectable options will normally be enclosed in " + "[]".yellow + "'s."
16
16
  puts # formatting
17
17
  if File.exists?('../lib/save_game.json')
18
18
  puts "Would you like to start a new game?"
@@ -0,0 +1,38 @@
1
+ require 'colorize'
2
+
3
+ class Choice
4
+ attr_reader :choices
5
+
6
+ def initialize msg, choices
7
+ @msg = msg
8
+ @choices = choices
9
+ end
10
+
11
+ def prompt
12
+ put_prompt_msg
13
+ get_prompt_resp
14
+ end
15
+
16
+ def to_s
17
+ @choices
18
+ end
19
+
20
+ def add(command, msg)
21
+ @choices[command] = msg
22
+ end
23
+
24
+ private
25
+ def put_prompt_msg
26
+ p = []
27
+ p << @msg
28
+ @choices.each do |key, description|
29
+ p << "[#{key}] ".yellow + description
30
+ end
31
+ puts "#{p.join("\n")}\n"
32
+ end
33
+
34
+ def get_prompt_resp
35
+ gets.chomp
36
+ end
37
+
38
+ end
@@ -2,6 +2,7 @@ require "json"
2
2
  require "game_mechanics"
3
3
  require "mobs"
4
4
  require "places"
5
+ require "choice"
5
6
 
6
7
  include GameMechanics
7
8
 
@@ -37,12 +38,14 @@ class GameSelect
37
38
  puts # formatting
38
39
  puts "_"*50
39
40
  puts "Starting a new game, please answer the following questions:"
40
- puts "Whould you like to play as a knight, wizard, cleric, or rogue?"
41
- puts "[1]. Knight"
42
- puts "[2]. Wizard"
43
- puts "[3]. Cleric"
44
- puts "[4]. Rogue"
45
- prompt; class_choice = gets.chomp
41
+ c = Choice.new "Whould you like to play as a knight, wizard, cleric, or rogue?",
42
+ {
43
+ "1" => "Knight",
44
+ "2" => "Wizard",
45
+ "3" => "Cleric",
46
+ "4" => "Rogue"
47
+ }
48
+ class_choice = c.prompt
46
49
  end while not (class_choice == "1" or class_choice == "2" or class_choice == "3" or class_choice == "4")
47
50
  begin
48
51
  player_name = choose_name
@@ -78,16 +81,16 @@ class GameSelect
78
81
  @player = load_data
79
82
  end
80
83
  end
81
-
84
+
82
85
  end
83
86
 
84
87
  class NewGame
85
88
  # Not using this right now. Later, I hope to support multiple characters and then
86
89
  # I will move the newgame stuff into here. Need a save file with multiple lines support first
87
90
  attr_accessor :save_slot, :char_name
88
-
91
+
89
92
  def initialize new_game
90
93
  @new_game = new_game
91
94
  end
92
-
95
+
93
96
  end
@@ -0,0 +1,49 @@
1
+ require 'edge_coloring_graph'
2
+ require 'choice'
3
+
4
+ DoorNames = {
5
+ :w => 'wooden door',
6
+ :i => 'iron door',
7
+ :c => 'crack in the wall',
8
+ :r => 'rusty door'
9
+ }
10
+
11
+ class DungeonMap
12
+ def initialize map
13
+ @map = map
14
+ end
15
+
16
+ def door_to current_location, command
17
+ doors = doors_at current_location
18
+ if doors[command.to_sym]
19
+ return doors[command.to_sym]
20
+ else
21
+ return current_location
22
+ end
23
+ end
24
+
25
+ def choices location
26
+ doors = doors_at location
27
+ door_choices = {}
28
+ doors.keys.each do |command|
29
+ door_choices[command.to_sym] = "Go through the #{DoorNames[command]}."
30
+ end
31
+ Choice.new 'Where will you go next?', door_choices
32
+ end
33
+
34
+ def doors_at location
35
+ doors = {}
36
+ @map[location].each_with_index do |door, next_room|
37
+ doors[door.to_sym] = next_room if door != ' '
38
+ end
39
+ doors
40
+ end
41
+
42
+ def to_s
43
+ rows = []
44
+ @map.each_with_index do |row, i|
45
+ rows << "#{i}|#{row.join '|'}"
46
+ end
47
+ rows.join "\n"
48
+ end
49
+ end
@@ -0,0 +1,10 @@
1
+
2
+ class EdgeColoringGraph
3
+ def initialize map
4
+ @edges = map
5
+ end
6
+
7
+ def edge(x, y)
8
+ @edges[x][y]
9
+ end
10
+ end
@@ -1,11 +1,11 @@
1
1
  module GameMechanics
2
-
2
+
3
3
  @@save_file = '../lib/save_game.json'
4
-
4
+
5
5
  def prompt
6
6
  print ">> "
7
7
  end
8
-
8
+
9
9
  def yes_no
10
10
  #restrict input to valid answers, but don't worry about case
11
11
  begin
@@ -13,7 +13,7 @@ module GameMechanics
13
13
  prompt; @yes_no = STDIN.gets.chomp.downcase
14
14
  end while not (@yes_no == "yes" or @yes_no == "no")
15
15
  end
16
-
16
+
17
17
  def save_data
18
18
  # increase level as player gets more xp!
19
19
  case
@@ -31,6 +31,12 @@ module GameMechanics
31
31
  @player.lvl = 6
32
32
  when (15001..19000).include?(@player.xp)
33
33
  @player.lvl = 7
34
+ when (19001..24000).include?(@player.xp)
35
+ @player.lvl = 8
36
+ when (24001..29000).include?(@player.xp)
37
+ @player.lvl = 9
38
+ when @player.xp > 29000
39
+ @player.lvl = 10
34
40
  end
35
41
  save_info = {
36
42
  role: @player.class,
@@ -48,7 +54,7 @@ module GameMechanics
48
54
  f.write(save_info.to_json)
49
55
  end
50
56
  end
51
-
57
+
52
58
  def load_data
53
59
  load_info = JSON.parse(File.read(@@save_file))
54
60
  role = load_info['role']
@@ -63,7 +69,7 @@ module GameMechanics
63
69
  end
64
70
  # Set stats based off information in load_info
65
71
  @player.lvl = load_info['lvl']
66
- @player.xp = load_info['xp']
72
+ @player.xp = load_info['xp']
67
73
  @player.coin = load_info['coin']
68
74
  @player.name = load_info['name']
69
75
  @player.cur_hp = load_info['cur_hp']
@@ -79,7 +85,7 @@ module GameMechanics
79
85
  # I was trying to do the above assignments with iteration, there has to be a way!
80
86
  # load_info.each do |attribute, value|
81
87
  # @player.#{attribute} = value unless attribute == "role"
82
- # end
88
+ # end
83
89
  end
84
90
 
85
91
  def restore_player
@@ -90,31 +96,40 @@ module GameMechanics
90
96
  end
91
97
 
92
98
  def bar_top
93
- "_"*27 + " STATS " + "_"*27
99
+ "_"*27 + " " + "STATS" + " " + "_"*27
94
100
  end
95
-
101
+
96
102
  def stat_bar name, xp, lvl, coin, cur_hp, cur_mana
97
- " Name: #{name} | XP: #{xp} | Lvl: #{lvl} | Coin: #{coin} | HP: #{cur_hp} | Mana: #{cur_mana}"
103
+ " Name: " + "#{name}" + " | XP: #{xp} | Lvl: #{lvl} | Coin: #{coin} | HP: #{cur_hp} | Mana: #{cur_mana}"
98
104
  end
99
-
105
+
100
106
  def bar_low
101
107
  "-"*61
102
108
  end
103
-
109
+
104
110
  def is_even?(x)
105
111
  x % 2 == 0 ? true : false
106
112
  end
107
-
113
+
108
114
  def player_croaks
109
115
  puts # formatting
116
+ if @player.class.to_s == "Wizard" and @player.spell_buff == true
117
+ puts "A single tear falls from Draco as he fades away..."
118
+ puts #formatting
119
+ @player.spell_buff = false
120
+ end
110
121
  puts "It happens to the best of us #{@player.name}."
111
122
  puts "Fortunately for you, the game of Destiny never ends."
112
123
  puts "The game will exit now and you can restart in town."
113
124
  puts # formatting
114
125
  puts "Better luck next time, eh?"
126
+ @player.buff_food = false
127
+ @player.buff_drink = false
128
+ @player.cur_hp = @player.hp/2
129
+ save_data
115
130
  exit
116
131
  end
117
-
132
+
118
133
  def combat bad_guy
119
134
  # create an opponent
120
135
  @bad_guy = bad_guy.new
@@ -129,14 +144,16 @@ module GameMechanics
129
144
  @heal = false
130
145
  puts # formatting
131
146
  puts bar_low + "--"
132
- 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}"
147
+ puts " #{@player.name} - HP: #{@player.cur_hp} - Mana: #{@player.cur_mana} |".green + " - VS - " + "| #{@bad_guy.name} - HP: #{@bad_guy.cur_hp} - Mana: #{@bad_guy.cur_mana}".red
133
148
  puts bar_low + "--"
134
149
  puts # formatting
135
- puts "#{@bad_guy.name} vs. #{@player.name}, what will you do?"
136
- puts "[1]. Attack."
137
- puts "[2]. Run."
138
- puts "[3]. Cast Heal and Attack." if @player.class.to_s == "Cleric"
139
- prompt; move = gets.chomp
150
+ choice_opts = {
151
+ "1" => "Attack.",
152
+ "2" => "Run."
153
+ }
154
+ choice_opts["3"] = "Cast Heal and Attack." if @player.class.to_s == "Cleric"
155
+ c = Choice.new "#{@bad_guy.name} vs. #{@player.name}, what will you do?", choice_opts
156
+ move = c.prompt
140
157
  move = "4" if move == "3" and @player.class.to_s != "Cleric"
141
158
  end while not (move == "1" or move == "2" or move == "3")
142
159
  @heal = true if move == "3" # set cleric heal flag to true
@@ -151,13 +168,13 @@ module GameMechanics
151
168
  @dmg_dlt = dice(@player.dmg) + dmg_mod
152
169
  elsif @player.class.to_s == "Wizard"
153
170
  begin
154
- puts "How many magic darts will you shoot?"
155
- puts "[1]." # always allow wizard one dart even without enough mana
156
- puts "[2]." if @player.cur_mana - 2*@player.lvl >= 0
157
- puts "[3]." if @player.cur_mana - 3*@player.lvl >= 0
158
- prompt; darts = gets.chomp.to_i
159
- darts = 4 if darts == 2 and @player.cur_mana - 2*@player.lvl < 0
160
- darts = 4 if darts == 3 and @player.cur_mana - 3*@player.lvl < 0
171
+ choice_opts = { "1" => "one dart" }
172
+ choice_opts["2"] = "two darts" if @player.cur_mana - 2*@player.lvl >= 0
173
+ choice_opts["3"] = "three darts" if @player.cur_mana - 3*@player.lvl >= 0
174
+ c = Choice.new "How many magic darts will you shoot?", choice_opts
175
+ darts = c.prompt.to_i
176
+ darts = 4 if darts == 2 and @player.cur_mana - 2*@player.lvl < 0
177
+ darts = 4 if darts == 3 and @player.cur_mana - 3*@player.lvl < 0
161
178
  end while not (darts == 1 or darts == 2 or darts == 3)
162
179
  puts # formatting
163
180
  puts "#{@player.name} conjures #{darts} magic dart that zips toward the #{@bad_guy.name}." if darts == 1
@@ -176,10 +193,10 @@ module GameMechanics
176
193
  end
177
194
  @heal_amount = dice(2)*@player.lvl + heal_bonus + 1 # testing with the +1, what I am going for here
178
195
  # is to balance the heal with their lower damage and hp
179
- puts "Praying intently, you add #{@heal_amount} health points as you prepare to strike."
196
+ puts "Praying intently, you add " + "#{@heal_amount}".green + " health points as you prepare to strike."
197
+ @player.cur_hp = @player.cur_hp + @heal_amount
180
198
  puts "#{@player.name}, any health points above your normal maximum will fade after combat." if @player.cur_hp > @player.hp
181
199
  puts # formatting
182
- @player.cur_hp = @player.cur_hp + @heal_amount
183
200
  end
184
201
  puts "#{@player.name} brings the holy mace thundering down upon #{@bad_guy.name}!"
185
202
  puts # formatting
@@ -201,7 +218,7 @@ module GameMechanics
201
218
  @dmg_dlt = @dmg_dlt - @bad_guy.armor/4
202
219
  @dmg_dlt = 0 if @dmg_dlt < 1
203
220
  puts #formatting
204
- puts "You deal #{@dmg_dlt} damage to the #{@bad_guy.name}." unless @dmg_dlt < 1
221
+ puts "You deal " + "#{@dmg_dlt}".green + " damage to the #{@bad_guy.name}." unless @dmg_dlt < 1
205
222
  puts # formatting
206
223
  @bad_guy.cur_hp = @bad_guy.cur_hp - @dmg_dlt
207
224
  end
@@ -227,7 +244,7 @@ module GameMechanics
227
244
  else
228
245
  dmg_taken = dice(@bad_guy.dmg) - @player.armor/4
229
246
  if @player.class.to_s == "Wizard" and @player.spell_buff == true and dmg_taken > 1
230
- draco_helps = @player.lvl
247
+ draco_helps = @player.lvl + @player.lvl/2 # Trying a bump in mitigation as Wizard is squishy!
231
248
  dmg_taken = dmg_taken - draco_helps
232
249
  puts "Draco helps shield you absorbing some of the potential damage."
233
250
  puts # formatting
@@ -235,7 +252,7 @@ module GameMechanics
235
252
  dmg_taken = 0 if dmg_taken < 1
236
253
  @player.cur_hp = @player.cur_hp - dmg_taken
237
254
  if dmg_taken > 0
238
- puts "#{@bad_guy.name} hits YOU for #{dmg_taken} damage!"
255
+ puts "#{@bad_guy.name} hits YOU for " + "#{dmg_taken}".red + " damage!"
239
256
  puts "OUCH!"
240
257
  else
241
258
  puts "You deflect the blow and take no damage."
@@ -276,7 +293,7 @@ module GameMechanics
276
293
  dmg_taken = dice(@bad_guy.dmg) - @player.armor/4
277
294
  dmg_taken = 0 if dmg_taken < 1
278
295
  @player.cur_hp = @player.cur_hp - dmg_taken
279
- puts "#{@bad_guy.name} hits YOU for #{dmg_taken} damage!" unless dmg_taken < 1
296
+ puts "#{@bad_guy.name} hits YOU for " + "#{dmg_taken}".red + " damage!" unless dmg_taken < 1
280
297
  puts "OUCH!" unless dmg_taken < 1
281
298
  end
282
299
  puts #formatting
@@ -292,14 +309,14 @@ module GameMechanics
292
309
  puts "Ah, the life of a rogue, so free, so evasive!"
293
310
  puts "#{@player.name}, using your roguish powers you slip away unseen, leaving"
294
311
  puts "#{@bad_guy.name} cursing and muttering in the dark."
295
- end
312
+ end
296
313
  save_data
297
314
  return
298
315
  end
299
316
  end
300
-
317
+
301
318
  end
302
-
319
+
303
320
  def dice(sides=6,&block)
304
321
  if block_given?
305
322
  block.call(rand(1..sides))
@@ -361,7 +378,7 @@ module GameMechanics
361
378
  player_croaks
362
379
  end
363
380
  save_data
364
- end
381
+ end
365
382
  end
366
-
367
- end
383
+
384
+ end
@@ -91,18 +91,28 @@ class GiantRat < Mobs
91
91
  def initialize(str=12, agi=10, int=4, dmg=5, armor=6, hp=8, cur_hp=8, dodge=5, mana=0, cur_mana=0, xp=150, lvl=1, coin=1, name="Giant Rat")
92
92
  rat_type = dice(10)
93
93
  case
94
- when (1..8).include?(rat_type)
94
+ when (1..5).include?(rat_type)
95
95
  # no change, you just get the generic giant rat
96
- when (9..10).include?(rat_type)
96
+ when (6..9).include?(rat_type)
97
97
  # this feller is much harder to defeat
98
- str = 16
99
- dmg = 8
98
+ str = 14
99
+ dmg = 6
100
100
  hp = 10
101
101
  cur_hp = 10
102
102
  dodge = 10
103
- xp = 400
104
- coin = 3
103
+ xp = 250
104
+ coin = 2
105
105
  name = "ROUS"
106
+ when rat_type == 10
107
+ # Giant rat mini boss!
108
+ str = 16
109
+ dmg = 8
110
+ hp = 12
111
+ cur_hp = 12
112
+ dodge = 15
113
+ xp = 400
114
+ coin = 4
115
+ name = "Nuck Chorris"
106
116
  end
107
117
  super(str,agi,int,dmg,armor,hp,cur_hp,dodge,mana,cur_mana,xp,lvl,coin,name)
108
118
  end
@@ -115,9 +125,9 @@ class Goblin < Mobs
115
125
  # Should probably create a method that does the below
116
126
  goblin_type = dice(10)
117
127
  case
118
- when (1..6).include?(goblin_type)
128
+ when (1..5).include?(goblin_type)
119
129
  # no change, you just get the generic goblin
120
- when (7..10).include?(goblin_type)
130
+ when (6..9).include?(goblin_type)
121
131
  # this feller is stronger, but less nimble
122
132
  str = 16
123
133
  dmg = 6
@@ -128,6 +138,16 @@ class Goblin < Mobs
128
138
  xp = 200
129
139
  coin = 2
130
140
  name = "Goblin Warrior"
141
+ when goblin_type == 10
142
+ # Mini boss goblin!
143
+ str = 16
144
+ dmg = 8
145
+ armor = 10
146
+ hp = 10
147
+ cur_hp = 10
148
+ xp = 300
149
+ coin = 3
150
+ name = "Goblin Chief"
131
151
  end
132
152
  super(str,agi,int,dmg,armor,hp,cur_hp,dodge,mana,cur_mana,xp,lvl,coin,name)
133
153
  end
@@ -139,19 +159,28 @@ class Kobold < Mobs
139
159
  def initialize(str=12, agi=8, int=8, dmg=5, armor=5, hp=6, cur_hp=6, dodge=10, mana=2, cur_mana=2, xp=150, lvl=1, coin=2, name="Kobold")
140
160
  kobold_type = dice(10)
141
161
  case
142
- when (1..6).include?(kobold_type)
162
+ when (1..5).include?(kobold_type)
143
163
  # no change, you just get the generic kobold
144
- when (7..10).include?(kobold_type)
164
+ when (6..9).include?(kobold_type)
145
165
  # this one has double the chance to dodge as a regular kobold
146
166
  agi = 16
147
167
  dmg = 6
148
168
  armor = 6
149
- hp = 8
150
- cur_hp = 8
151
169
  dodge = 20
152
170
  xp = 300
153
171
  coin = 4
154
172
  name = "Kobold Thief"
173
+ when kobold_type == 10
174
+ # kobold mini boss!
175
+ str = 16
176
+ agi = 12
177
+ dmg = 8
178
+ armor = 8
179
+ hp = 10
180
+ cur_hp = 10
181
+ xp = 400
182
+ coin = 5
183
+ name = "Kobold Berserker"
155
184
  end
156
185
  super(str,agi,int,dmg,armor,hp,cur_hp,dodge,mana,cur_mana,xp,lvl,coin,name)
157
186
  end
@@ -163,9 +192,9 @@ class Skeleton < Mobs
163
192
  def initialize(str=12, agi=10, int=8, dmg=5, armor=6, hp=8, cur_hp=8, dodge=5, mana=0, cur_mana=0, xp=200, lvl=1, coin=3, name="Skeleton")
164
193
  skeleton_type = dice(10)
165
194
  case
166
- when (1..7).include?(skeleton_type)
195
+ when (1..5).include?(skeleton_type)
167
196
  # no change, you just get the generic skeleton
168
- when (8..10).include?(skeleton_type)
197
+ when (6..9).include?(skeleton_type)
169
198
  # this feller is considerably tougher
170
199
  str = 16
171
200
  dmg = 6
@@ -173,8 +202,20 @@ class Skeleton < Mobs
173
202
  hp = 10
174
203
  cur_hp = 10
175
204
  xp = 300
176
- coin = 5
205
+ coin = 3
177
206
  name = "Skeletal Knight"
207
+ when skeleton_type == 10
208
+ # skeleton mini boss!
209
+ str = 14
210
+ agi = 14
211
+ dmg = 8
212
+ armor = 8
213
+ hp = 10
214
+ cur_hp = 10
215
+ dodge = 10
216
+ xp = 400
217
+ coin = 5
218
+ name = "Skeleton of Geoff"
178
219
  end
179
220
  super(str,agi,int,dmg,armor,hp,cur_hp,dodge,mana,cur_mana,xp,lvl,coin,name)
180
221
  end
@@ -1,8 +1,10 @@
1
1
  # This file will contain the various places the player can go
2
2
  # Town, Tavern, Dungeon and options in each
3
+ require 'choice'
4
+ require 'dungeon_map'
3
5
 
4
6
  class Town
5
-
7
+
6
8
  def initialize
7
9
  # Town is only available as an option in the Dungeon (to return to)
8
10
  # initialize is only called the first time, so this greeting is only seen once
@@ -10,22 +12,24 @@ class Town
10
12
  puts "You walk into town, scanning each nook and cranny. Most faces are friendly,"
11
13
  puts "some are not..."
12
14
  end
13
-
15
+
14
16
  def choices
15
17
  move = 0
16
18
  until move == "3"
17
19
  begin
18
20
  load_data
19
21
  puts # formatting
20
- puts bar_top
22
+ puts bar_top.yellow
21
23
  puts stat_bar(@player.name, @player.xp, @player.lvl, @player.coin, @player.cur_hp, @player.cur_mana)
22
- puts bar_low
24
+ puts bar_low.yellow
23
25
  puts # formatting
24
- puts "Please choose where you will head next:"
25
- puts "[1]. The Dungeon"
26
- puts "[2]. Ye Old Tavern"
27
- puts "[3]. Exit Game"
28
- prompt; move = gets.chomp
26
+ c = Choice.new "Please choose where you will head next:",
27
+ {
28
+ "1" => "The Dungeon",
29
+ "2" => "Ye Old Tavern",
30
+ "3" => "Exit Game"
31
+ }
32
+ move = c.prompt
29
33
  end while not (move == "1" or move == "2" or move == "3")
30
34
  case
31
35
  when move == "1"
@@ -43,9 +47,30 @@ class Town
43
47
  end
44
48
 
45
49
  class Dungeon
46
-
50
+ # a sample map
51
+ # a map is an edge array defining a graph. Edges have colorings.
52
+ # TODO: make a set of maps and define them elsewhere
53
+ # write an algorithm to create good maps
54
+ #
55
+
47
56
  # can get here from town, initialize just gives a one time (per visit) message
48
57
  def initialize
58
+
59
+ map = <<-MAP
60
+ 0 1 2 3 4 5 6 7 8 9
61
+ 0| | |r| | |w| |c| | |
62
+ 1| | | | |w|c| | | | |
63
+ 2|r| | |c| |i| | |w| |
64
+ 3| | |c| | | |i| | | |
65
+ 4| |w| | | | | | | | |
66
+ 5|w|c|i| | | | | | | |
67
+ 6| | | |i| | | |w| |r|
68
+ 7|c| | | | | |w| | |i|
69
+ 8| | |w| | | | | | |c|
70
+ 9| | | | | | |r|i|c| |
71
+ MAP
72
+ @map = map.split("\n")[1..map.length].map {|line| line.split('|')[1..map.length]}
73
+ @dungeon_map = DungeonMap.new @map
49
74
  puts # formatting
50
75
  rand_greet = dice(3)
51
76
  rand_greet = "You have entered the dungeon! DUM DUM DUM!!" if rand_greet == 1
@@ -53,25 +78,24 @@ class Dungeon
53
78
  rand_greet = "As you enter the dungeon, you notice strange markings along the walls..." if rand_greet == 3
54
79
  puts rand_greet
55
80
  end
56
-
81
+
57
82
  def choices
58
83
  move = 0
59
84
  load_data
60
- bread_crumb = 0 # helps track how deep you go into the dungeon
61
- until move == "2" and bread_crumb == 0
62
- begin
63
- puts # formatting
64
- puts bar_top
65
- puts stat_bar(@player.name, @player.xp, @player.lvl, @player.coin, @player.cur_hp, @player.cur_mana)
66
- puts bar_low
67
- puts # formatting
68
- puts "Now #{@player.name}, what will you do next?"
69
- puts "[1]. Go deeper into the dungeon."
70
- puts "[2]. Return to town."
71
- puts "[3]. Conjure Wizard Familiar" if @player.class.to_s == "Wizard" and @player.spell_buff == false
72
- prompt; move = gets.chomp
73
- move = "4" if move == "3" and (@player.class.to_s != "Wizard" or @player.spell_buff == true)
74
- end while not (move == "1" or move == "2" or move == "3")
85
+ room_id = 0 # start at room 0
86
+ until move == "t" and room_id == 0
87
+ puts # formatting
88
+ puts bar_top.yellow
89
+ puts stat_bar(@player.name, @player.xp, @player.lvl, @player.coin, @player.cur_hp, @player.cur_mana)
90
+ puts bar_low.yellow
91
+ puts # formatting
92
+ c = @dungeon_map.choices room_id
93
+ c.add('t', 'Go back to town.') if room_id == 0
94
+ if @player.class.to_s == "Wizard" and
95
+ @player.spell_buff == false
96
+ c.add('f', "Conjure Wizard Familar")
97
+ end
98
+ move = c.prompt
75
99
  # apply food buff
76
100
  @player.cur_hp = @player.cur_hp + @player.lvl if @player.buff_food == true
77
101
  # prevent food buff from raising current health points above maximum
@@ -80,8 +104,9 @@ class Dungeon
80
104
  @player.cur_mana = @player.cur_mana + @player.lvl if @player.buff_drink == true
81
105
  # prevent drink buff from raising current mana points above maximum
82
106
  @player.cur_mana = @player.mana if @player.cur_mana > @player.mana
83
- case
84
- when move == "1"
107
+ new_room_id = @dungeon_map.door_to room_id, move
108
+ if new_room_id != room_id
109
+ room_id = new_room_id
85
110
  puts # formatting
86
111
  rand_msg = dice(3)
87
112
  rand_msg = "You walk further into the dark, dank, dirty, dungeon, smirking slightly at your awesome alliteration ability." if rand_msg == 1
@@ -89,30 +114,25 @@ class Dungeon
89
114
  rand_msg = "More strange markings, they seem to mean something, but what and who wrote them?" if rand_msg == 3
90
115
  puts rand_msg
91
116
  puts # formatting
92
- bread_crumb = bread_crumb + 1
93
117
  random_encounter
94
- when move == "2"
95
- if bread_crumb <= 1
96
- puts # formatting
97
- puts "You make it back to town in one piece!"
98
- puts # formatting
99
- # remove food buffs from player when they leave the dungeon
100
- @player.buff_food = false
101
- @player.buff_drink = false
102
- if @player.class.to_s == "Wizard" and @player.spell_buff == true
103
- puts "Drako wishes you well and fades away, ready to help another day."
104
- puts #formatting
105
- @player.spell_buff = false
106
- end
107
- save_data
108
- return
109
- end
110
- bread_crumb = bread_crumb - 1
118
+ elsif move == "t" # back to town
111
119
  puts # formatting
112
- puts "You head back toward town."
120
+ puts "You make it back to town in one piece!"
113
121
  puts # formatting
114
- random_encounter
115
- when move == "3"
122
+ # remove food buffs from player when they leave the dungeon
123
+ @player.buff_food = false
124
+ @player.buff_drink = false
125
+ if @player.class.to_s == "Wizard" and @player.spell_buff == true
126
+ puts "Drako wishes you well and fades away, ready to help another day."
127
+ puts #formatting
128
+ @player.spell_buff = false
129
+ end
130
+ save_data
131
+ return
132
+ # wizard familiar
133
+ elsif move == "f" and
134
+ @player.class.to_s == "Wizard" and
135
+ @player.spell_buff == false
116
136
  puts # formatting
117
137
  puts "#{@player.name} concentrates intently while waving the magic wand and casting the spell..."
118
138
  puts # formatting
@@ -127,7 +147,7 @@ class Dungeon
127
147
  end
128
148
 
129
149
  class Tavern
130
-
150
+
131
151
  # only available as an option in the Town
132
152
  # The tavern will "heal" the player by restoring mana and hp
133
153
  def initialize
@@ -139,28 +159,30 @@ class Tavern
139
159
  puts "Some rest would probably do you good, #{@player.name}." if @player.cur_hp < @player.hp
140
160
  puts # formatting
141
161
  end
142
-
162
+
143
163
  def choices
144
164
  move = 0
145
165
  until move == "4"
146
166
  begin
147
167
  puts # formatting
148
- puts bar_top
168
+ puts bar_top.yellow
149
169
  puts stat_bar(@player.name, @player.xp, @player.lvl, @player.coin, @player.cur_hp, @player.cur_mana)
150
- puts bar_low
170
+ puts bar_low.yellow
151
171
  puts # formatting
152
- room_cost = @player.lvl*3
153
- nourish_cost = @player.lvl*2
154
- puts "What would you like to do in the tavern, #{@player.name}?"
155
- puts "[1]. Buy some food. | Cost: #{nourish_cost} coins."
156
- puts "[2]. Buy a drink. | Cost: #{nourish_cost} coins."
157
- puts "[3]. Rest. | Cost: #{room_cost} coins."
158
- puts "[4]. Leave the tavern."
159
- prompt; move = gets.chomp
172
+ room_cost = @player.lvl*2
173
+ nourish_cost = @player.lvl
174
+ c = Choice.new "What would you like to do in the tavern, #{@player.name}?",
175
+ {
176
+ "1" => "Buy some food. | Cost: #{nourish_cost} coins.",
177
+ "2" => "Buy a drink. | Cost: #{nourish_cost} coins.",
178
+ "3" => "Rest. | Cost: #{room_cost} coins.",
179
+ "4" => "Leave the tavern."
180
+ }
181
+ move = c.prompt
160
182
  end while not (move == "1" or move == "2" or move == "3" or move == "4")
161
183
  case
162
184
  when move == "1"
163
- if @player.coin >= @player.lvl*2
185
+ if @player.coin >= @player.lvl and @player.buff_food != true
164
186
  @player.buff_food = true
165
187
  puts # formatting
166
188
  puts "You find a seat at an open table and the waiter approaches to take your order."
@@ -169,14 +191,17 @@ class Tavern
169
191
  puts "health as you travel in the dungeon."
170
192
  puts # formatting
171
193
  puts "You order and enjoy a delicious meal, #{@player.name}, you really do feel swell!"
172
- @player.coin = @player.coin - @player.lvl*2
194
+ @player.coin = @player.coin - @player.lvl
173
195
  save_data
196
+ elsif @player.buff_food == true
197
+ puts #formatting
198
+ puts "You couldn't possibly eat anymore."
174
199
  else
175
200
  puts # formatting
176
201
  puts "You can't afford a meal! Go to the dungeon and earn some money!"
177
202
  end
178
203
  when move == "2"
179
- if @player.coin >= @player.lvl*2
204
+ if @player.coin >= @player.lvl and @player.buff_drink != true
180
205
  @player.buff_drink = true
181
206
  puts # formatting
182
207
  puts "You sally up to the bar and the barkeep approaches to take your order."
@@ -185,23 +210,29 @@ class Tavern
185
210
  puts "mana as you travel in the dungeon."
186
211
  puts # formatting
187
212
  puts "You swirl the wine, sniff, then take a sip, #{@player.name}, you really do feel superior!"
188
- @player.coin = @player.coin - @player.lvl*2
213
+ @player.coin = @player.coin - @player.lvl
189
214
  save_data
215
+ elsif @player.buff_drink == true
216
+ puts #formatting
217
+ puts "You couldn't possibly drink anymore."
190
218
  else
191
219
  puts # formatting
192
220
  puts "You can't afford wine, you churl! Go to the dungeon and earn some money!"
193
221
  end
194
222
  when move == "3"
195
- if @player.coin >= @player.lvl*3
223
+ if @player.coin >= @player.lvl*2 and (@player.cur_hp != @player.hp or @player.cur_mana != @player.mana)
196
224
  health = @player.cur_hp
197
225
  mana = @player.cur_mana
198
- @player.coin = @player.coin - @player.lvl*3
226
+ @player.coin = @player.coin - @player.lvl*2
199
227
  restore_player
200
228
  health = @player.cur_hp - health
201
229
  mana = @player.cur_mana - mana
202
230
  puts # formatting
203
231
  puts "You pay for a small room and get a good night of rest."
204
232
  puts "Resting has restored #{health} health points and #{mana} points of mana."
233
+ elsif (@player.cur_hp == @player.hp and @player.cur_mana == @player.mana)
234
+ puts # formatting
235
+ puts "You don't really need to rest, get out there and make your own discoveries!"
205
236
  else
206
237
  puts # formatting
207
238
  puts "You can't afford a room! Hit the dungeon and earn some money!"
metadata CHANGED
@@ -1,16 +1,37 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: destiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kody Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Role playing game with distinct classes and character development
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.7.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.7.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.0
33
+ description: Role playing game with distinct classes, character development, and a
34
+ dungeon map!
14
35
  email: kodywilson@gmail.com
15
36
  executables:
16
37
  - destiny
@@ -18,7 +39,10 @@ extensions: []
18
39
  extra_rdoc_files: []
19
40
  files:
20
41
  - bin/destiny
42
+ - lib/choice.rb
21
43
  - lib/destiny.rb
44
+ - lib/dungeon_map.rb
45
+ - lib/edge_coloring_graph.rb
22
46
  - lib/game_mechanics.rb
23
47
  - lib/mobs.rb
24
48
  - lib/places.rb