Skip to content

Commit

Permalink
ブロックの回転方法を変更
Browse files Browse the repository at this point in the history
オブジェクトの生成を抑えてより高速に処理するため
  • Loading branch information
zariganitosh authored and zariganitosh committed Apr 29, 2014
1 parent 66864cd commit 9ec6600
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions tetris.rb
Expand Up @@ -98,23 +98,17 @@ def initialize(game, field)
@game = game
@field = field
@id = rand(0..6)
@blocks = @@minos[@id]
@blocks = [@@minos[@id], #回転なし
@@minos[@id].transpose.map(&:reverse), #右90度回転
@@minos[@id].reverse.map(&:reverse), #180度回転
@@minos[@id].transpose.reverse] #左90度回転(右270度回転)
@x, @y, @angle = (4 - @blocks.size) / 2 + 3, -1, 0
@state = :falling
@last_chance = 0
end

def blocks(angle = @angle)
case angle % 4
when 0
@blocks
when 1
@blocks.transpose.map(&:reverse) #右90度回転
when 2
@blocks.reverse.map(&:reverse) #180度回転
when 3
@blocks.transpose.reverse #左90度回転(右270度回転)
end
@blocks[angle % 4]
end

def rotate(dr)
Expand Down

0 comments on commit 9ec6600

Please sign in to comment.