Class: GamesAndRpgParadise::GUI::UniversalWidgets::Hangman
- Inherits:
-
Base
- Object
- Base
- GamesAndRpgParadise::GUI::UniversalWidgets::Hangman
show all
- Includes:
- UniversalWidgets::BaseModule
- Defined in:
- lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb
Overview
Constant Summary
collapse
- TITLE =
'Hangman Game'
- WIDTH =
'42% or minimum 480px'
- HEIGHT =
'30% or minimum 300px'
- USE_THIS_FONT =
:dejavu_condensed_22
- SMALLER_FONT =
:dejavu_condensed_18
- LARGER_FONT =
:hack_24
Base::Extensions::Colours::ARRAY_AVAILABLE_KONSOLE_COLOURS
CommonExtensions::CONTROL_C_CODE, CommonExtensions::N
Class Method Summary
collapse
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(commandline_arguments = nil, run_already = true) ⇒ Hangman
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 60
def initialize(
commandline_arguments = nil,
run_already = true
)
super(:vertical) if use_gtk3?
determine_the_GUI_to_be_used(commandline_arguments) reset
set_commandline_arguments(
commandline_arguments
)
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
620
621
622
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 620
def self.[](i = ARGV)
new(i)
end
|
.run(i = ARGV) ⇒ Object
#
GamesAndRpgParadise::GUI::Gtk::Hangman.run
#
605
606
607
608
609
610
611
612
613
614
615
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 605
def self.run(
i = ARGV
)
require 'gtk_paradise/run'
_ = ::GamesAndRpgParadise::GUI::Gtk::Hangman.new(i)
r = ::Gtk.run
r << _
r.automatic_size
r.automatic_title
r.top_left_then_run
end
|
Instance Method Details
#append_to_the_buffer(i) ⇒ Object
296
297
298
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 296
def append_to_the_buffer(i)
@text_buffer.append(i)
end
|
#border_size? ⇒ Boolean
457
458
459
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 457
def border_size?
0
end
|
206
207
208
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 206
def button_make_a_guess?
@button_make_a_guess
end
|
#check_if_the_game_is_over ⇒ Object
#
check_if_the_game_is_over
#
562
563
564
565
566
567
568
569
570
571
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 562
def check_if_the_game_is_over
if game_over?
e 'Game over!!'
append_to_the_buffer(
::GamesAndRpgParadise::Hangman::RIP_ASCII_PICTURE
)
do_display_the_unhappy_smiley
end
end
|
#clear_the_main_buffer ⇒ Object
#
clear_the_main_buffer
#
289
290
291
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 289
def clear_the_main_buffer
set_buffer('')
end
|
#connect_the_skeleton ⇒ Object
#
connect_the_skeleton (connect tag)
#
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 464
def connect_the_skeleton
abort_on_exception
do_restart_the_game
outer_vbox = create_vbox
title = left_aligned_label(
'The Hangman game'
)
title.set_font(:hack_22)
title.make_bold
outer_vbox.minimal(title, 1)
outer_vbox.maximal(@scrolled_window)
label = left_aligned_text(
'The word to be <b>guessed</b> is:'
)
hbox = create_hbox
hbox.maximal(@entry_guessable_word, 1)
hbox.minimal(@label_that_may_contain_the_unhappy_smiley, 1)
@grid.left(label)
@grid.right_double_width(hbox)
@grid.new_row
hbox = create_hbox
label = text(
'Input the character to be guessed next:'
)
@grid.left label
@grid.right_double_width @entry_input_the_character
@grid.new_row
@grid.left label('These characters were guessed so far:')
@grid.right_double_width @guessed_characters_label
@grid.new_row
@grid.left text('The word to be guessed contains <b>n characters</b>:')
@grid.right_double_width @label_the_guessable_word_has_n_characters
hbox_containing_the_grid = create_hbox
hbox_containing_the_grid.maximal(@grid)
@checkbutton_for_using_the_dictionaries_gem.css_class('pad5px')
@checkbutton_for_using_the_dictionaries_gem.on_toggled { |widget|
if widget.active?
@game.make_use_of_the_dictionaries_gem
do_restart_the_game(false)
@game.we_may_not_exit
end
}
mini_hbox = hbox
text1 = text('Make use of the dictionaries gem:')
text1.use_this_font SMALLER_FONT
text1.hint = 'Activate the checkbox to the right side of this '\
'text in order to make use of the dictionaries '\
'gem. This necessitates the installation of that '\
'gem.'
mini_hbox.minimal(text1)
mini_hbox.minimal(@checkbutton_for_using_the_dictionaries_gem)
outer_vbox.minimal(hbox_containing_the_grid, 5)
outer_vbox.minimal(mini_hbox, 5)
button_box = create_hbox
button_box.minimal(@button_make_a_guess, 8)
button_box.minimal(@button_restart_the_game, 8)
outer_vbox.add(button_box)
window = create_window_or_runner(nil, width?, height?, title?)
window << outer_vbox
Thread.new {
sleep 0.001
@entry_input_the_character.grab_focus
}
sync_the_entry_guessable_word_onto_the_label_the_guessable_word_has_n_characters
properly_prepare_this_window(window,
{
title: title?,
font: font?,
width: width?,
height: height?,
padding: padding?,
border_size: border_size?
}
)
window.show_all
window.top_left
run_main
end
|
#create_entry_input_the_character ⇒ Object
#
create_entry_input_the_character
This method will create the gtk-entry that is used to obtain the user-input.
#
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 363
def create_entry_input_the_character
@entry_input_the_character = create_entry
@entry_input_the_character.center
@entry_input_the_character.do_focus
@entry_input_the_character.yellow_background
@entry_input_the_character.bblack1
@entry_input_the_character.hint = 'Input here which '\
'character (a single character) is to be guessed next.'
@entry_input_the_character.on_mouse_click_select_everything
@entry_input_the_character.width_height(280, 30)
@entry_input_the_character.on_enter {
do_make_a_guess_then_select_everything
}
@entry_input_the_character.set_maxsize(1)
end
|
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 131
def create_the_buttons
@button_make_a_guess = button('_Make a guess', self, :use_mnemonics) {
:do_make_a_guess
}
@button_make_a_guess.bblack1
@button_make_a_guess.on_hover(:steelblue)
@button_make_a_guess.hint = 'Click on this button to make a guess. '\
'This will use the character you did '\
'input above.'
@button_restart_the_game = button('_Restart the game', self, :use_mnemonics) {
:do_restart_the_game
}
@button_restart_the_game.bblack1
@button_restart_the_game.on_hover(:steelblue)
@button_restart_the_game.hint = 'Click on this '\
'button to restart the game.'
end
|
#create_the_entries ⇒ Object
#
create_the_entries (entries tag, entry tag)
#
386
387
388
389
390
391
392
393
394
395
396
397
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 386
def create_the_entries
@entry_guessable_word = create_entry @entry_guessable_word.yellow_background
@entry_guessable_word.bblack1
@entry_guessable_word.disallow_changes
@entry_guessable_word.center
@entry_guessable_word.width_height(280, 30)
create_entry_input_the_character end
|
#create_the_grid ⇒ Object
#
create_the_grid (grid tag)
#
249
250
251
252
253
254
255
256
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 249
def create_the_grid
@grid = default_grid
@grid.set_column_spacing(6)
@grid.set_row_spacing(6)
end
|
#create_the_labels ⇒ Object
#
create_the_labels (labels tag, label tag)
#
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 327
def create_the_labels
@guessed_characters_label = bold_label
@guessed_characters_label.css_class('royalblue')
@guessed_characters_label.set_name('royalblue')
@guessed_characters_label.make_selectable
@label_that_may_contain_the_unhappy_smiley = label
@label_that_may_contain_the_unhappy_smiley.css_class('gold')
@label_that_may_contain_the_unhappy_smiley.make_selectable
@label_the_guessable_word_has_n_characters = bold_label
end
|
#create_the_main_scrolled_window ⇒ Object
#
create_the_main_scrolled_window
#
165
166
167
168
169
170
171
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 165
def create_the_main_scrolled_window
@scrolled_window = scrolled_window(@text_view) { :always }
@scrolled_window.bblack2
@scrolled_window.pad4px
@scrolled_window.set_size_request(1400, 550)
@scrolled_window.set_font(:hack_22)
end
|
#create_the_skeleton ⇒ Object
Also known as:
create_skeleton
#
create_skeleton (create tag, skeleton tag)
#
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 303
def create_the_skeleton
if use_gtk3?
@text_buffer = create_text_buffer
@text_buffer.set_text('')
end
@checkbutton_for_using_the_dictionaries_gem = create_checkbutton
create_the_text_view
create_the_labels
create_the_entries
create_the_buttons
create_the_grid
create_the_main_scrolled_window
end
|
#create_the_text_view ⇒ Object
576
577
578
579
580
581
582
583
584
585
586
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 576
def create_the_text_view
if use_gtk3?
@text_view = create_text_view(@text_buffer)
else
@text_view = create_text_view
end
@text_view.css_class('mar4px')
end
|
#do_display_the_unhappy_smiley ⇒ Object
#
do_display_the_unhappy_smiley
#
190
191
192
193
194
195
196
197
198
199
200
201
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 190
def do_display_the_unhappy_smiley
@label_that_may_contain_the_unhappy_smiley.set_text(
" #{UNHAPPY_SMILEY} "
)
@label_that_may_contain_the_unhappy_smiley.remove_css_class('BG_black')
@label_that_may_contain_the_unhappy_smiley.css_class('BG_black')
end
|
#do_make_a_guess(i = @entry_input_the_character.text?.to_s) ⇒ Object
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
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 213
def do_make_a_guess(
i = @entry_input_the_character.text?.to_s
)
if game_over?
else
if i.empty?
(
button_make_a_guess?,
'You have to provide one character.'
)
elsif @game.has_this_character_been_guessed_already?(i)
(
entry_input_which_character?,
"The character <b>#{i}</b> has already been guessed."
)
else
@game.guess_this_character(i)
set_buffer(@game.frame?)
@guessed_characters_label.set_text(
@game.guessed_characters?.
sort.join(', ')
)
@guessed_characters_label.make_bold
end
update_the_entry_guessable_word
check_if_the_game_is_over
end
end
|
#do_make_a_guess_then_select_everything ⇒ Object
#
do_make_a_guess_then_select_everything
#
261
262
263
264
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 261
def do_make_a_guess_then_select_everything
do_make_a_guess
@entry_input_the_character.select_everything
end
|
350
351
352
353
354
355
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 350
def
(
entry_input_which_character?,
'The game is over. You have to <b>restart</b> the game.'
)
end
|
#do_restart_the_game(shall_we_initialize_a_new_base_game_object = true) ⇒ Object
#
do_restart_the_game (restart tag)
#
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 269
def do_restart_the_game(
shall_we_initialize_a_new_base_game_object = true
)
reset_the_game_variables(
shall_we_initialize_a_new_base_game_object
)
@game.restart
@game.we_may_not_exit
@entry_input_the_character.clear
clear_the_main_buffer
@guessed_characters_label.set_text(
@game.guessed_characters?.join(', ')
)
@label_that_may_contain_the_unhappy_smiley.set_text('')
update_the_entry_guessable_word
end
|
#entry_input_which_character? ⇒ Boolean
#
entry_input_which_character?
#
320
321
322
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 320
def entry_input_which_character?
@entry_input_the_character
end
|
#game_over? ⇒ Boolean
414
415
416
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 414
def game_over?
@game.game_over?
end
|
#handle_CSS ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 107
def handle_CSS
use_gtk_paradise_project_css_file
more_CSS '
popover {
color: darkblue;
margin: 8px;
padding: 10px;
border: 3px solid black;
font-size: 1.8em;
}
'
apply_the_CSS_rules
end
|
#initialize_the_game_object ⇒ Object
#
initialize_the_game_object
#
402
403
404
405
406
407
408
409
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 402
def initialize_the_game_object
require 'games_and_rpg_paradise/games/hangman/hangman.rb'
@game = GamesAndRpgParadise::Hangman.new(:do_not_run_yet)
@game.we_may_not_exit
end
|
#padding? ⇒ Boolean
450
451
452
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 450
def padding?
4
end
|
#reset ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 77
def reset
super() if respond_to?(:super)
reset_the_base_module
reset_the_internal_variables
infer_the_namespace
@configuration = [true, __dir__, namespace?]
title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
if use_gtk3?
handle_CSS
end
infer_the_size_automatically
end
|
#reset_the_ascii_position ⇒ Object
#
reset_the_ascii_position
#
176
177
178
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 176
def reset_the_ascii_position
@ascii_position = 0
end
|
#reset_the_game_variables(shall_we_initialize_a_new_base_game_object = true) ⇒ Object
#
reset_the_game_variables
#
437
438
439
440
441
442
443
444
445
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 437
def reset_the_game_variables(
shall_we_initialize_a_new_base_game_object = true
)
initialize_the_game_object if shall_we_initialize_a_new_base_game_object
@ascii_position = 0
end
|
#reset_the_shared_module ⇒ Object
#
reset_the_shared_module
#
430
431
432
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 430
def reset_the_shared_module
reset_the_game_variables
end
|
#run ⇒ Object
598
599
600
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 598
def run
run_super
end
|
158
159
160
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 158
def scrolled_window?
@scrolled_window
end
|
#set_buffer(i = @game.frame?) ⇒ Object
591
592
593
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 591
def set_buffer(i = @game.frame?)
@text_buffer.set_text(i)
end
|
#smaller_font? ⇒ Boolean
124
125
126
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 124
def smaller_font?
SMALLER_FONT
end
|
#sync_the_entry_guessable_word_onto_the_label_the_guessable_word_has_n_characters ⇒ Object
#
sync_the_entry_guessable_word_onto_the_label_the_guessable_word_has_n_characters
#
99
100
101
102
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 99
def sync_the_entry_guessable_word_onto_the_label_the_guessable_word_has_n_characters
_ = @entry_guessable_word.text?.to_s.size.to_s
@label_the_guessable_word_has_n_characters.set_text(_)
end
|
#update_the_entry_guessable_word ⇒ Object
#
update_the_entry_guessable_word
#
421
422
423
424
425
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 421
def update_the_entry_guessable_word
@entry_guessable_word.set_text(
@game.return_the_word_that_has_been_guessed_so_far
)
end
|
#won? ⇒ Boolean
183
184
185
|
# File 'lib/games_and_rpg_paradise/gui/universal_widgets/hangman/hangman.rb', line 183
def won?
@game.won?
end
|