Class: GamesParadise::GUI::Gtk::Hangman

Inherits:
Gtk::Box
  • Object
show all
Includes:
HangmanModule, Gtk::BaseModule
Defined in:
lib/games_paradise/gui/gtk3/hangman/hangman.rb

Overview

GamesParadise::GUI::Gtk::Hangman

Constant Summary

Constants included from HangmanModule

HangmanModule::HEIGHT, HangmanModule::NAMESPACE, HangmanModule::SMALLER_FONT, HangmanModule::TITLE, HangmanModule::USE_THIS_FONT, HangmanModule::WIDTH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HangmanModule

#append_to_the_buffer, #button_make_a_guess?, #check_if_the_game_is_over, #clear_the_main_buffer, #create_entry_input_the_character, #create_skeleton, #create_the_buttons, #create_the_entries, #create_the_grid, #create_the_labels, #create_the_main_scrolled_window, #create_the_text_view, #do_display_the_unhappy_smiley, #do_make_a_guess, #do_make_a_guess_then_select_everything, #do_popup_the_game_is_over, #do_restart_the_game, #entry_input_which_character?, #game_over?, #initialize_the_game_object, #reset_the_ascii_position, #reset_the_game_variables, #reset_the_shared_module, #scrolled_window?, #set_buffer, #sync_the_entry_guessable_word_onto_the_label_the_guessable_word_has_n_characters, #update_the_entry_guessable_word, #won?

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Hangman

#

initialize

#


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 29

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  super(:vertical)
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.run(i = ARGV) ⇒ Object

#

GamesParadise::GUI::Gtk::Hangman.run

#


167
168
169
170
171
172
173
174
175
176
177
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 167

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/app/app.rb'
  _ = ::GamesParadise::GUI::Gtk::Hangman.new(i)
  r = ::Gtk.run
  r << _
  r.automatic_size_then_automatic_title
  r.enable_quick_exit
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 77

def border_size?
  2
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 84

def connect_skeleton
  abort_on_exception
  title = left_aligned_label(
    'The Hangman game'
  )
  title.set_font(:hack_22)
  title.make_bold
  minimal(title, 1)
  maximal(@scrolled_window)

  label = gtk_left_aligned_text(
    'The word to be <b>guessed</b> is:'
  )
  hbox = gtk_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 = default_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 = hbox
  hbox_containing_the_grid.maximal(@grid)

  @checkbutton_for_using_the_dictionaries_gem = checkbutton
  @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
  _ = text('Make use of the dictionaries gem:')
  _.use_this_font SMALLER_FONT
  _.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 _
  mini_hbox.minimal @checkbutton_for_using_the_dictionaries_gem
  hbox_containing_the_grid.minimal(mini_hbox)

  minimal(hbox_containing_the_grid, 5)
  button_box = hbutton_box
  button_box.center
  button_box.minimal(@button_make_a_guess,     8)
  button_box.minimal(@button_restart_the_game, 8)
  add(button_box)
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


70
71
72
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 70

def padding?
  4
end

#resetObject

#

reset (reset tag)

#


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 44

def reset
  reset_the_internal_variables
  infer_the_namespace
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, namespace?]
  # ======================================================================= #
  # === Set the title, width, height and the font in use.
  # ======================================================================= #
  title_width_height_font(TITLE, WIDTH, HEIGHT, USE_THIS_FONT)
  use_gtk_paradise_project_css_file 
  infer_the_size_automatically
  reset_the_shared_module
  adhoc_css 'popover {
    color: darkblue;
    margin: 8px;
    padding: 10px;
    border: 3px solid black;
    font-size: 1.8em;
  }'
end

#runObject

#

run (run tag)

#


154
155
156
157
158
159
160
161
162
# File 'lib/games_paradise/gui/gtk3/hangman/hangman.rb', line 154

def run
  super()
  apply_the_css_string
  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
end