Module: GamesParadise::GUI::Gtk::Minesweeper::MinesweeperGameModule
- Includes:
- Gtk::BaseModule
- Included in:
- MinesweeperGame
- Defined in:
- lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- TITLE =
#
TITLE
#
'Minesweeper Game'
- WIDTH =
#
WIDTH
#
400
- HEIGHT =
#
HEIGHT
#
400
- CHEAT_IMMORTAL =
#
CHEAT_IMMORTAL
Here are some game cheats which you can set.
#
false
Instance Attribute Summary collapse
-
#i_conceal_what ⇒ Object
can contain m, 0, 1, 2 and so on.
Class Method Summary collapse
-
.run ⇒ Object
# === GamesParadise::GUI::Gtk::Minesweeper::MinesweeperGameModule.run ========================================================================= #.
Instance Method Summary collapse
-
#array_mine_fields? ⇒ Boolean
(also: #array_mine_fields)
# === array_mine_fields? ========================================================================= #.
-
#become_immortal ⇒ Object
# === become_immortal ========================================================================= #.
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#check_for_empty_fields(x, y) ⇒ Object
# === check_for_empty_fields ========================================================================= #.
-
#check_for_surrounding_blanks(x_coord, y_coord) ⇒ Object
# === check_for_surrounding_blanks ========================================================================= #.
-
#click_restart_button ⇒ Object
# === click_restart_button ========================================================================= #.
-
#connect_skeleton ⇒ Object
# === connect_skeleton ========================================================================= #.
-
#create_a_new_grid_placer ⇒ Object
# === create_a_new_grid_placer.
-
#create_buttons ⇒ Object
# === create_buttons ========================================================================= #.
-
#create_checkbox ⇒ Object
# === create_checkbox.
-
#create_fixed ⇒ Object
# === create_fixed.
-
#create_labels ⇒ Object
# === create_labels ========================================================================= #.
-
#create_new_coloured_button(use_this_title = 'Hello World', is_it_a_quit_button = false) ⇒ Object
# === create_new_coloured_button ========================================================================= #.
-
#create_skeleton ⇒ Object
# === create_skeleton ========================================================================= #.
-
#favicon? ⇒ Boolean
# === favicon? ========================================================================= #.
-
#find_mine_field_in_array(x_coord, y_coord) ⇒ Object
# === find_mine_field_in_array.
-
#game_over? ⇒ Boolean
(also: #game_over)
# === game_over? ========================================================================= #.
-
#grid_placer? ⇒ Boolean
(also: #grid_placer)
# === grid_placer? ========================================================================= #.
-
#immortal_mode? ⇒ Boolean
# === immortal_mode? ========================================================================= #.
-
#initialize(how_many_mines_on_gamemap = 15, be_verbose = true, run_already = true) ⇒ Object
# === initialize ========================================================================= #.
-
#n_mines? ⇒ Boolean
(also: #n_mines)
# === n_mines? ========================================================================= #.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#populate_game_map ⇒ Object
# === populate_game_map.
-
#reset ⇒ Object
# === reset.
-
#restart_the_game ⇒ Object
# === restart_the_game.
-
#reveal_all ⇒ Object
# === reveal_all.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_game_over ⇒ Object
# === set_game_over.
Instance Attribute Details
#i_conceal_what ⇒ Object
can contain m, 0, 1, 2 and so on.
25 26 27 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 25 def i_conceal_what @i_conceal_what end |
Class Method Details
.run ⇒ Object
#
GamesParadise::GUI::Gtk::Minesweeper::MinesweeperGameModule.run
#
415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 415 def self.run require 'gtk_paradise/run' _ = ::GamesParadise::GUI::Gtk::Minesweeper::MinesweeperGame.new r = ::Gtk.run r << _ r.set_size_request( _.width?, _.height? ) r.add_shortcut(:r, 'click_restart_button', :alt) r.automatic_title r.top_left_then_run end |
Instance Method Details
#array_mine_fields? ⇒ Boolean Also known as: array_mine_fields
#
array_mine_fields?
#
351 352 353 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 351 def array_mine_fields? @array_mine_fields end |
#become_immortal ⇒ Object
#
become_immortal
#
236 237 238 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 236 def become_immortal @cheat_immortal = true end |
#border_size? ⇒ Boolean
#
border_size?
#
119 120 121 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 119 def border_size? 2 end |
#check_for_empty_fields(x, y) ⇒ Object
#
check_for_empty_fields
#
358 359 360 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 358 def check_for_empty_fields(x,y) check_for_surrounding_blanks(x, y) end |
#check_for_surrounding_blanks(x_coord, y_coord) ⇒ Object
#
check_for_surrounding_blanks
#
365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 365 def check_for_surrounding_blanks(x_coord, y_coord) @grid_placer.return_adjacent_grids( [x_coord, y_coord] ).each { |array_coord| mine = find_mine_field_in_array(array_coord.first.to_s, array_coord[1].to_s) case mine.i_conceal_what when '0' mine.click_me else if mine.i_display_what == 'flag' # pass through end end } end |
#click_restart_button ⇒ Object
#
click_restart_button
#
243 244 245 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 243 def @button_restart.signal_emit(:clicked) end |
#connect_skeleton ⇒ Object
#
connect_skeleton
#
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 250 def connect_skeleton @alignment = gtk_alignment(0.15, 0.15, 0.15, 0.15) @alignment.set_padding(2,1,2,1) vbox = gtk_vbox hbox_top = gtk_hbox hbox_top.pack_start(@label_how_many_mines, expand: false, fill: true, padding: 3) hbox_top.maximal(@smiley_face, 1) vbox.maximal(hbox_top,6) vbox.maximal(@fixed_mine_field,2) hbox = create_paned_hbox(@button_restart, @button_quit) vbox.pack_start(hbox,expand: false, fill: true) _ = create_paned_hbox(@button_check) vbox.pack_start(_,expand: false, fill: true) @alignment.add(vbox) add(@alignment) show_all end |
#create_a_new_grid_placer ⇒ Object
#
create_a_new_grid_placer
Creates a new GridPlacerClass
#
341 342 343 344 345 346 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 341 def create_a_new_grid_placer @grid_placer = ::GamesParadise::Minesweeper::GridPlacer.new( ::GamesParadise::Minesweeper::DIMENSION, @how_many_mines_on_gamemap ) # for the underlying layout end |
#create_buttons ⇒ Object
#
create_buttons
#
227 228 229 230 231 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 227 def @button_restart = ('RestartGame_slateblue') @button_restart.on_clicked { restart_the_game } @button_quit = ('QuitGame_slateblue', :this_is_a_quit_button) end |
#create_checkbox ⇒ Object
#
create_checkbox
Add the button for “immortality”.
#
278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 278 def create_checkbox @button_check = ('Immortal', false) @button_check.set_active(false) # not selected @button_check.hint = 'Having this check button active means that you will not '\ 'die. This may be useful for testing purposes.' @button_check.on_toggled { || if .active? become_immortal elsif not .active? @cheat_immortal = false end } end |
#create_fixed ⇒ Object
#
create_fixed
Our MineField.
#
314 315 316 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 314 def create_fixed @fixed_mine_field = gtk_fixed end |
#create_labels ⇒ Object
#
create_labels
#
188 189 190 191 192 193 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 188 def create_labels @label_how_many_mines = label( @how_many_mines_on_gamemap.to_s+" Mines are\non the field." ) @label_how_many_mines.make_bold end |
#create_new_coloured_button(use_this_title = 'Hello World', is_it_a_quit_button = false) ⇒ Object
#
create_new_coloured_button
#
217 218 219 220 221 222 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 217 def ( use_this_title = 'Hello World', = false ) (use_this_title, ) end |
#create_skeleton ⇒ Object
#
create_skeleton
#
328 329 330 331 332 333 334 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 328 def create_skeleton create_labels create_a_new_grid_placer create_checkbox create_fixed end |
#favicon? ⇒ Boolean
#
favicon?
#
126 127 128 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 126 def favicon? ::GamesParadise::GUI::Gtk::Minesweeper.image_dir+'symbols/mine.png' end |
#find_mine_field_in_array(x_coord, y_coord) ⇒ Object
#
find_mine_field_in_array
searches our array for the proper entry. Returns our mine field object.
#
135 136 137 138 139 140 141 142 143 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 135 def find_mine_field_in_array( x_coord, y_coord ) @array_mine_fields.each { |mine| if x_coord.to_s == mine.x.to_s return mine if y_coord.to_s == mine.y.to_s end } end |
#game_over? ⇒ Boolean Also known as: game_over
#
game_over?
#
305 306 307 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 305 def game_over? @game_over end |
#grid_placer? ⇒ Boolean Also known as: grid_placer
#
grid_placer?
#
382 383 384 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 382 def grid_placer? @grid_placer end |
#immortal_mode? ⇒ Boolean
#
immortal_mode?
#
210 211 212 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 210 def immortal_mode? @cheat_immortal end |
#initialize(how_many_mines_on_gamemap = 15, be_verbose = true, run_already = true) ⇒ Object
#
initialize
#
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 60 def initialize( how_many_mines_on_gamemap = 15, be_verbose = true, run_already = true ) super(:vertical) reset @how_many_mines_on_gamemap = how_many_mines_on_gamemap if be_verbose efancy "Using #{@how_many_mines_on_gamemap} mines." end @smiley_face = ::GamesParadise::GUI::Gtk::Minesweeper::SmileyFace.new(self) # our smiley image @n_mines = how_many_mines_on_gamemap run if run_already end |
#n_mines? ⇒ Boolean Also known as: n_mines
#
n_mines?
#
181 182 183 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 181 def n_mines? @n_mines end |
#padding? ⇒ Boolean
#
padding?
#
321 322 323 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 321 def padding? 8 end |
#populate_game_map ⇒ Object
#
populate_game_map
This will populate our game map. Use only this method when populating the game map.
#
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 151 def populate_game_map # @grid_placer.display_game_map 1.upto(@grid_placer.grid_dimension) { |i| 1.upto(@grid_placer.grid_dimension) { |index_inner| # puts i.to_s+index_inner.to_s+' '+@grid_placer.hash_grid[i.to_s][index_inner.to_s] # inner value can contain m,0,1,2 and so on. inner_value = @grid_placer.hash_grid[i.to_s][index_inner.to_s] mine = ::GamesParadise::GUI::Gtk::Minesweeper::MineField.new( inner_value, self, i.to_i, index_inner.to_i ) mine.set_new_image # conceal by setting new pseudo image @array_mine_fields << mine # keeps our mine fields # =================================================================== # # We must reverse Y Coordinate because Gtk::Fixed counts this way. # =================================================================== # @fixed_mine_field.put( mine, i.to_i * ::GamesParadise::Minesweeper::BUTTON_BASE_DIMENSION, (@grid_placer.grid_dimension - index_inner.to_i) * ::GamesParadise::Minesweeper::BUTTON_BASE_DIMENSION ) } } end |
#reset ⇒ Object
#
reset
This method will reset all relevant flags and revert to the old colour as well.
#
82 83 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 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 82 def reset reset_the_internal_variables set_use_this_font(:dejavu_condensed_25) # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] # ======================================================================= # # === @title # ======================================================================= # @title = TITLE # ======================================================================= # # === @width # ======================================================================= # set_width(WIDTH) # ======================================================================= # # === @height # ======================================================================= # set_height(HEIGHT) # ======================================================================= # # === @array_mine_fields # ======================================================================= # @array_mine_fields = [] # This array contains all of our mines. # ======================================================================= # # === @game_over # ======================================================================= # @game_over = false # ======================================================================= # # === @cheat_immortal # ======================================================================= # @cheat_immortal = CHEAT_IMMORTAL use_project_css_file end |
#restart_the_game ⇒ Object
#
restart_the_game
This method will restart the game, so it can be played anew/again.
#
391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 391 def restart_the_game # First lets clear our mines: create_a_new_grid_placer populate_game_map @array_mine_fields.each { |mine| mine.i_conceal_what = @grid_placer.hash_grid[mine.x_coordinate.to_s][mine.y_coordinate.to_s] mine.reset } @game_over = false @smiley_face.set_happy_image end |
#reveal_all ⇒ Object
#
reveal_all
Reveal everything with this method.
#
298 299 300 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 298 def reveal_all @array_mine_fields.each { |mine| mine.do_reveal } end |
#run ⇒ Object
#
run
#
406 407 408 409 410 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 406 def run create_skeleton populate_game_map connect_skeleton end |
#set_game_over ⇒ Object
#
set_game_over
Sets that the game is over.
#
200 201 202 203 204 205 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/minesweeper_game_module.rb', line 200 def set_game_over unless immortal_mode? @smiley_face.set_unhappy_image @game_over = true end end |