Module: GamesParadise::GUI::Gtk::Minesweeper::MineFieldModule
- Includes:
- Gtk::BaseModule
- Included in:
- MineField
- Defined in:
- lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- TITLE =
#
TITLE
#
'Minesweeper - Mine Field Module'
- WIDTH =
#
WIDTH
#
120
- HEIGHT =
#
HEIGHT
#
100
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::MineFieldModule.run ========================================================================= #.
Instance Method Summary collapse
-
#border_size? ⇒ Boolean
# === border_size? ========================================================================= #.
-
#change_to_default_colour ⇒ Object
# === change_to_default_colour.
-
#check_and_modify_concealment(i = @i_conceal_what) ⇒ Object
# === check_and_modify_concealment.
-
#do_reveal ⇒ Object
(also: #reveal)
# === do_reveal.
-
#i_display_what? ⇒ Boolean
(also: #i_display_what)
# === i_display_what? ========================================================================= #.
-
#immortal_mode? ⇒ Boolean
(also: #is_immortal?)
# === immortal_mode? ========================================================================= #.
-
#initialize(i_conceal_what = 'nothing', master_widget = '', x_coordinate = 1, y_coordinate = y, run_already = true) ⇒ Object
# === initialize ========================================================================= #.
-
#on_left_mouse_click ⇒ Object
(also: #click_me)
# === on_left_mouse_click ========================================================================= #.
-
#on_middle_mouse_click ⇒ Object
# === on_middle_mouse_click.
-
#padding? ⇒ Boolean
# === padding? ========================================================================= #.
-
#register_signals ⇒ Object
# === register_signals.
-
#reset ⇒ Object
# === reset.
-
#run ⇒ Object
# === run ========================================================================= #.
-
#set_concealment(i = 'nothing') ⇒ Object
# === set_concealment.
-
#set_concealment_and_image(i = 'nothing') ⇒ Object
# === set_concealment_and_image.
-
#set_new_image(i = 'nothing') ⇒ Object
# === set_new_image.
-
#x? ⇒ Boolean
(also: #x_coordinate, #x)
# === x ========================================================================= #.
-
#y? ⇒ Boolean
(also: #y_coordinate, #y)
# === y ========================================================================= #.
Instance Attribute Details
#i_conceal_what ⇒ Object
can contain m, 0, 1, 2 and so on.
27 28 29 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 27 def i_conceal_what @i_conceal_what end |
Class Method Details
.run ⇒ Object
#
GamesParadise::GUI::Gtk::Minesweeper::MineFieldModule.run
#
405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 405 def self.run require 'gtk_paradise/run' _ = ::GamesParadise::GUI::Gtk::Minesweeper::MineFieldModule.new r = ::Gtk.run r << _ r.set_size_request( _.width?, _.height? ) r.automatic_title r.top_left_then_run end |
Instance Method Details
#border_size? ⇒ Boolean
#
border_size?
#
165 166 167 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 165 def border_size? 2 end |
#change_to_default_colour ⇒ Object
#
change_to_default_colour
Here you can change back to the default colour again.
#
389 390 391 392 393 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 389 def change_to_default_colour # modify_background( :prelight, :darkorchid ) # modify_background( :active, :grey ) # modify_background( :normal, :white ) end |
#check_and_modify_concealment(i = @i_conceal_what) ⇒ Object
#
check_and_modify_concealment
When I am clicked, we check the concealment.
We check on the value of @i_conceal_what.
If we have the immortal-mode set on, then we can conceal again on a left-mouse button click event.
#
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 276 def check_and_modify_concealment( i = @i_conceal_what ) case i # case tag when 'mine', 'm' set_concealment_and_image('mine') when 'nothing','0', :blank set_concealment_and_image('blank') when '1' set_concealment_and_image('one') # how many mines when '2' set_concealment_and_image('two') when '3' set_concealment_and_image('three') when '4' set_concealment_and_image('four') when '5' set_concealment_and_image('five') when '6' set_concealment_and_image('six') when '7' set_concealment_and_image('seven') when '8' set_concealment_and_image('eight') end end |
#do_reveal ⇒ Object Also known as: reveal
#
do_reveal
This action reveals the mine field.
#
262 263 264 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 262 def do_reveal check_and_modify_concealment end |
#i_display_what? ⇒ Boolean Also known as: i_display_what
#
i_display_what?
#
182 183 184 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 182 def i_display_what? @i_display_what end |
#immortal_mode? ⇒ Boolean Also known as: is_immortal?
#
immortal_mode?
#
380 381 382 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 380 def immortal_mode? @master_widget.immortal_mode? end |
#initialize(i_conceal_what = 'nothing', master_widget = '', x_coordinate = 1, y_coordinate = y, run_already = true) ⇒ Object
#
initialize
#
55 56 57 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 89 90 91 92 93 94 95 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 55 def initialize( i_conceal_what = 'nothing', = '', x_coordinate = 1, y_coordinate = y, run_already = true ) super() reset @master_widget = # Keep a reference to the master widget. @x_coordinate = x_coordinate.to_i # stores x coord @y_coordinate = y_coordinate.to_i # stores y coord # ======================================================================= # # @i_conceal_what will carry the name of the hidden field. Can be a # number like 4, 5 etc but can also be the value blank - or, in the # worst case for the player, it can contain a mine. >:) # ======================================================================= # set_concealment(i_conceal_what) # ======================================================================= # # @i_display_what will show what we currently have on our face. # # Options are: # # cover, flag, flag?, revealed # # The default is cover. # ======================================================================= # @i_display_what = 'cover' case @i_conceal_what when 'rand' rand(2) == 0 ? @i_conceal_what = 'nothing' : @i_conceal_what = 'mine' end change_to_default_colour # default colour of our widgetset self.can_focus = false set_size_request( ::GamesParadise::Minesweeper::BUTTON_BASE_DIMENSION, ::GamesParadise::Minesweeper::BUTTON_BASE_DIMENSION ) register_signals run if run_already end |
#on_left_mouse_click ⇒ Object Also known as: click_me
#
on_left_mouse_click
#
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 358 def on_left_mouse_click if @flag_i_was_clicked_already and immortal_mode? @flag_i_was_clicked_already = false check_and_modify_concealment(:blank) else check_and_modify_concealment # linker knopf @flag_i_was_clicked_already = true end case @i_conceal_what when 'm', 'mine' # User stepped on a mine. @master_widget.set_game_over when 'blank' @master_widget.check_for_surrounding_blanks(x?, y?) else # e 'DEBUG I CONCEAL THIS -> ' # e @i_conceal_what end end |
#on_middle_mouse_click ⇒ Object
#
on_middle_mouse_click
Delegate to the master-widget here.
#
151 152 153 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 151 def on_middle_mouse_click @master_widget.check_for_empty_fields(x, y) if @master_widget end |
#padding? ⇒ Boolean
#
padding?
#
158 159 160 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 158 def padding? 2 end |
#register_signals ⇒ Object
#
register_signals
Register signals, in particular when a user clicks on a minefield.
#
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 318 def register_signals { |, event| unless @master_widget.game_over? if event.event_type == Gdk::EventType::BUTTON_PRESS # normaler klick, einfacher klick if event. == 1 # Left mouse button click. unless @flag_i_was_clicked_already if @i_display_what == 'flag' # Do nothing if user clicked on a red flag. else on_left_mouse_click end end elsif event. == 2 on_middle_mouse_click if @flag_i_was_clicked_already # only if we were already clicked, is # middle clicking enabled! else # rechtsklick unless @flag_i_was_clicked_already case @i_display_what when 'cover' set_new_image(:red_flag) when 'flag' set_new_image(:flag_quotation) when 'flag?' set_new_image(:empty) end end end elsif event.event_type == Gdk::Event::BUTTON_RELEASE # p "mausknopf wurde losgelassen" end # else # self.modify_bg( Gtk::StateType::ACTIVE, WHITE ) end # unless game over } end |
#reset ⇒ Object
#
reset
This method will reset all relevant flags and revert to the old colour as well.
#
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 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 103 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) use_project_css_file # ======================================================================= # # === @master_widget # ======================================================================= # @master_widget = nil # ======================================================================= # # === @main_image # ======================================================================= # @main_image = gtk_image # This instance variable will store our image. # ======================================================================= # # === @flag_i_was_clicked_already # # At start-up, the widget here has not yet received a click-event, # so this variable will keep track of that game-state. # ======================================================================= # @flag_i_was_clicked_already = false # ======================================================================= # # === @y_coordinate # ======================================================================= # @y_coordinate = 0 set_new_image(:nothing) change_to_default_colour end |
#run ⇒ Object
#
run
#
398 399 400 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 398 def run add(@main_image) end |
#set_concealment(i = 'nothing') ⇒ Object
#
set_concealment
Sets a new concealment. Will modify @i_conceal_what. Use ONLY this method when modifying @i_conceal_what.
#
175 176 177 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 175 def set_concealment(i = 'nothing') @i_conceal_what = i.to_s end |
#set_concealment_and_image(i = 'nothing') ⇒ Object
#
set_concealment_and_image
Sets our var, and also the image.
#
308 309 310 311 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 308 def set_concealment_and_image(i = 'nothing') set_concealment(i) set_new_image(i) end |
#set_new_image(i = 'nothing') ⇒ Object
#
set_new_image
This simply sets a new image, but does not modify @i_conceal_what.
#
191 192 193 194 195 196 197 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 191 def set_new_image(i = 'nothing') case i.to_s when '0' @main_image.set_file(GamesParadise::Minesweeper::BASE_IMG_DIR+'bang.png') # explosion when '1','flag-question','flag?','flag_quotation' @i_display_what = 'flag?' @main_image.set_file(GamesParadise::Minesweeper::FLAGS_IMG_DIR+'flag-question.png') when '2','flag','red_flag' @i_display_what = 'flag' @main_image.set_file(GamesParadise::Minesweeper::FLAGS_IMG_DIR+'flag.png') when '3', 'mine', 'm' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::BASE_IMG_DIR+'mine.png') when '4', 'one' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'one.png') when '5', 'two' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'two.png') when '6', 'three' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'three.png') when '7', 'four' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'four.png') when '8', 'five' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'five.png') when '9', 'six' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'six.png') when '10', 'seven' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'seven.png') when '11', 'eight' @i_display_what = 'revealed' @main_image.set_file(GamesParadise::Minesweeper::NUMBERS_IMG_DIR+'eight.png') # ======================================================================= # # Nothing means blank - we set to the "blank" status again. # ======================================================================= # when 'blank', 'empty', 'nothing' @i_display_what = 'cover' @main_image.clear # Modify the background of blank ones. # @main_image.modify_bg(Gtk::STATE_NORMAL, Gdk::Color.parse('black')) end end |
#x? ⇒ Boolean Also known as: x_coordinate, x
#
x
#
244 245 246 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 244 def x? @x_coordinate end |
#y? ⇒ Boolean Also known as: y_coordinate, y
#
y
#
252 253 254 |
# File 'lib/games_paradise/gui/shared_code/minesweeper/mine_field_module.rb', line 252 def y? @y_coordinate end |