Class: Rubytris::Current
- Inherits:
-
Object
- Object
- Rubytris::Current
- Defined in:
- lib/rubytris/current.rb
Constant Summary collapse
- BLOCKS =
[ [ [0, 1, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], ], [ [0, 1, 1, 0], [1, 1, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], ], [ [1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], ], [ [1, 1, 1, 1], [0, 0, 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, 0, 0, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], ], [ [0, 0, 1, 0], [1, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], ], ]
Instance Method Summary collapse
-
#fall ⇒ Object
move fall.
-
#initialize(x, y, current = new_block) ⇒ Current
constructor
A new instance of Current.
-
#left ⇒ Object
move left.
- #move_position ⇒ Object
-
#new_block ⇒ Object
create new block.
-
#right ⇒ Object
move right.
-
#rotation ⇒ Object
move rotation.
Constructor Details
#initialize(x, y, current = new_block) ⇒ Current
Returns a new instance of Current.
40 41 42 43 44 |
# File 'lib/rubytris/current.rb', line 40 def initialize(x, y, current = new_block) @x = x @y = y @current = current end |
Instance Method Details
#fall ⇒ Object
move fall
71 72 73 |
# File 'lib/rubytris/current.rb', line 71 def fall() Current.new(@x, @y + 1, @current) end |
#left ⇒ Object
move left
66 67 68 |
# File 'lib/rubytris/current.rb', line 66 def left() Current.new(@x - 1, @y, @current) end |
#move_position ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rubytris/current.rb', line 46 def move_position() count = 0 block_position = Array.new(4) @current.each_with_index do |block, y| block.each_with_index do |b, x| if b == 1 block_position[count] = [ @x + x, @y + y ] count += 1 end end end block_position end |
#new_block ⇒ Object
create new block
90 91 92 93 |
# File 'lib/rubytris/current.rb', line 90 def new_block() rnd = rand(BLOCKS.length) BLOCKS[rnd] end |
#right ⇒ Object
move right
61 62 63 |
# File 'lib/rubytris/current.rb', line 61 def right() Current.new(@x + 1, @y, @current) end |
#rotation ⇒ Object
move rotation
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubytris/current.rb', line 76 def rotation() tmp = Array.new(4){ Array.new(4, 0)} @current.each_with_index do |line, y| line.each_with_index do |l, x| tmp[x][y] = l end end tmp.each_with_index do |line, i| tmp[i] = line.reverse end Current.new(@x, @y, tmp) end |