Class: GamesParadise::ShakesAndFidgets::Adventure
- Inherits:
-
Base
- Object
- Base
- GamesParadise::ShakesAndFidgets::Adventure
show all
- Defined in:
- lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb
Constant Summary
collapse
- DEFAULT_ADVENTURE_DESCRIPTION =
#
DEFAULT_ADVENTURE_DESCRIPTION
#
'Die nackte Priesterin.'
- FILE_ADVENTURE =
GamesParadise::PROJECT_BASE_DIRECTORY+'shakes_and_fidgets/yaml/adventure.yml'
- CANCELLED =
'[Cancelled]'
Constants inherited
from Base
Base::CONTROL_C_CODE, Base::N
Class Method Summary
collapse
-
.show_available_adventures ⇒ Object
# === GamesParadise::ShakesAndFidgets::Adventure.show_available_adventures ========================================================================= #.
Instance Method Summary
collapse
Methods inherited from Base
#cat, #commandline_arguments?, #efancy, #eparse, #first_argument?, #forestgreen, #gold, #lightblue, #lightgreen, #mediumorchid, #mediumslateblue, #opnn, #peru, #register_sigint, #rev, #royalblue, #set_commandline_arguments, #sfile, #steelblue, #teal, #tomato, #yellow
Methods included from BaseModule
#cliner, #commandline_arguments?, #first_argument?, #infer_the_namespace, #namespace?, #rename_file, #reset_the_internal_hash, #return_pwd, #set_commandline_arguments
Constructor Details
#initialize(run_already = true) ⇒ Adventure
54
55
56
57
58
59
60
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 54
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
#
GamesParadise::ShakesAndFidgets::Adventure.show_available_adventures
#
41
42
43
44
45
46
47
48
49
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 41
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
365
366
367
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 365
def character?
@character
end
|
#count_down(i = @dauer) ⇒ Object
#
count_down
Use this method to count down.
#
410
411
412
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 410
def count_down(i = @dauer)
AsciiParadise::AsciiCounter.new(i, PADDING_TO_USE)
end
|
#dataset? ⇒ Boolean
Also known as:
dataset
112
113
114
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 112
def dataset?
@adventure
end
|
#debug ⇒ Object
317
318
319
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 317
def debug
pp self
end
|
#let_character_fight_adventure_monster ⇒ Object
#
let_character_fight_adventure_monster
#
324
325
326
327
328
329
330
331
332
333
334
335
336
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 324
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.
#
343
344
345
346
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 343
def load_adventure(i = FILE_ADVENTURE)
@adventure = YAML.load_file(i) return @adventure
end
|
#money? ⇒ Boolean
Also known as:
money
358
359
360
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 358
def money?
@money
end
|
#padded_display(title, value) ⇒ Object
255
256
257
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 255
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.
#
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 236
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 65
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.
#
127
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
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 127
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.
#
264
265
266
267
268
269
270
271
272
273
274
275
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 264
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
372
373
374
375
376
377
378
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 372
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
91
92
93
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 91
def set_description(i)
@description = i
end
|
#set_money_reward(i) ⇒ Object
351
352
353
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 351
def set_money_reward(i)
@money = i end
|
#set_motivation_cost(i = 10) ⇒ Object
98
99
100
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 98
def set_motivation_cost(i = 10)
@motivation_cost = i
end
|
#set_name(i) ⇒ Object
84
85
86
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 84
def set_name(i)
@name = i
end
|
#set_xp_reward(i) ⇒ Object
105
106
107
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 105
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.
#
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
# File 'lib/games_paradise/shakes_and_fidgets/adventure/adventure.rb', line 386
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
|