public void CopyFrom(STPiece piece) { this.mShape = piece.mShape; this.mX = piece.mX; this.mY = piece.mY; this.mOrientation = piece.mOrientation; }
private int mOrientation; // 1,2,3,4 (0,1/4,2/4,3/4-"turn"); 0 == none private void InitializeAllFields( ) { this.mShape = STPieceShape.None; this.mX = 0; this.mY = 0; this.mOrientation = 0; }
public static bool GetCellOffsetXYOccupiedForShape ( STPieceShape shape, // O,I,S,Z,L,J,T; None int orientation, // 1,2,3,4; 0 == none int x, int y ) { if (STPieceShape.None == shape) { return(false); } // force orientation to range 1..totalOrientations int totalOrientations = 0; totalOrientations = STPiece.GetMaximumOrientationsOfShape(shape); if (0 == totalOrientations) { return(false); } orientation = 1 + ((((orientation - 1) % totalOrientations) + totalOrientations) % totalOrientations); // Loop through all cells and test against supplied cell. int totalCells = 0; totalCells = STPiece.GetTotalCellsForShape(shape); int cellIndex = 0; for (cellIndex = 1; cellIndex <= totalCells; cellIndex++) { int cellX = 0; int cellY = 0; STPiece.GetCellOffsetXYForShape(shape, orientation, cellIndex, ref cellX, ref cellY); if ((x == cellX) && (y == cellY)) { return(true); } } return(false); }
public static int GetMaximumOrientationsOfShape ( STPieceShape shape ) { if (STPieceShape.O == shape) { return(1); } if (STPieceShape.I == shape) { return(2); } if (STPieceShape.S == shape) { return(2); } if (STPieceShape.Z == shape) { return(2); } if (STPieceShape.L == shape) { return(4); } if (STPieceShape.J == shape) { return(4); } if (STPieceShape.T == shape) { return(4); } if (STPieceShape.None == shape) { return(0); } return(0); }
public static byte GetByteCodeValueOfShape ( STPieceShape shape ) { if (STPieceShape.O == shape) { return((byte)1); } if (STPieceShape.I == shape) { return((byte)2); } if (STPieceShape.S == shape) { return((byte)3); } if (STPieceShape.Z == shape) { return((byte)4); } if (STPieceShape.L == shape) { return((byte)5); } if (STPieceShape.J == shape) { return((byte)6); } if (STPieceShape.T == shape) { return((byte)7); } if (STPieceShape.None == shape) { return((byte)0); } return((byte)0); }
public static int GetTotalCellsForShape(STPieceShape shape) { return(4); }
public static void GetCellOffsetXYForShape ( STPieceShape shape, // O,I,S,Z,L,J,T; None int orientation, // 1,2,3,4; 0 == none int cellIndex, // 1,2,3,4; 0 == none ref int x, ref int y ) { x = 0; y = 0; // force cellIndex to range 1..4 cellIndex = 1 + (((cellIndex - 1) % 4 + 4) % 4); // force orientation to range 1..totalOrientations int totalOrientations = 0; totalOrientations = STPiece.GetMaximumOrientationsOfShape(shape); if (0 == totalOrientations) { return; } orientation = 1 + ((((orientation - 1) % totalOrientations) + totalOrientations) % totalOrientations); if (STPieceShape.None == shape) { return; } if (STPieceShape.O == shape) { // orientation 1,2,3,4 : (-1, -1), ( 0, -1), ( 0, 0), (-1, 0) if (1 == cellIndex) { x = -1; y = -1; } else if (2 == cellIndex) { x = 0; y = -1; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = -1; y = 0; } } if (STPieceShape.I == shape) { // orientation 1,3: (-2, 0), (-1, 0), ( 0, 0), ( 1, 0) // orientation 2,4: ( 0, -2), ( 0, -1), ( 0, 0), ( 0, 1) if ((1 == orientation) || (3 == orientation)) { if (1 == cellIndex) { x = -2; y = 0; } else if (2 == cellIndex) { x = -1; y = 0; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 1; y = 0; } } else { if (1 == cellIndex) { x = 0; y = -2; } else if (2 == cellIndex) { x = 0; y = -1; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } } if (STPieceShape.S == shape) { // orientation 1,3: (-1, -1), ( 0, -1), ( 0, 0), ( 1, 0) // orientation 2,4: ( 1, -1), ( 0, 0), ( 1, 0), ( 0, 1) if ((1 == orientation) || (3 == orientation)) { if (1 == cellIndex) { x = -1; y = -1; } else if (2 == cellIndex) { x = 0; y = -1; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 1; y = 0; } } else { if (1 == cellIndex) { x = 1; y = -1; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } } if (STPieceShape.Z == shape) { // orientation 1,3: ( 0, -1), ( 1, -1), (-1, 0), ( 0, 0) // orientation 2,4: ( 0, -1), ( 0, 0), ( 1, 0), ( 1, 1) if ((1 == orientation) || (3 == orientation)) { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 1; y = -1; } else if (3 == cellIndex) { x = -1; y = 0; } else if (4 == cellIndex) { x = 0; y = 0; } } else { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = 1; y = 1; } } } if (STPieceShape.L == shape) { // orientation 1: (-1, -1), (-1, 0), ( 0, 0), ( 1, 0) // orientation 2: ( 0, -1), ( 1, -1), ( 0, 0), ( 0, 1) // orientation 3: (-1, 0), ( 0, 0), ( 1, 0), ( 1, 1) // orientation 4: ( 0, -1), ( 0, 0), (-1, 1), ( 0, 1) if (1 == orientation) { if (1 == cellIndex) { x = -1; y = -1; } else if (2 == cellIndex) { x = -1; y = 0; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 1; y = 0; } } else if (2 == orientation) { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 1; y = -1; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } else if (3 == orientation) { if (1 == cellIndex) { x = -1; y = 0; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = 1; y = 1; } } else { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = -1; y = 1; } else if (4 == cellIndex) { x = 0; y = 1; } } } if (STPieceShape.J == shape) { // orientation 1: ( 1, -1), (-1, 0), ( 0, 0), ( 1, 0) // orientation 2: ( 0, -1), ( 0, 0), ( 0, 1), ( 1, 1) // orientation 3: (-1, 0), ( 0, 0), ( 1, 0), (-1, 1) // orientation 4: (-1, -1), ( 0, -1), ( 0, 0), ( 0, 1) if (1 == orientation) { if (1 == cellIndex) { x = 1; y = -1; } else if (2 == cellIndex) { x = -1; y = 0; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 1; y = 0; } } else if (2 == orientation) { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 0; y = 1; } else if (4 == cellIndex) { x = 1; y = 1; } } else if (3 == orientation) { if (1 == cellIndex) { x = -1; y = 0; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = -1; y = 1; } } else { if (1 == cellIndex) { x = -1; y = -1; } else if (2 == cellIndex) { x = 0; y = -1; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } } if (STPieceShape.T == shape) { // orientation 1: ( 0, -1), (-1, 0), ( 0, 0), ( 1, 0) // orientation 2: ( 0, -1), ( 0, 0), ( 1, 0), ( 0, 1) // orientation 3: (-1, 0), ( 0, 0), ( 1, 0), ( 0, 1) // orientation 4: ( 0, -1), (-1, 0), ( 0, 0), ( 0, 1) if (1 == orientation) { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = -1; y = 0; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 1; y = 0; } } else if (2 == orientation) { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } else if (3 == orientation) { if (1 == cellIndex) { x = -1; y = 0; } else if (2 == cellIndex) { x = 0; y = 0; } else if (3 == cellIndex) { x = 1; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } else { if (1 == cellIndex) { x = 0; y = -1; } else if (2 == cellIndex) { x = -1; y = 0; } else if (3 == cellIndex) { x = 0; y = 0; } else if (4 == cellIndex) { x = 0; y = 1; } } } }
public void SetShape(STPieceShape shape) { this.mShape = shape; }