Class: Rubytris::Field
- Inherits:
-
Object
- Object
- Rubytris::Field
- Defined in:
- lib/rubytris/field.rb
Constant Summary collapse
- WIDTH =
11
- HEIGHT =
20
- FINISH_COUNT =
40
- WALL_CHAR =
"□ "
- BLOCK_CHAR =
"■ "
- NONE_CHAR =
" "
Instance Attribute Summary collapse
-
#point ⇒ Object
readonly
Returns the value of attribute point.
Instance Method Summary collapse
- #are_block?(next_pos) ⇒ Boolean
- #clear ⇒ Object
- #fix(now_pos) ⇒ Object
- #game_finish? ⇒ Boolean
-
#initialize ⇒ Field
constructor
A new instance of Field.
- #line_clear ⇒ Object
- #pre_fix(now_pos) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize ⇒ Field
Returns a new instance of Field.
18 19 20 21 |
# File 'lib/rubytris/field.rb', line 18 def initialize() @field = init_field @point = 0 end |
Instance Attribute Details
#point ⇒ Object (readonly)
Returns the value of attribute point.
16 17 18 |
# File 'lib/rubytris/field.rb', line 16 def point @point end |
Instance Method Details
#are_block?(next_pos) ⇒ Boolean
45 46 47 48 49 50 51 52 53 |
# File 'lib/rubytris/field.rb', line 45 def are_block?(next_pos) result = false next_pos.each do |pos| if is_block?(pos[0], pos[1]) result = true end end result end |
#clear ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rubytris/field.rb', line 23 def clear() @field.each_with_index do |line, y| line.each_with_index do |l, x| @field[y][x] = 0 if l == FieldStatus::ACTIVE end end end |
#fix(now_pos) ⇒ Object
55 56 57 58 59 |
# File 'lib/rubytris/field.rb', line 55 def fix(now_pos) now_pos.each do |pos| @field[pos[1]][pos[0]] = FieldStatus::FIX end end |
#game_finish? ⇒ Boolean
41 42 43 |
# File 'lib/rubytris/field.rb', line 41 def game_finish?() @point >= 40 end |
#line_clear ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/rubytris/field.rb', line 31 def line_clear() @field.each_with_index do |line, y| if line == [FieldStatus::WALL, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::FIX, FieldStatus::WALL] @point += 1 @field.delete_at(y) @field.insert(0, [FieldStatus::WALL, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::NONE, FieldStatus::WALL]) end end end |
#pre_fix(now_pos) ⇒ Object
61 62 63 64 65 |
# File 'lib/rubytris/field.rb', line 61 def pre_fix(now_pos) now_pos.each do |pos| @field[pos[1]][pos[0]] = FieldStatus::ACTIVE end end |
#write ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rubytris/field.rb', line 67 def write() text = "\n\e[25D" @field.each do |line| line.each do |l| if l == FieldStatus::NONE text += NONE_CHAR elsif l == FieldStatus::ACTIVE || l == FieldStatus::FIX text += BLOCK_CHAR else text += WALL_CHAR end end text += "\n\e[25D" end puts text end |