Class: Textbringer::TetrisMode

Inherits:
GamegridMode show all
Defined in:
lib/textbringer/modes/tetris_mode.rb

Constant Summary collapse

BOARD_WIDTH =
10
BOARD_HEIGHT =
20
BORDER_VALUE =

cell value used for the 1-cell border around the board

8
PIECE_COLORS =
{
  1 => :gamegrid_block_cyan,
  2 => :gamegrid_block_yellow,
  3 => :gamegrid_block_magenta,
  4 => :gamegrid_block_green,
  5 => :gamegrid_block_red,
  6 => :gamegrid_block_blue,
  7 => :gamegrid_block_white,
}.freeze
PIECE_NAMES =
["", "I", "O", "T", "S", "Z", "J", "L"].freeze
PIECES =

Pieces[rotation][row][col] — 4×4 bounding box, 1-indexed types

[
  nil,
  # 1: I (cyan)
  [
    [[0,0,0,0],[1,1,1,1],[0,0,0,0],[0,0,0,0]],
    [[0,0,1,0],[0,0,1,0],[0,0,1,0],[0,0,1,0]],
    [[0,0,0,0],[0,0,0,0],[1,1,1,1],[0,0,0,0]],
    [[0,1,0,0],[0,1,0,0],[0,1,0,0],[0,1,0,0]],
  ],
  # 2: O (yellow)
  [
    [[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,1,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
  ],
  # 3: T (magenta)
  [
    [[0,1,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,0,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]],
    [[0,0,0,0],[1,1,1,0],[0,1,0,0],[0,0,0,0]],
    [[0,1,0,0],[1,1,0,0],[0,1,0,0],[0,0,0,0]],
  ],
  # 4: S (green)
  [
    [[0,1,1,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]],
    [[1,0,0,0],[1,1,0,0],[0,1,0,0],[0,0,0,0]],
    [[0,1,1,0],[1,1,0,0],[0,0,0,0],[0,0,0,0]],
    [[1,0,0,0],[1,1,0,0],[0,1,0,0],[0,0,0,0]],
  ],
  # 5: Z (red)
  [
    [[1,1,0,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,0,1,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]],
    [[1,1,0,0],[0,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,0,1,0],[0,1,1,0],[0,1,0,0],[0,0,0,0]],
  ],
  # 6: J (blue)
  [
    [[1,0,0,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,1,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],
    [[0,0,0,0],[1,1,1,0],[0,0,1,0],[0,0,0,0]],
    [[0,1,0,0],[0,1,0,0],[1,1,0,0],[0,0,0,0]],
  ],
  # 7: L (white)
  [
    [[0,0,1,0],[1,1,1,0],[0,0,0,0],[0,0,0,0]],
    [[0,1,0,0],[0,1,0,0],[0,1,1,0],[0,0,0,0]],
    [[0,0,0,0],[1,1,1,0],[1,0,0,0],[0,0,0,0]],
    [[1,1,0,0],[0,1,0,0],[0,1,0,0],[0,0,0,0]],
  ],
].freeze

Constants inherited from Mode

Mode::DEFAULT_SYNTAX_TABLE

Constants included from Commands

Commands::CLIPBOARD_AVAILABLE, Commands::COMPLETION_POPUP_STATUS, Commands::CTAGS, Commands::EMAIL_REGEXP, Commands::HELP_RING, Commands::ISEARCH_STATUS, Commands::ISPELL_STATUS, Commands::ISPELL_WORD_REGEXP, Commands::KEYBOARD_MACROS, Commands::LSP_DOCUMENT_VERSIONS, Commands::LSP_STATUS, Commands::REGISTERS, Commands::RE_SEARCH_STATUS, Commands::URI_REGEXP

Constants included from Utils

Utils::COMPLETION, Utils::EXPRESSION_COMPLETOR, Utils::EXPRESSION_COMPLETOR_OPTIONS, Utils::HOOKS

Instance Attribute Summary collapse

Attributes inherited from Mode

#buffer

Instance Method Summary collapse

Methods inherited from GamegridMode

#highlight, inherited

Methods inherited from Mode

define_generic_command, define_local_command, define_syntax, #highlight, inherited, list, #name, #syntax_table

Methods included from Commands

[], #buffer_uri, #command_help, command_table, #completion_popup_done, completion_popup_mode_active?, #completion_popup_pre_command_hook, #completion_popup_start, #current_prefix_arg, define_command, #ensure_ispell_active, #execute_keyboard_macro, #get_tags, #insert_completion, #isearch_done, #isearch_mode, #isearch_mode?, #isearch_pre_command_hook, #isearch_prompt, #isearch_repeat, #isearch_repeat_backward, #isearch_repeat_forward, #isearch_search, #ispell_done, #ispell_forward, #ispell_mode, #keymap_bindings, list, #lsp_after_set_visited_file_name_hook, #lsp_close_signature_window, #lsp_completion_context, #lsp_find_file_hook, #lsp_open_document, #lsp_position, #lsp_setup_buffer_hooks, #lsp_show_signature_window, #lsp_signature_pre_command_hook, #lsp_text_document_sync_kind, #lsp_utf16_length, #match_beginning, #match_end, #match_string, #message_misspelled, #number_prefix_arg, #prefix_numeric_value, #read_input_method_name, #read_keyboard_macro, #read_register, #read_theme_name, #replace_match, undefine_command, #universal_argument_mode

Methods included from Utils

add_hook, background, complete_for_minibuffer, delete_completions_window, foreground, foreground!, get_hooks, message, read_buffer, read_char, read_command_name, read_encoding, read_event, read_expression, read_file_name, read_from_minibuffer, read_key_sequence, read_object, read_single_char, received_keyboard_quit?, remove_hook, ruby_install_name, run_hooks, run_hooks_in, self_insert_and_exit_minibuffer, set_transient_map, show_exception, sit_for, sleep_for, y_or_n?, yes_or_no?

Constructor Details

#initialize(buffer) ⇒ TetrisMode

Returns a new instance of TetrisMode.



91
92
93
94
95
96
97
# File 'lib/textbringer/modes/tetris_mode.rb', line 91

def initialize(buffer)
  super
  buffer.keymap = TETRIS_MODE_MAP
  @game_over = true
  @paused    = false
  @grid      = nil
end

Instance Attribute Details

#game_overObject (readonly)

Returns the value of attribute game_over.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def game_over
  @game_over
end

#levelObject (readonly)

Returns the value of attribute level.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def level
  @level
end

#lines_clearedObject (readonly)

Returns the value of attribute lines_cleared.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def lines_cleared
  @lines_cleared
end

#next_typeObject (readonly)

Returns the value of attribute next_type.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def next_type
  @next_type
end

#pausedObject (readonly)

Returns the value of attribute paused.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def paused
  @paused
end

#piece_rotObject (readonly)

Returns the value of attribute piece_rot.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def piece_rot
  @piece_rot
end

#piece_typeObject (readonly)

Returns the value of attribute piece_type.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def piece_type
  @piece_type
end

#piece_xObject (readonly)

Returns the value of attribute piece_x.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def piece_x
  @piece_x
end

#piece_yObject (readonly)

Returns the value of attribute piece_y.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def piece_y
  @piece_y
end

#scoreObject (readonly)

Returns the value of attribute score.



87
88
89
# File 'lib/textbringer/modes/tetris_mode.rb', line 87

def score
  @score
end