Class: TetrixPiece

Inherits:
Object show all
Defined in:
ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb

Overview

** ** Copyright © 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at [email protected]. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **

** Translated to QtRuby by Richard Dale

Constant Summary collapse

NoShape =
0
ZShape =
1
SShape =
2
LineShape =
3
TShape =
4
SquareShape =
5
LShape =
6
MirroredLShape =
7

Instance Method Summary collapse

Constructor Details

#initializeTetrixPiece

Returns a new instance of TetrixPiece.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'ext/ruby/qtruby/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

Instance Method Details

#maxXObject



84
85
86
87
88
89
90
# File 'ext/ruby/qtruby/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

#maxYObject



100
101
102
103
104
105
106
# File 'ext/ruby/qtruby/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

#minXObject



76
77
78
79
80
81
82
# File 'ext/ruby/qtruby/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

#minYObject



92
93
94
95
96
97
98
# File 'ext/ruby/qtruby/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) ⇒ Object



72
73
74
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 72

def pieceShape=(shape)
    @pieceShape = shape
end

#rotatedLeftObject



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'ext/ruby/qtruby/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

#rotatedRightObject



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'ext/ruby/qtruby/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

#setRandomShapeObject



59
60
61
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 59

def setRandomShape()
    self.shape = Kernel.rand(7) + 1
end

#setX(index, x) ⇒ Object



56
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 56

def setX(index, x) @coords[index][0] = x end

#setY(index, y) ⇒ Object



57
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 57

def setY(index, y) @coords[index][1] = y end

#shapeObject



52
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 52

def shape() return @pieceShape end

#shape=(shape) ⇒ Object



63
64
65
66
67
68
69
70
# File 'ext/ruby/qtruby/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) ⇒ Object



53
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 53

def x(index) return @coords[index][0] end

#y(index) ⇒ Object



54
# File 'ext/ruby/qtruby/examples/widgets/tetrix/tetrixpiece.rb', line 54

def y(index) return @coords[index][1] end