class TetrixPiece

Constants

LShape
LineShape
MirroredLShape
NoShape
SShape
SquareShape
TShape
ZShape

Public Class Methods

new() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 37
def initialize()
    @coordsTable = [
        [ [ 0, 0 ],   [ 0, 0 ],   [ 0, 0 ],   [ 0, 0 ] ],
        [ [ 0, -1 ],  [ 0, 0 ],   [ -1, 0 ],  [ -1, 1 ] ],
        [ [ 0, -1 ],  [ 0, 0 ],   [ 1, 0 ],   [ 1, 1 ] ],
        [ [ 0, -1 ],  [ 0, 0 ],   [ 0, 1 ],   [ 0, 2 ] ],
        [ [ -1, 0 ],  [ 0, 0 ],   [ 1, 0 ],   [ 0, 1 ] ],
        [ [ 0, 0 ],   [ 1, 0 ],   [ 0, 1 ],   [ 1, 1 ] ],
        [ [ -1, -1 ], [ 0, -1 ],  [ 0, 0 ],   [ 0, 1 ] ],
        [ [ 1, -1 ],  [ 0, -1 ],  [ 0, 0 ],   [ 0, 1 ] ] ]
    @coords = [[0, 0], [0, 0], [0, 0], [0, 0]]

    self.shape = NoShape
end

Public Instance Methods

maxX() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 84
def maxX()
    max = @coords[0][0]
    (1...4).each do |i|
        max = [max, @coords[i][0]].max
    end
    return max
end
maxY() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 100
def maxY()
    max = @coords[0][1]
    (1...4).each do |i|
        max = [max, @coords[i][1]].max
    end
    return max
end
minX() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 76
def minX()
    min = @coords[0][0]
    (1...4).each do |i|
        min = [min, @coords[i][0]].min
    end
    return min
end
minY() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 92
def minY()
    min = @coords[0][1]
    (1...4).each do |i|
        min = [min, @coords[i][1]].min
    end
    return min
end
pieceShape=(shape) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 72
def pieceShape=(shape)
    @pieceShape = shape
end
rotatedLeft() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 108
def rotatedLeft()
    if @pieceShape == SquareShape
        return self
    end

    result = TetrixPiece.new
    result.pieceShape = @pieceShape
    (0...4).each do |i|
        result.setX(i, y(i))
        result.setY(i, -x(i))
    end
    return result
end
rotatedRight() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 122
def rotatedRight()
    if @pieceShape == SquareShape
        return self
    end

    result = TetrixPiece.new
    result.pieceShape = @pieceShape
    (0...4).each do |i|
        result.setX(i, -y(i))
        result.setY(i, x(i))
    end
    return result
end
setRandomShape() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 59
def setRandomShape()
    self.shape = Kernel.rand(7) + 1
end
setX(index, x) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 56
def setX(index, x) @coords[index][0] = x end
setY(index, y) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 57
def setY(index, y) @coords[index][1] = y end
shape() click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 52
def shape() return @pieceShape end
shape=(shape) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 63
def shape=(shape)
    (0...4).each do |i|
        (0...2).each do |j|
            @coords[i][j] = @coordsTable[shape][i][j]
        end
    end
    @pieceShape = shape
end
x(index) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 53
def x(index) return @coords[index][0] end
y(index) click to toggle source
# File examples/widgets/tetrix/tetrixpiece.rb, line 54
def y(index) return @coords[index][1] end