Class: GamesAndRpgParadise::Gamebooks::CommandlineGamebook

Inherits:
Base
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb

Overview

GamesAndRpgParadise::Gamebooks::CommandlineGamebook

Constant Summary

Constants included from Base::Extensions::Colours

Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base::Extensions::Colours

ecomment, #efancy, #eparse, #forestgreen, #gold, #grey, #lightblue, #mediumseagreen, #mediumslateblue, #peru, #rev, sdir, sfancy, #sfile, simp, #teal, #yellow

Methods included from Base::Extensions::CommandlineArguments

#commandline_arguments?, #filter_away_commandline_arguments, #first_argument?, #first_non_hyphened_argument?, #set_commandline_arguments

Methods included from CommonExtensions

#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

#

initialize

#


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?

#

character?

#

Returns:

  • (Boolean)


254
255
256
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 254

def character?
  @character
end

#content?Boolean

#

content?

#

Returns:

  • (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_characterObject

#

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
  # ======================================================================= #
  @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)
  # ======================================================================= #
  # === Endurance
  # ======================================================================= #
  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?

#

current_page?

#

Returns:

  • (Boolean)


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_loopObject

#

enter_the_main_loop

#


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
      menu(@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_playerObject

#

greet_the_player

#


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
#

menu (menu tag)

#


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 menu(
    i = @user_input
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === char?
    # ===================================================================== #
    when /char\??$/i
      show_the_character
    # ===================================================================== #
    # === gold
    # ===================================================================== #
    when /gold\??$/i
      show_available_gold_coins
    # ===================================================================== #
    # === create
    # ===================================================================== #
    when /create\??$/i
      create_a_new_character
    # ===================================================================== #
    # === content
    # ===================================================================== #
    when /content\??$/i,
         'l',
         'ls',
         'll'
      e steelblue(content?)
    # ===================================================================== #
    # === debug
    # ===================================================================== #
    when /debug$/i
      pp @dataset
    # ===================================================================== #
    # === exits?
    # ===================================================================== #
    when /exits\??$/i
      show_the_available_exits
    # ===================================================================== #
    # === quit
    # ===================================================================== #
    when /^q$/,
         'quit',
         'exit'
      @shall_we_quit = true
    # ===================================================================== #
    # === help
    # ===================================================================== #
    when /help$/
      show_help_options
    end
  end
end

#obtain_user_inputObject

#

obtain_user_input

#


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_sigintObject

#

register_sigint

#


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

#resetObject

#

reset (reset tag)

#


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
  # ======================================================================= #
  @shall_we_quit = false
  # ======================================================================= #
  # === @current_page
  #
  # Keep track of the current page via this variable.
  # ======================================================================= #
  @current_page = 0
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title = nil
  # ======================================================================= #
  # === @character
  # ======================================================================= #
  @character = nil
end

#runObject

#

run (run tag)

#


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_coinsObject

#

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_optionsObject

#

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_exitsObject

#

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_characterObject

#

show_the_character

#


116
117
118
# File 'lib/games_and_rpg_paradise/gamebooks/commandline_gamebook/commandline_gamebook.rb', line 116

def show_the_character
  pp char?
end