Class: GamesAndRpgParadise::Gamebooks::CommandlineGamebook
- Inherits:
-
Base
- Object
- Base
- GamesAndRpgParadise::Gamebooks::CommandlineGamebook
show all
- Defined in:
- lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb
Overview
GamesAndRpgParadise::Gamebooks::CommandlineGamebook
Constant Summary
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === GamesAndRpgParadise::Gamebooks::CommandlineGamebook[] ========================================================================= #.
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, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ CommandlineGamebook
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 35
def initialize(
commandline_arguments = nil,
run_already = true
)
register_sigint
reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
GamesAndRpgParadise::Gamebooks::CommandlineGamebook[]
#
297
298
299
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 297
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#character? ⇒ Boolean
Also known as:
char?
254
255
256
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 254
def character?
@character
end
|
#content? ⇒ Boolean
199
200
201
202
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 199
def content?
pointer = @dataset[@current_page]
pointer['content']
end
|
#create_a_new_character ⇒ Object
#
create_a_new_character
#
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
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 207
def create_a_new_character
e 'A new character will be rolled next.'
@character = GamesAndRpgParadise::Gamebook::LoneWolf::Character.new
new_value = 10+GamesAndRpgParadise.roll('1W9')
e 'The combat skill will be: '+steelblue(new_value.to_s)
@character.set_combat_skill(new_value)
@character.set_initial_combat_skill(new_value)
new_value = 20+GamesAndRpgParadise.roll('1W9')
e 'The endurance value will be: '+steelblue(new_value.to_s)
@character.set_max_endurance(new_value)
@character.set_endurance(new_value)
e
new_value = GamesAndRpgParadise.roll('1W9')
e 'You obtain '+steelblue(new_value.to_s)+' gold coins.'
@character.add_n_gold_coins(new_value)
e
e 'Next you can select Kai disciplines - the available Kai disciplines'
e 'will be shown next:'
e
available_kai_disciplines = GamesAndRpgParadise::Gamebook::LoneWolf.basic_kai_disciplines?
available_kai_disciplines.each_with_index {|this_discipline, index| index += 1
colourized_number = lightgreen("number #{index}")
e " - #{steelblue(this_discipline.ljust(25))} # #{colourized_number}"
}
pick_how_many_kai_disciplines = 3
e pick_how_many_kai_disciplines.to_s+' kai disciplines should be picked next.'
pick_how_many_kai_disciplines.times {|pick|
e 'Pick a kai discipline next (use a number, as shown above; numbering starts at 1):'
user_input = $stdin.gets.chomp.to_i
@character.array_kai_disciplines << available_kai_disciplines[user_input - 1]
}
e
result = @character.save
e 'The character will be saved locally into '
e sfile(result)
e 'as well.'
end
|
#current_page? ⇒ Boolean
Also known as:
the_current_subpage_is?
76
77
78
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 76
def current_page?
@current_page
end
|
#enter_the_main_loop ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 83
def enter_the_main_loop
e tomato('Enter a number next, to denote which gamebook to use:')
e
user_input = $stdin.gets.chomp
@dataset, @title = GamesAndRpgParadise::Gamebooks.load_this_lone_wolf_gamebook(
user_input,
:also_provide_the_title
)
e 'Choosing '+steelblue(@title.to_s)+' next.'
if @dataset
loop {
e tomato('Input what next should be done (help for obtaining '\
'help options; q to quit):')
obtain_user_input
(@user_input)
break if @shall_we_quit
}
else
e 'No dataset has been found for the given input '+
steelblue(user_input.to_s)
end
end
|
#greet_the_player ⇒ Object
279
280
281
282
283
284
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 279
def greet_the_player
e "#{rev}Welcome to the interactive commandline-gamebook."
e
e 'This allows you to play through a gamebook, from start to finish.'
e
end
|
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
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
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 123
def (
i = @user_input
)
if i.is_a? Array
i.each {|entry| (entry) }
else
case i when /char\??$/i
show_the_character
when /gold\??$/i
show_available_gold_coins
when /create\??$/i
create_a_new_character
when /content\??$/i,
'l',
'ls',
'll'
e steelblue(content?)
when /debug$/i
pp @dataset
when /exits\??$/i
show_the_available_exits
when /^q$/,
'quit',
'exit'
@shall_we_quit = true
when /help$/
show_help_options
end
end
end
|
272
273
274
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 272
def obtain_user_input
@user_input = $stdin.gets.chomp
end
|
#register_sigint ⇒ Object
109
110
111
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 109
def register_sigint
Signal.trap('SIGINT') { exit }
end
|
#reset ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 50
def reset
super()
infer_the_namespace
@shall_we_quit = false
@current_page = 0
@title = nil
@character = nil
end
|
#run ⇒ Object
289
290
291
292
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 289
def run
greet_the_player
enter_the_main_loop
end
|
#show_available_gold_coins ⇒ Object
#
show_available_gold_coins
#
192
193
194
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 192
def show_available_gold_coins
e steelblue(character?.n_gold_coins?)
end
|
#show_help_options ⇒ Object
#
show_help_options (help tag)
#
261
262
263
264
265
266
267
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 261
def show_help_options
e
e ' exits? # show the exits'
e ' create # create a new character'
e ' gold? # show how much gold the character has'
e
end
|
#show_the_available_exits ⇒ Object
#
show_the_available_exits
#
182
183
184
185
186
187
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 182
def show_the_available_exits
pointer = @dataset[@current_page]
exits = pointer['exits']
e 'DEBUG'
pp exits
end
|
#show_the_character ⇒ Object
116
117
118
|
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 116
def show_the_character
pp char?
end
|