Class: GamesAndRpgParadise::GUI::Gtk::Memory::Card

Inherits:
Gtk::Button
  • Object
show all
Includes:
Memory, Gtk::BaseModule
Defined in:
lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb

Constant Summary

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::TITLE, Memory::USE_THIS_FONT_FAMILY

Instance Method Summary collapse

Constructor Details

#initialize(this_is_the_card_that_will_be_revealed_on_a_click_event, parent_widget) ⇒ Card

#

initialize

#


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb', line 29

def initialize(
    this_is_the_card_that_will_be_revealed_on_a_click_event,
    parent_widget
  )
  super()
  reset
  @parent_widget = parent_widget
  @random_card_image = ::Gtk::Image.new(file: FILE_CARD_RANDOM)
  @random_card_image.bblack1 
  set_image(@random_card_image)
  @this_is_the_card_that_will_be_revealed_on_a_click_event =
    this_is_the_card_that_will_be_revealed_on_a_click_event
  @image_that_will_be_revealed_on_a_click_event =
    ::Gtk::Image.new(
      file: @this_is_the_card_that_will_be_revealed_on_a_click_event
    )
  @image_that_will_be_revealed_on_a_click_event.bblack1
  show_all
  on_clicked {
    if @was_clicked
      do_hide_the_image
      @parent_widget.decrement_n_cards_are_revealed
    else
      set_image(
        @image_that_will_be_revealed_on_a_click_event
      )
      @parent_widget.increment_n_cards_are_revealed
      @was_clicked = true
      if @parent_widget.n_cards_are_revealed == 2
        Thread.new {
          sleep 0.5
          @parent_widget.compare_the_two_revealed_cards
        }
      end
    end
  }
  set_border_width(0)
  bblack1
end

Instance Method Details

#am_i_revealed?Boolean

#

am_i_revealed?

#

Returns:

  • (Boolean)


84
85
86
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb', line 84

def am_i_revealed?
  @was_clicked
end

#do_hide_the_imageObject

#

do_hide_the_image

This method will specifically NOT tamper with the counter of the parent widget.

#


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

def do_hide_the_image
  set_image(@random_card_image)
  @was_clicked = false
end

#remove_it_permanentlyObject

#

remove_it_permanently

#


110
111
112
113
114
115
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb', line 110

def remove_it_permanently
  grey_out
  this_image = ::Gtk::Image.new(file: FILE_BLACK_BACKGROUND)
  this_image.bblack1
  set_image(this_image) # Remove the image here.
end

#resetObject

#

reset (reset tag)

#


72
73
74
75
76
77
78
79
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb', line 72

def reset
  # ======================================================================= #
  # === @was_clicked
  #
  # This flag variable keeps track as to whether it was clicked or not.
  # ======================================================================= #
  @was_clicked = false
end

#this_is_the_card_that_will_be_revealed_on_a_click_event?Boolean Also known as: this_is_the_card_that_will_be_revealed_on_a_click_event, path?

#

this_is_the_card_that_will_be_revealed_on_a_click_event?

#

Returns:

  • (Boolean)


102
103
104
# File 'lib/games_and_rpg_paradise/gui/shared_code/memory/card.rb', line 102

def this_is_the_card_that_will_be_revealed_on_a_click_event?
  @this_is_the_card_that_will_be_revealed_on_a_click_event
end