Module: GamesParadise::GUI::HangmanModule
- Included in:
- Gtk::Hangman
- Defined in:
- lib/games_paradise/gui/shared_code/hangman/hangman_module.rb
Overview
GamesParadise::GUI::HangmanModule
Constant Summary
collapse
- NAMESPACE =
inspect
- TITLE =
'Hangman Game'
- WIDTH =
'25% or minimum 200px'
- HEIGHT =
'15% or minimum 100px'
- USE_THIS_FONT =
:dejavu_condensed_22
- SMALLER_FONT =
:dejavu_condensed_18
Instance Method Summary
collapse
Instance Method Details
#append_to_the_buffer(i) ⇒ Object
127
128
129
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 127
def append_to_the_buffer(i)
@text_buffer.append(i)
end
|
#border_size? ⇒ Boolean
106
107
108
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 106
def border_size?
0
end
|
290
291
292
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 290
def button_make_a_guess?
@button_make_a_guess
end
|
#check_if_the_game_is_over ⇒ Object
#
check_if_the_game_is_over
#
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 246
def check_if_the_game_is_over
if game_over?
e 'Game over!!'
append_to_the_buffer(
::GamesParadise::Hangman::RIP_ASCII_PICTURE
)
do_display_the_unhappy_smiley
end
end
|
#clear_the_main_buffer ⇒ Object
#
clear_the_main_buffer
#
120
121
122
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 120
def clear_the_main_buffer
set_buffer('')
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.
#
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 393
def create_entry_input_the_character
@entry_input_the_character = 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
|
#create_skeleton ⇒ Object
#
create_skeleton (create tag)
#
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 134
def create_skeleton
@text_buffer = text_buffer
@text_buffer.set_text('')
create_the_text_view
create_the_main_scrolled_window
create_the_labels
create_the_entries
create_the_buttons
create_the_grid
end
|
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
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 198
def create_the_buttons
@button_make_a_guess = button('_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_make_a_guess.on_clicked {
do_make_a_guess
}
@button_restart_the_game = button('_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.'
@button_restart_the_game.on_clicked {
do_restart_the_game
}
end
|
#create_the_entries ⇒ Object
#
create_the_entries (entries tag, entry tag)
#
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 372
def create_the_entries
@entry_guessable_word = entry(
@game.return_the_word_that_has_been_guessed_so_far
)
@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)
#
175
176
177
178
179
180
181
182
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 175
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)
#
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 332
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
#
235
236
237
238
239
240
241
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 235
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_text_view ⇒ Object
187
188
189
190
191
192
193
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 187
def create_the_text_view
@text_view = text_view(@text_buffer)
@text_view.css_class('mar4px')
end
|
#do_display_the_unhappy_smiley ⇒ Object
#
do_display_the_unhappy_smiley
#
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 274
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
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
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 297
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?.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
#
148
149
150
151
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 148
def do_make_a_guess_then_select_everything
do_make_a_guess
@entry_input_the_character.select_everything
end
|
355
356
357
358
359
360
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 355
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)
#
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 156
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
@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?
#
365
366
367
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 365
def entry_input_which_character?
@entry_input_the_character
end
|
#game_over? ⇒ Boolean
63
64
65
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 63
def game_over?
@game.game_over?
end
|
#initialize_the_game_object ⇒ Object
#
initialize_the_game_object
#
52
53
54
55
56
57
58
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 52
def initialize_the_game_object
@game = GamesParadise::Hangman.new(:do_not_run_yet)
@game.we_may_not_exit
end
|
#padding? ⇒ Boolean
99
100
101
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 99
def padding?
0
end
|
#reset_the_ascii_position ⇒ Object
#
reset_the_ascii_position
#
260
261
262
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 260
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
#
86
87
88
89
90
91
92
93
94
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 86
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
#
79
80
81
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 79
def reset_the_shared_module
reset_the_game_variables
end
|
228
229
230
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 228
def scrolled_window?
@scrolled_window
end
|
#set_buffer(i = @game.frame?) ⇒ Object
113
114
115
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 113
def set_buffer(i = @game.frame?)
@text_buffer.set_text(i)
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
#
416
417
418
419
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 416
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
#
70
71
72
73
74
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 70
def update_the_entry_guessable_word
@entry_guessable_word.set_text(
@game.return_the_word_that_has_been_guessed_so_far
)
end
|
#won? ⇒ Boolean
267
268
269
|
# File 'lib/games_paradise/gui/shared_code/hangman/hangman_module.rb', line 267
def won?
@game.won?
end
|