Class: GamesParadise::GUI::Gtk::Nibbles
- Inherits:
-
Gtk::Window
- Object
- Gtk::Window
- GamesParadise::GUI::Gtk::Nibbles
- Includes:
- Gtk::BaseModuleAndAppModule
- Defined in:
- lib/games_paradise/gui/gtk3/nibbles/nibbles.rb
Constant Summary collapse
- NAMESPACE =
#
NAMESPACE
#
inspect
- DOT_SIZE =
#
DOT_SIZE
#
::GamesParadise::Nibbles::DOT_SIZE
- ALL_DOTS =
#
ALL_DOTS
The ALL_DOTS constant defines the maximum number of possible dots on the Board.
#
::GamesParadise::Nibbles::WIDTH_OF_THE_BOARD * ::GamesParadise::Nibbles::HEIGHT / (DOT_SIZE * DOT_SIZE)
- TITLE =
#
TITLE
#
'Nibbles'
- RAND_POS =
#
RAND_POS
The RAND_POS constant is used to calculate a random position of the apple.
#
26
- DELAY =
#
DELAY
The DELAY constant determines the speed of the game.
#
100
- LENGTH_OF_THE_SNAKE =
#
LENGTH_OF_THE_SNAKE
#
4
Class Method Summary collapse
-
.run ⇒ Object
# === GamesParadise::GUI::Gtk::Nibbles.run ========================================================================= #.
-
.x_coordinate? ⇒ Boolean
# === GamesParadise::GUI::Gtk::Nibbles.x_coordinate? ========================================================================= #.
-
.y_coordinate? ⇒ Boolean
# === GamesParadise::GUI::Gtk::Nibbles.y_coordinate? ========================================================================= #.
Instance Method Summary collapse
-
#connect_skeleton ⇒ Object
# === connect_skeleton ========================================================================= #.
-
#initialize ⇒ Nibbles
constructor
# === initialize ========================================================================= #.
-
#on_key_down(widget, event) ⇒ Object
# === on_key_down.
-
#reset ⇒ Object
# === reset ========================================================================= #.
-
#run ⇒ Object
# === run ========================================================================= #.
Constructor Details
#initialize ⇒ Nibbles
#
initialize
#
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 101 def initialize super() reset set_title(TITLE) signal_connect(:destroy) { ::Gtk.main_quit } signal_connect(:key_press_event) { |, event| on_key_down(, event) # Delegate all key-press-events into this method. } set_default_size( ::GamesParadise::Nibbles::WIDTH_OF_THE_BOARD, ::GamesParadise::Nibbles::HEIGHT ) set_window_position :center enable_simple_exit run end |
Class Method Details
.run ⇒ Object
#
GamesParadise::GUI::Gtk::Nibbles.run
#
161 162 163 164 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 161 def self.run GamesParadise::GUI::Gtk::Nibbles.new ::Gtk.main end |
.x_coordinate? ⇒ Boolean
#
GamesParadise::GUI::Gtk::Nibbles.x_coordinate?
#
87 88 89 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 87 def self.x_coordinate? @x end |
.y_coordinate? ⇒ Boolean
#
GamesParadise::GUI::Gtk::Nibbles.y_coordinate?
#
94 95 96 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 94 def self.y_coordinate? @y end |
Instance Method Details
#connect_skeleton ⇒ Object
#
connect_skeleton
#
146 147 148 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 146 def connect_skeleton add(@board) end |
#on_key_down(widget, event) ⇒ Object
#
on_key_down
This method will delegate the on-key-down event to class NibblesBoard.
#
138 139 140 141 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 138 def on_key_down(, event) # key = event.keyval @board.on_key_down(event) end |
#reset ⇒ Object
#
reset
#
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 121 def reset # ======================================================================= # # === @configuration # ======================================================================= # @configuration = [true, __dir__, NAMESPACE] # ======================================================================= # # === @board # ======================================================================= # @board = NibblesBoard.new end |
#run ⇒ Object
#
run
#
153 154 155 156 |
# File 'lib/games_paradise/gui/gtk3/nibbles/nibbles.rb', line 153 def run connect_skeleton show_all end |