Module: GamesAndRpgParadise::GUI::Gtk::MemoryModule

Includes:
Memory, Gtk::BaseModule
Included in:
MemoryForGtk3
Defined in:
lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
TITLE =
#

TITLE

#
::GamesAndRpgParadise::Memory::TITLE
WIDTH =
#

WIDTH

#
500
HEIGHT =
#

HEIGHT

#
500

Constants included from Memory

Memory::ARRAY_IMAGES_FOR_THE_MEMORY_GAME, Memory::FILE_BLACK_BACKGROUND, Memory::FILE_CAMEL_HEAD, Memory::FILE_CARD_RANDOM, Memory::FILE_DONKEY, Memory::FILE_FROG, Memory::FILE_LION, Memory::FILE_NEW_GAME, Memory::FILE_OCTOPUS, Memory::FILE_SAD_CRAB, Memory::FILE_SHEEP, Memory::FILE_SNAIL, Memory::FILE_SPERM_WHALE, Memory::FILE_UNICORN, Memory::GAME_MESSAGE_YOU_WON, Memory::IMAGES_DIRECTORY, Memory::SCREENHEIGHT, Memory::SCREENWIDTH, Memory::USE_THIS_FONT_FAMILY

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(i = ARGV) ⇒ Object

#

GamesAndRpgParadise::GUI::Gtk::MemoryModule.run

#


205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 205

def self.run(
    i = ARGV
  )
  require 'gtk_paradise/run'
  _ = ::GamesAndRpgParadise::GUI::Gtk::MemoryForGtk3.new(i)
  r = ::Gtk.run
  r << _
  r.set_size_request(_.width?, _.height?)
  r.automatic_title
  r.set_border_width(0)
  r.top_left_then_run
end

Instance Method Details

#border_size?Boolean

#

border_size?

#

Returns:

  • (Boolean)


101
102
103
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 101

def border_size?
  0
end

#compare_the_two_revealed_cardsObject

#

compare_the_two_revealed_cards

#


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 155

def compare_the_two_revealed_cards
  selection = @array_all_buttons.select {|button|
    button.am_i_revealed?
  }
  filenames = selection.map {|entry| File.basename(entry.path?) }
  do_hide_all_the_cards
  if filenames.uniq.count == 1
    # ===================================================================== #
    # In this case they must be the same.
    # ===================================================================== #
    selection.each {|this_button|
      this_button.remove_it_permanently
    }
  end
end

#connect_skeletonObject

#

connect_skeleton (connect tag)

#


118
119
120
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 118

def connect_skeleton
  abort_on_exception
end

#create_skeletonObject

#

create_skeleton (create tag)

#


108
109
110
111
112
113
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 108

def create_skeleton
  @grid = gtk_grid
  @grid.css_class('pad0px')
  @grid.set_column_spacing(0)
  @grid.set_row_spacing(0)
end

#decrement_n_cards_are_revealedObject

#

decrement_n_cards_are_revealed

#


184
185
186
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 184

def decrement_n_cards_are_revealed
  @n_cards_are_revealed -= 1
end

#do_hide_all_the_cardsObject

#

do_hide_all_the_cards

#


174
175
176
177
178
179
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 174

def do_hide_all_the_cards
  @n_cards_are_revealed = 0
  @array_all_buttons.each {|this_button|
    this_button.do_hide_the_image
  }
end

#increment_n_cards_are_revealedObject

#

increment_n_cards_are_revealed

#


191
192
193
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 191

def increment_n_cards_are_revealed
  @n_cards_are_revealed += 1
end

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

#

initialize

#


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 47

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

#n_cards_are_revealed?Boolean Also known as: n_cards_are_revealed

#

n_cards_are_revealed?

#

Returns:

  • (Boolean)


198
199
200
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 198

def n_cards_are_revealed?
  @n_cards_are_revealed
end

#padding?Boolean

#

padding?

#

Returns:

  • (Boolean)


94
95
96
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 94

def padding?
  0
end

#resetObject

#

reset (reset tag)

#


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
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 63

def reset
  reset_the_internal_variables
  # ======================================================================= #
  # === @configuration
  # ======================================================================= #
  @configuration = [true, __dir__, NAMESPACE]
  # ======================================================================= #
  # === @title
  # ======================================================================= #
  @title  = TITLE
  # ======================================================================= #
  # === @width
  # ======================================================================= #
  set_width(WIDTH)
  # ======================================================================= #
  # === @height
  # ======================================================================= #
  set_height(HEIGHT)
  # ======================================================================= #
  # === @n_cards_are_revealed
  # ======================================================================= #
  @n_cards_are_revealed = 0
  set_use_this_font(:dejavu_condensed_22)
  use_gtk_paradise_project_css_file
  infer_the_size_automatically
  background_colour(:black)
end

#runObject

#

run (run tag)

#


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
150
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/memory_module.rb', line 125

def run
  create_skeleton_then_connect_skeleton
  # ======================================================================= #
  # We will use all but the last two elements, as these are different
  # cards, e. g. a new game.
  # ======================================================================= #
  _ = ARRAY_IMAGES_FOR_THE_MEMORY_GAME[0 .. -3]
  _.shuffle!
  _ = _ * 2
  _.shuffle!
  top_position = 0
  index = 0
  @array_all_buttons = []
  _.each {|this_file_path|
    button = GamesAndRpgParadise::GUI::Gtk::Memory::Card.new(this_file_path, self)
    @array_all_buttons << button
    # .attach(child_widget, left_pos, top_pos, width, height)
    if (index > 0) and ((index % 5) == 0)
      top_position += 1
      index = 0
    end
    @grid.attach(button,index, top_position, 1, 1)
    index += 1
  }
  minimal(@grid, 0)
end