Class: GamesAndRpgParadise::GUI::HangmanGameWindow

Inherits:
Gosu::Window
  • Object
show all
Includes:
Base::Extensions
Defined in:
lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb

Constant Summary collapse

WIDTH =
#

WIDTH

#
880
HEIGHT =
#

HEIGHT

#
880

Constants included from CommonExtensions

CommonExtensions::CONTROL_C_CODE, CommonExtensions::N

Class Method Summary collapse

Instance Method Summary collapse

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, #register_sigint, #remove_this_directory, #rename_file, #reset_the_internal_hash, #return_pwd, #return_today, #touch_file, #wrap, #write_what_into

Methods inherited from Gosu::Window

#gosu_button_down?, #image, #image10?, #image1?, #image2?, #image3?, #image4?, #image5?, #image6?, #image7?, #image8?, #image9?, #on_left_arrow_pressed?, #on_right_arrow_pressed?, #q_means_quit, #set_font, #set_title, #sqrt, #tab_key?, #write_this_text

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ HangmanGameWindow

#

initialize

#


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 42

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  super(WIDTH, HEIGHT, false)
  reset
  set_title 'The Hangman Game'
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

GamesAndRpgParadise::GUI::Hangman[]

#


229
230
231
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 229

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#check_whether_that_character_is_part_of_the_hangman(i = @old_character) ⇒ Object

#

check_whether_that_character_is_part_of_the_hangman

#


204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 204

def check_whether_that_character_is_part_of_the_hangman(
    i = @old_character
  )
  if @game.is_this_character_included?(i)
    e 'Yes, the character '+i+' is included.'
  else # else it was a wrong guess.
    if is_the_game_over?
      e ::Colours.steelblue('GAME OVER!!!')
      disable_user_input
      do_display_game_over_banner
    end
    progress_the_frame_by_plus_one
  end
end

#consider_drawing_the_game_over_textObject

#

consider_drawing_the_game_over_text

#


160
161
162
163
164
165
166
167
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 160

def consider_drawing_the_game_over_text
  if @display_the_game_over_banner
    @font_smaller.draw_text(
      'GAME OVER', 250, 40, 1, 1, 1,
      ::Gosu::COLOUR_GOLD
    )
  end
end

#correct_frame_out_of_bound_valuesObject

#

correct_frame_out_of_bound_values

#


122
123
124
125
126
127
128
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 122

def correct_frame_out_of_bound_values
  if @game.frame_counter? < 0
    @game.frame_counter = 0
  elsif @game.frame_counter? > 6
    @game.frame_counter = 6
  end
end

#disable_user_inputObject

#

disable_user_input

#


133
134
135
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 133

def disable_user_input
  @the_user_may_input_something = false
end

#do_display_game_over_bannerObject

#

do_display_game_over_banner

#


222
223
224
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 222

def do_display_game_over_banner
  @display_the_game_over_banner = true
end

#do_show_the_next_frameObject

#

do_show_the_next_frame

#


100
101
102
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 100

def do_show_the_next_frame
  @game.increment_the_frame_counter_by_plus_one
end

#do_show_the_previous_frameObject

#

do_show_the_previous_frame

#


93
94
95
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 93

def do_show_the_previous_frame
  @game.decrement_the_frame_counter_by_plus_one
end

#drawObject

#

draw (draw tag)

#


195
196
197
198
199
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 195

def draw
  draw_this_frame(@game.frame_counter?)
  @text_input.draw(0)
  consider_drawing_the_game_over_text
end

#draw_this_frame(i) ⇒ Object

#

draw_this_frame

#


146
147
148
149
150
151
152
153
154
155
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 146

def draw_this_frame(i)
  if i.is_a? Numeric
    i = ::GamesAndRpgParadise::Hangman::ARRAY_ASCII_HANGMAN_PROGRESSION[@game.frame_counter?]
  end
  @font.draw_text(
    i,
    10, 10, 0, 1.5, 1.5,
    Gosu::Color::YELLOW
  )
end

#is_the_game_over?Boolean

#

is_the_game_over?

#

Returns:

  • (Boolean)


115
116
117
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 115

def is_the_game_over?
  @game.is_the_game_over?
end

#progress_the_frame_by_plus_oneObject

#

progress_the_frame_by_plus_one

#


107
108
109
110
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 107

def progress_the_frame_by_plus_one
  @game.increase_the_frame_counter_by_plus_one
  @game.check_for_game_over_state
end

#resetObject

#

reset (reset tag)

#


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 58

def reset
  # ======================================================================= #
  # === @font
  #
  # @font = Gosu::Font.new(30, name: 'Hack')
  # ======================================================================= #
  @font = set_font(:hack_30)
  # ======================================================================= #
  # === @font_smaller
  # ======================================================================= #
  @font_smaller = set_font(:hack_25)
  # ======================================================================= #
  # === @game
  # ======================================================================= #
  @game = ::GamesAndRpgParadise::Hangman.new { :do_not_run_yet }
  @game.we_may_not_exit
  # ======================================================================= #
  # === @the_user_may_input_something
  # ======================================================================= #
  @the_user_may_input_something = true
  # ======================================================================= #
  # === @display_the_game_over_banner
  # ======================================================================= #
  @display_the_game_over_banner = false
  # ======================================================================= #
  # === @old_character
  # ======================================================================= #
  @old_character = ''
  @text_input = TextField.new(self, 300, 250)
  self.text_input = @text_input 
end

#runObject

#

run (run tag)

#


140
141
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 140

def run
end

#updateObject

#

update (update tag)

#


172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/games_and_rpg_paradise/gui/gosu/hangman/hangman.rb', line 172

def update
  on_right_arrow_pressed? { # right arrow key is pressed
    do_show_the_next_frame
  }
  on_left_arrow_pressed? { # left arrow key is pressed
    do_show_the_previous_frame
  }
  q_means_quit
  if @the_user_may_input_something
    if @old_character == @text_input.text
    else
      @old_character = @text_input.text
      unless @old_character.empty?
        check_whether_that_character_is_part_of_the_hangman(@old_character)
      end
    end
    correct_frame_out_of_bound_values
  end
end