Class: Tetris

Inherits:
Object
  • Object
show all
Includes:
Glimmer::UI::CustomShell
Defined in:
lib/glimmer-dsl-opal/samples/elaborate/tetris/view/block.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/model/game.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/model/block.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/view/playfield.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/model/past_game.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/model/tetromino.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/view/score_lane.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/view/tetris_menu_bar.rb,
lib/glimmer-dsl-opal/samples/elaborate/tetris/view/high_score_dialog.rb

Overview

Copyright © 2007-2022 Andy Maleh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Modules: Model, View

Constant Summary collapse

BLOCK_SIZE =
37
FONT_NAME =
'Menlo'
FONT_TITLE_HEIGHT =
32
FONT_TITLE_STYLE =
:bold
BEVEL_CONSTANT =
20

Instance Attribute Summary collapse

Attributes included from Glimmer::UI::CustomWidget

#body_root, #options, #parent, #swt_style

Instance Method Summary collapse

Methods included from Glimmer::UI::CustomShell

#close, encoded_request_parameter_string, #hide, included, #initialize, #open, request_parameter_string, requested?, requested_and_not_handled?, #show, #start_event_loop, #visible?

Methods included from Glimmer::UI::CustomWidget

add_custom_widget_namespaces_for, #add_observer, #async_exec, #attribute_setter, #can_add_observer?, #can_handle_observation_request?, #content, custom_widget_namespaces, for, #get_attribute, #handle_observation_request, #has_attribute?, #has_instance_method?, #has_style?, included, #initialize, #local_respond_to?, #method_missing, namespaces_for_class, #post_initialize_child, reset_custom_widget_namespaces, #respond_to?, #set_attribute, #sync_exec

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::UI::CustomWidget

Instance Attribute Details

#gameObject (readonly)

Returns the value of attribute game.



41
42
43
# File 'lib/glimmer-dsl-opal/samples/elaborate/tetris.rb', line 41

def game
  @game
end

Instance Method Details

#show_about_dialogObject



143
144
145
146
147
148
# File 'lib/glimmer-dsl-opal/samples/elaborate/tetris.rb', line 143

def show_about_dialog
  message_box {
    text 'Glimmer Tetris'
    message "Glimmer Tetris\n\nGlimmer DSL for SWT Sample\n\nLeft is A\nRight is D\nDown is S\nUp is W\nRotate Left is Q\nRotate Right is E\nAlternatively:\nUse arrow keys for movement\nand right/left alt/shift keys for rotation\n\nCopyright (c) 2007-2022 Andy Maleh"
  }.open
end

#show_high_score_dialogObject



137
138
139
140
141
# File 'lib/glimmer-dsl-opal/samples/elaborate/tetris.rb', line 137

def show_high_score_dialog
  return if @high_score_dialog&.visible?
  @high_score_dialog = high_score_dialog(parent_shell: body_root, game: @game) #if @high_score_dialog.nil? || @high_score_dialog.disposed?
  @high_score_dialog.show
end

#start_moving_tetrominos_downObject



127
128
129
130
131
132
133
134
135
# File 'lib/glimmer-dsl-opal/samples/elaborate/tetris.rb', line 127

def start_moving_tetrominos_down
  Async::Task.new do
    work = lambda do
      @game.down!
      Async::Task.new(delay: @game.delay * 1000.0, &work) unless @game.game_over? || body_root.disposed?
    end
    Async::Task.new(delay: @game.delay * 1000.0, &work)
  end
end