source: trunk/examples/script/qstetrix/tetrixpiece.js@ 374

Last change on this file since 374 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 3.0 KB
Line 
1TetrixShape = {
2 NoShape:0,
3 ZShape:1,
4 SShape:2,
5 LineShape:3,
6 TShape:4,
7 SquareShape:5,
8 LShape:6,
9 MirroredLShape:7
10}
11
12TetrixCoordsTable = [
13 [ [ 0, 0 ], [ 0, 0 ], [ 0, 0 ], [ 0, 0 ] ],
14 [ [ 0, -1 ], [ 0, 0 ], [ -1, 0 ], [ -1, 1 ] ],
15 [ [ 0, -1 ], [ 0, 0 ], [ 1, 0 ], [ 1, 1 ] ],
16 [ [ 0, -1 ], [ 0, 0 ], [ 0, 1 ], [ 0, 2 ] ],
17 [ [ -1, 0 ], [ 0, 0 ], [ 1, 0 ], [ 0, 1 ] ],
18 [ [ 0, 0 ], [ 1, 0 ], [ 0, 1 ], [ 1, 1 ] ],
19 [ [ -1, -1 ], [ 0, -1 ], [ 0, 0 ], [ 0, 1 ] ],
20 [ [ 1, -1 ], [ 0, -1 ], [ 0, 0 ], [ 0, 1 ] ]
21]
22
23function TetrixPiece()
24{
25 this.shape = TetrixShape.NoShape;
26}
27
28TetrixPiece.prototype.__defineGetter__(
29 "shape",
30 function() {
31 return this._shape;
32 }
33);
34
35TetrixPiece.prototype.__defineSetter__(
36 "shape",
37 function(shape) {
38 this._shape = shape;
39 this._coords = new Array(4);
40 for (var i = 0; i < 4; ++i)
41 this._coords[i] = TetrixCoordsTable[shape][i].slice();
42 }
43);
44
45TetrixPiece.prototype.setRandomShape = function() {
46 this.shape = Math.floor(((Math.random() * 100000) % 7) + 1);
47}
48
49TetrixPiece.prototype.getX = function(index) {
50 return this._coords[index][0];
51}
52
53TetrixPiece.prototype.getY = function(index) {
54 return this._coords[index][1];
55}
56
57TetrixPiece.prototype._setX = function(index, x) {
58 this._coords[index][0] = x;