1 | TetrixShape = {
|
---|
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 |
|
---|
12 | TetrixCoordsTable = [
|
---|
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 |
|
---|
23 | function TetrixPiece()
|
---|
24 | {
|
---|
25 | this.shape = TetrixShape.NoShape;
|
---|
26 | }
|
---|
27 |
|
---|
28 | TetrixPiece.prototype.__defineGetter__(
|
---|
29 | "shape",
|
---|
30 | function() {
|
---|
31 | return this._shape;
|
---|
32 | }
|
---|
33 | );
|
---|
34 |
|
---|
35 | TetrixPiece.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 |
|
---|
45 | TetrixPiece.prototype.setRandomShape = function() {
|
---|
46 | this.shape = Math.floor(((Math.random() * 100000) % 7) + 1);
|
---|
47 | }
|
---|
48 |
|
---|
49 | TetrixPiece.prototype.getX = function(index) {
|
---|
50 | return this._coords[index][0];
|
---|
51 | }
|
---|
52 |
|
---|
53 | TetrixPiece.prototype.getY = function(index) {
|
---|
54 | return this._coords[index][1];
|
---|
55 | }
|
---|
56 |
|
---|
57 | TetrixPiece.prototype._setX = function(index, x) {
|
---|
58 | this._coords[index][0] = x;
|
---|
|
---|