Class: GamesAndRpgParadise::ShakesAndFidgets::Adventure
- Inherits:
-
Base
- Object
- Base
- GamesAndRpgParadise::ShakesAndFidgets::Adventure
show all
- Defined in:
- lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb
Constant Summary
collapse
- DEFAULT_ADVENTURE_DESCRIPTION =
#
DEFAULT_ADVENTURE_DESCRIPTION
#
'Die nackte Priesterin.'
- FILE_ADVENTURE =
GamesAndRpgParadise.project_base_directory?+
'games/shakes_and_fidgets/yaml/adventure.yml'
- CANCELLED =
'[Cancelled]'
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Class Method Summary
collapse
-
.show_available_adventures ⇒ Object
# === GamesAndRpgParadise::ShakesAndFidgets::Adventure.show_available_adventures ========================================================================= #.
Instance Method Summary
collapse
ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow
#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments
#cat, #cd, #cliner, #copy_file, #delete, #dirname_but_retains_the_trailing_slash, #disable_colours, #ensure_that_the_log_directory_exists, #esystem, #get_user_input, #infer_the_namespace, #is_on_roebe?, #log_dir?, #mkdir, #mkdir_then_cd_into_it, #mv, #namespace?, #opne, #opnn, #project_base_directory?, #project_image_directory?, #project_yaml_directory?, #rds, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Constructor Details
#initialize(run_already = true) ⇒ Adventure
55
56
57
58
59
60
61
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 55
def initialize(
run_already = true
)
reset
run_already = false if run_already.to_s.include? 'dont'
run if run_already
end
|
Class Method Details
.show_available_adventures ⇒ Object
#
GamesAndRpgParadise::ShakesAndFidgets::Adventure.show_available_adventures
#
42
43
44
45
46
47
48
49
50
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 42
def self.show_available_adventures
e 'These adventures are available:'
_ = ShakesAndFidgets::Adventure.new(:dont_run_yet)
_.reset
_.dataset.each_with_index {|(key, *), index|
e ' '+simp(((index+1).to_s).rjust(3))+' '+sfancy(key)
}
e 'Thus, we have a total of '+_.dataset.size.to_s+' entries available.'
end
|
Instance Method Details
#character? ⇒ Boolean
Also known as:
character
366
367
368
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 366
def character?
@character
end
|
#count_down(i = @dauer) ⇒ Object
#
count_down
Use this method to count down.
#
411
412
413
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 411
def count_down(i = @dauer)
AsciiParadise::AsciiCounter.new(i, PADDING_TO_USE)
end
|
#dataset? ⇒ Boolean
Also known as:
dataset
113
114
115
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 113
def dataset?
@adventure
end
|
#debug ⇒ Object
318
319
320
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 318
def debug
pp self
end
|
#let_character_fight_adventure_monster ⇒ Object
#
let_character_fight_adventure_monster
#
325
326
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 325
def let_character_fight_adventure_monster
monster_is_dead = true
monster_is_dead = false if rand(53) == 1 if monster_is_dead
e N+sfancy(@character.name)+' hat das Adventure bestanden!'
@character.add_xp @reward
else
e N+'Oh nein!'
e 'Das Monster hat '+sfancy(@character.name)+normal+' besiegt. :('
e 'Es gibt daher keine XP für diesen Kampf.'
end
end
|
#load_adventure(i = FILE_ADVENTURE) ⇒ Object
#
load_adventure
This method will also assign to the @adventure variable.
#
344
345
346
347
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 344
def load_adventure(i = FILE_ADVENTURE)
@adventure = YAML.load_file(i) return @adventure
end
|
#money? ⇒ Boolean
Also known as:
money
359
360
361
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 359
def money?
@money
end
|
#padded_display(title, value) ⇒ Object
256
257
258
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 256
def padded_display(title, value)
e blue+title.strip.ljust(15)+rev+(value.to_s.strip.rjust(21))
end
|
#report_adventure_dataset ⇒ Object
#
report_adventure_dataset
Use the following method to get more information about an Adventure.
#
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 237
def report_adventure_dataset
result = N+blue+'Titel des Adventures: '+rev
if Object.const_defined? :Konsole
result << Konsole.italic(@name)
else
result << @name
end
e result
e red+N+@description e e blue+('Dauer des Adventure:').ljust(24)+rev+@dauer.to_s.rjust(3)+' Sekunden'
padded_display('XP Reward: ', @reward.to_s+' XP')
padded_display('Money Reward: ', @money.to_s+' silver coins')
padded_display('Motivation: ', '-'+@motivation_cost.to_s)
end
|
#reset ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 66
def reset
@adventures = [] @be_interactive = false @character = nil
load_adventure end
|
#select_an_adventure(choose_n_adventures = 3, optional_motivation_of_the_hero = 100) ⇒ Object
Also known as:
start_interactively
#
select_an_adventure
This interactive method allows you to fetch user input and specifically assign an adventure. We must keep in mind that we only want to fetch unique adventures - if the adventure already exists in our hash, we won’t add it.
The first argument to this method tells us how many adventures we want to have available in our options array.
#
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 128
def select_an_adventure(
choose_n_adventures = 3,
optional_motivation_of_the_hero = 100
)
report_name; e 'You enter the Tavern.'
@adventures.clear if optional_motivation_of_the_hero == 0
e 'You feel too tired to adventure today.'
return CANCELLED
else
loop {
new_adventure = create_adventure(:random)
@adventures << new_adventure unless @adventures.include? new_adventure
break if @adventures.size == choose_n_adventures
}
cliner
@adventures.each_with_index {|adventure, index|
e i = index+1
padding_to_use = ' ' name_of_the_adventure = adventure.keys.first
duration = adventure[name_of_the_adventure]['Dauer']
description = adventure[name_of_the_adventure]['Beschreibung']
if Object.const_defined? :Konsole
name_of_the_adventure = Konsole.italic(name_of_the_adventure)+Konsole.rev
end
e padding_to_use+sfancy(i.to_s)+' '+name_of_the_adventure+
' [Duration: '+duration.to_s+']'
e if description.encoding.to_s == 'UTF-8'
description = description.force_encoding('iso-8859-1')
end
begin
splitted = description.split("\n")
splitted.map {|entry|
' '+entry
}.each {|entry| e entry } rescue ArgumentError => error cliner {
pp error
pp description
pp description.encoding.to_s
pp splitted.each {|entry|
p entry.class
}
}if splitted
end
}; e; cliner
e 'Please pick one of these now (or enter a '+
sfancy('non-number')+' to cancel):'
user_input = get_user_input if user_input =~ /^\d+$/ @be_interactive = true
n_adventures_available = @adventures.size user_input = user_input.to_i user_input = 1 if user_input < 1 if user_input > n_adventures_available user_input = n_adventures_available
end
user_input -= 1
title = @adventures[user_input].keys.first
data = @adventures[user_input][title] dauer = data['Dauer']
return create_adventure( title, dauer,
data['Erfahrung'],
data['Belohnung'],
data['Adventurelust'],
data['Beschreibung']
)
else return CANCELLED
end
end
end
|
#set_character(i = nil) ⇒ Object
Also known as:
set_charakter
#
set_character
This method assigns to the @character variable.
#
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 265
def set_character(i = nil)
if i
if i.is_a? Character
@character = i
else
raise 'Illegal object passed. Please use '+
'only class Character here.'
end
else
@character = nil
end
end
|
#set_dauer(i) ⇒ Object
Also known as:
set_delay
373
374
375
376
377
378
379
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 373
def set_dauer(i)
if i.to_s.include? '-' splitted = i.to_s.strip.split('-').map(&:to_i)
i = rand(splitted.first..splitted.last) end
@dauer = i.to_i end
|
#set_description(i) ⇒ Object
92
93
94
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 92
def set_description(i)
@description = i
end
|
#set_money_reward(i) ⇒ Object
352
353
354
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 352
def set_money_reward(i)
@money = i end
|
#set_motivation_cost(i = 10) ⇒ Object
99
100
101
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 99
def set_motivation_cost(i = 10)
@motivation_cost = i
end
|
#set_name(i) ⇒ Object
85
86
87
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 85
def set_name(i)
@name = i
end
|
#set_xp_reward(i) ⇒ Object
106
107
108
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 106
def set_xp_reward(i) @reward = i
end
|
#start_adventure(character = @character) ⇒ Object
Also known as:
start, run
#
start_adventure (run tag)
This starts the Adventure. You must pass the character doing the adventure as argument.
#
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/adventure/adventure.rb', line 387
def start_adventure(
character = @character
)
create_adventure(:random) unless @be_interactive
set_character(character)
e 'Das '+sfancy('Abenteuer ')+'"'+simp(@name.to_s)+'" startet nun.'
report_adventure_dataset
e count_down(@dauer) @character.deduct_motivation @motivation_cost
@character.add_money(money?)
let_character_fight_adventure_monster
end
|