Class: GamesAndRpgParadise::ShakesAndFidgets::UserInput
- Inherits:
-
Object
- Object
- GamesAndRpgParadise::ShakesAndFidgets::UserInput
- Defined in:
- lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb
Constant Summary collapse
- CREATE_HERO_ON_STARTUP =
#
CREATE_HERO_ON_STARTUP
#
true
Constants included from Colours
Instance Method Summary collapse
-
#act_on_user_input(i = @user_input) ⇒ Object
# === act_on_user_input.
-
#add_motivation(i) ⇒ Object
# === add_motivation.
-
#add_xp(i) ⇒ Object
# === add_xp ========================================================================= #.
-
#bold_yellow(i = '') ⇒ Object
# === bold_yellow ========================================================================= #.
-
#character? ⇒ Boolean
(also: #char?)
# === character? ========================================================================= #.
-
#consider_creating_hero ⇒ Object
# === consider_creating_hero ========================================================================= #.
-
#continually_fetch_user_input ⇒ Object
# === continually_fetch_user_input.
-
#create_character ⇒ Object
(also: #make_character, #make_hero, #consider_making_character)
# === create_character ========================================================================= #.
-
#debug ⇒ Object
# === debug ========================================================================= #.
-
#deduct_n_pilze(i) ⇒ Object
# === deduct_n_pilze ========================================================================= #.
-
#enter_tavern ⇒ Object
# === enter_tavern.
-
#exit_program ⇒ Object
# === exit_program ========================================================================= #.
-
#feedback_character ⇒ Object
# === feedback_character.
-
#initialize(run_already = true) ⇒ UserInput
constructor
# === initialize ========================================================================= #.
-
#initialize_armours ⇒ Object
# === initialize_armours ========================================================================= #.
-
#initialize_variables ⇒ Object
# === initialize_variables ========================================================================= #.
-
#load_character ⇒ Object
# === load_character.
-
#not_found(i) ⇒ Object
# === not_found.
-
#open_in_editor(i) ⇒ Object
# === open_in_editor ========================================================================= #.
-
#open_project_files ⇒ Object
# === open_project_files (open tag).
-
#reload ⇒ Object
# === reload ========================================================================= #.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#rev ⇒ Object
# === rev ========================================================================= #.
-
#run ⇒ Object
# === run (run tag).
-
#save ⇒ Object
# === save (save tag) ========================================================================= #.
-
#set_character_class(i = '') ⇒ Object
(also: #set_class)
# === set_character_class ========================================================================= #.
-
#show_abenteuerlust ⇒ Object
# === show_abenteuerlust ========================================================================= #.
-
#show_available_adventures ⇒ Object
# === show_available_adventures ========================================================================= #.
-
#show_current_level ⇒ Object
# === show_current_level ========================================================================= #.
-
#show_help ⇒ Object
(also: #display_help)
# === show_help (help tag) ========================================================================= #.
-
#show_levels ⇒ Object
(also: #show_xp_levels)
# === show_levels.
Methods included from Shared
#calculate_cost_for_n_increase_of_attribute, #fetch_user_input, #load_yaml, #report_name, #save_character, #user_input
Methods included from Colours
#brown, #cfile, #convert_colour, convert_colour, #fancy, #normal, #pink, #red, #yel
Constructor Details
#initialize(run_already = true) ⇒ UserInput
#
initialize
#
39 40 41 42 43 44 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 39 def initialize( run_already = true ) reset run if run_already end |
Instance Method Details
#act_on_user_input(i = @user_input) ⇒ Object
#
act_on_user_input
The input to this method is supposed to be a String.
#
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 263 def act_on_user_input(i = @user_input) _ = i.chomp _ = _.strip # Since March 2012 we strip the input. if _.include? ' ' if _.include?('.') and _.include?('=') # Assume something like this: hero.name = joe splitted = _.split('=').map(&:strip) @character.send(splitted[0].split('.')[1]+'=', splitted[1]) end splitted = _.split(' ') a = splitted[1..-1] # All arguments. _ = splitted[0] f = splitted[1] # First argument. else a = nil end case _ # case tag # ======================================================================= # # === help # ======================================================================= # when 'help','hel','he','h','?','menu' show_help # ======================================================================= # # === name? # ======================================================================= # when 'name?' char?.report_name # ======================================================================= # # === set_xp # ======================================================================= # when 'set_xp','setxp','xp' char?.set_xp f.to_i e 'Now setting the XP to '+simp(char?.xp?.to_s)+'.' when 'character?','hero?','?hero','feedback?', 'show_abenteuerlust','char?','stats?','c?' feedback_character when 'set_class','setclass','class' set_class(f) when 'level?','levels?' show_levels show_current_level when 'zero' case f when 'abenteuerlust','1','ab' @character.abenteuerlust = 0 e 'Setting Abenteuerlust back to 0.' else # Batch set to zero. char?.set_money 0 char?.set_xp 0 end when 'addgold' e 'Adding 2500 coins now (for debugging purposes).' @character.add_cash '2500' when 'cash?','money?','gold?' efancy @character.cash? when 'zauberladen','magic','5','05','zauber','zau' Zauberladen.new(char?) when 'ehre','fame','ehre?','fame?' @character.report_fame when 'hall_of_fame','HallofFame','hall?','halloffame' HallofFame.new(char?) when 'save','15','sav' save when 'Ehrenhalle','ehrenhalle' Ehrenhalle.new when 'tavern','tav','abenteuer','ab', # Start the adventure here. 'go_adventure','adventure','1','taverne', 'abent','ad' enter_tavern when '8','post_office','postoffice','post' e 'You enter the post office.' e 'You can input "help" next to get an overview over as the available' e 'options in the post office.' @post_office. when 'motivation?','abenteuerlust' # Let's find out the motivation of our hero. efancy @character.abenteuerlust? when '4','waffenladen','weapons','waffen','weapon', 'waffe' Waffenladen.new(character?) show_help when 'stall' e 'Not yet implemented.' when 'all_adventures','abenteuer?','adventures?','a?' show_available_adventures when '3','stadtwache','work','worker','work?', 'stadtw','wache' Stadtwache.new(char?) show_help when 'add_xp','addxp' add_xp(a) when 'cat' cat(a) when 'xp?' efancy @character.xp? when 'open','open_project_files' open_project_files when 'demotivate' @character.abenteuerlust = 0 when 'url','url?' e 'http://s30.sfgame.de/' when 'hero','character','char','c','11','create' consider_making_character feedback_character when 'self' pp self when 'pwd' e Dir.pwd when 'mode?' e 'The current mode is: '+@mode when 'll' ShowDirectoryContent.do_show when 'test2' # pp @character.layers[:torso].attribute_boosts unless @character.layers[:torso].is_a?(String) when 'test','t','te','equip','equipment' e 'Testing:' make_character @character.try_to_equip # Defaults to a new armour without argument. @character.try_to_equip @character.try_to_equip @character.try_to_equip @character.try_to_equip @character.try_to_equip @character.try_to_equip # pp @charackter.all_armours # this fails. when 'toggle' @mode = 'debug' when 'debug','13','debug?' debug when 'load','14','restore','reloadc' load_character when 'reload' reload when 'q','qq' exit_program when '' else # Else tag. not_found(_) end end |
#add_motivation(i) ⇒ Object
#
add_motivation
Delegate into the Character class here.
#
154 155 156 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 154 def add_motivation(i) @character.add_motivation(i) end |
#add_xp(i) ⇒ Object
#
add_xp
#
175 176 177 178 179 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 175 def add_xp(i) i = i.first if i.is_a? Array e 'Now adding '+sfancy(i)+' XP to your hero '+@character.name+'.' @character.add_xp(i) end |
#bold_yellow(i = '') ⇒ Object
#
bold_yellow
#
237 238 239 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 237 def bold_yellow(i = '') GamesAndRpgParadise::ShakesAndFidgets.bold_yellow(i) end |
#character? ⇒ Boolean Also known as: char?
#
character?
#
463 464 465 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 463 def character? @character end |
#consider_creating_hero ⇒ Object
#
consider_creating_hero
#
219 220 221 222 223 224 225 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 219 def consider_creating_hero if CREATE_HERO_ON_STARTUP e 'We will create a hero now because CREATE_HERO_ON_STARTUP was '+ 'set to true.' make_hero end end |
#continually_fetch_user_input ⇒ Object
#
continually_fetch_user_input
Use this method to fetch user input from the main menu.
#
409 410 411 412 413 414 415 416 417 418 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 409 def continually_fetch_user_input begin fetch_user_input # This is defined in shared.rb rescue Interrupt exit_program end @user_input.each {|entry| act_on_user_input(entry) } end |
#create_character ⇒ Object Also known as: make_character, make_hero, consider_making_character
#
create_character
#
423 424 425 426 427 428 429 430 431 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 423 def create_character if @character # pass through in this case, as the character # already exists. else e 'Creating a '+simp('Hero')+' next.' @character = Character.new end end |
#debug ⇒ Object
#
debug
#
70 71 72 73 74 75 76 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 70 def debug # (debug tag) cliner { pp @character pp @character.name if @character # pp @abenteuer } end |
#deduct_n_pilze(i) ⇒ Object
#
deduct_n_pilze
#
168 169 170 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 168 def deduct_n_pilze(i) @character.pilze('-'+i.to_s) end |
#enter_tavern ⇒ Object
#
enter_tavern
We enter a tavern here. The tavern is a “virtual room” for now, only available via this method call.
#
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 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 187 def enter_tavern # ======================================================================= # # Intercept weary heroes here - they can drink something. # ======================================================================= # if @character.abenteuerlust == 0 e 'Du hast keine Lust mehr auf Abenteuer.' e 'Willst du etwas trinken? Kostet aber einen Pilz.' if user_input[0,1] =~ /[yj]/ e 'Ok, du trinkst etwas.' add_motivation('+20') deduct_n_pilze(1) show_abenteuerlust else e 'Du entschliesst dich nichts zu trinken.' end else @abenteuer = GamesAndRpgParadise::ShakesAndFidgets::Abenteuer.new(false) # bl $SHAKES/abenteuer.rb create_character if @character.nil? # Safeguard. Create it if it does not exist yet. old_xp = @character.xp? _ = @abenteuer.select_an_adventure(3, @character.motivation) # Allow the user to select an adventure. if _ == '[Cancelled]' e _ unless @character.motivation == 0 else @abenteuer.start_abenteuer(@character) save if @character.xp? > old_xp # Only save here when he gained XP. end end end |
#exit_program ⇒ Object
#
exit_program
#
81 82 83 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 81 def exit_program # exit tag exit end |
#feedback_character ⇒ Object
#
feedback_character
Feedback information about the character.
#
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 472 def feedback_character if @character e 'Feedbacking some information about the character.' e @character.report_name @character.report_xp @character.report_abenteuerlust @character.report_fame @character.report_level @character.report_stats @character.report_money @character.report_race @character.report_character_class e else e 'We can not feedback anything about the character' e 'because none was created so far.' end end |
#initialize_armours ⇒ Object
#
initialize_armours
#
145 146 147 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 145 def initialize_armours @armours = Armour.new end |
#initialize_variables ⇒ Object
#
initialize_variables
#
63 64 65 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 63 def initialize_variables @mode = 'normal' # Can be either normal or debug mode. Is called from within run() end |
#load_character ⇒ Object
#
load_character
Load the character here. Right now we only load the XP set.
#
127 128 129 130 131 132 133 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 127 def load_character e 'Loading from '+cfile+STORE_WHERE+normal dataset = YAML.load_file(STORE_WHERE) @character = character.new @character.set_xp(dataset) feedback_character end |
#not_found(i) ⇒ Object
#
not_found
Use this method when a command was not found.
#
253 254 255 256 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 253 def not_found(i) e 'Not found: `'+sfancy(i)+'`' e 'You can do "?" to show the help section.' end |
#open_in_editor(i) ⇒ Object
#
open_in_editor
#
117 118 119 120 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 117 def open_in_editor(i) _ = MAIN_EDITOR+' '+i esystem _ end |
#open_project_files ⇒ Object
#
open_project_files (open tag)
Use this to open some project files. There will be a slight delay on purpose if we use bluefish.
#
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 91 def open_project_files base_dir = BASE_DIR array = %w( abenteuer.rb arena/arena.rb armour.rb character.rb menu.rb opponent.rb shared.rb user_input.rb stadtwache.rb TODO/TODO_FOR_SHAKES_AND_FIDGETS.md ) # ======================================================================= # # === Open all these files next. # ======================================================================= # array.each {|file| open_in_editor(base_dir+file) sleep 0.6 if MAIN_EDITOR == 'bluefish' } end |
#reload ⇒ Object
#
reload
#
138 139 140 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 138 def reload # reload tag initialize_armours end |
#reset ⇒ Object
#
reset
#
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 49 def reset # ======================================================================= # # === @character # ======================================================================= # @character = nil # ======================================================================= # # === @post_office # ======================================================================= # @post_office = ShakesAndFidgets::PostOffice.new end |
#rev ⇒ Object
#
rev
#
495 496 497 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 495 def rev ::GamesAndRpgParadise.rev end |
#run ⇒ Object
#
run (run tag)
General run method.
#
537 538 539 540 541 542 543 544 545 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 537 def run initialize_variables display_help # Show help options on startup. initialize_armours # Easier helper. consider_creating_hero loop { continually_fetch_user_input } end |
#save ⇒ Object
#
save (save tag)
#
244 245 246 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 244 def save # Save method. Save the character dataset. (save tag) save_character(@character) # This method is defined in shared.rb end |
#set_character_class(i = '') ⇒ Object Also known as: set_class
#
set_character_class
#
455 456 457 458 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 455 def set_character_class(i = '') e 'Now setting to class '+sfancy(i.to_s)+'.' @character.set_character_class(i) # Delegate to class Character. end |
#show_abenteuerlust ⇒ Object
#
show_abenteuerlust
#
161 162 163 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 161 def show_abenteuerlust eparse 'Die Abenteuerlust ist nun: '+@character.abenteuerlust?.to_s end |
#show_available_adventures ⇒ Object
#
show_available_adventures
#
230 231 232 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 230 def show_available_adventures Abenteuer.show_available_adventures end |
#show_current_level ⇒ Object
#
show_current_level
#
447 448 449 450 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 447 def show_current_level e 'The character currently has '+simp(char?.xp?.to_s)+' XP.' @character.report_level end |
#show_help ⇒ Object Also known as: display_help
#
show_help (help tag)
#
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 502 def show_help # ======================================================================= # # === Instantiate a new Menu next # ======================================================================= # = ShakesAndFidgets::Menu.new e; report_name; e 'The following options are available for user input:'+N e = .entries = .size .each_with_index {|entry, index| index += 1 option = '%-12s' % entry[0] description = entry[1] index = index.to_s.rjust(2) _ = rev+'# ('+rev+bold_yellow(index)+') '+description e ' - '+option+' '+brown(_) } e ' - Hero '+brown('# ')+rev+'('+pink(+1)+rev+ ') Create your hero (or feedback the current hero).' e ' - Debug '+brown('# ')+rev+'('+pink(+2)+rev+ ') Feedback debug information.' e ' - Load '+brown('# ')+rev+'('+pink(+3)+rev+ ') load the character dataset' e ' - Save '+brown('# ')+rev+'('+pink(+4)+rev+ ') to save your character to file.' e ' - Test '+brown('# ')+rev+'('+pink(+5)+rev+ ') test your scripts'+N e end |
#show_levels ⇒ Object Also known as: show_xp_levels
#
show_levels
Show XP levels through this method here.
#
440 441 442 |
# File 'lib/games_and_rpg_paradise/games/shakes_and_fidgets/user_input/user_input.rb', line 440 def show_levels e XP_LEVELS_AS_ARRAY.map {|entry| ' '+entry }.join end |