// Generate hold piece by swapping active piece with hold piece public void GenerateHold() { // First time holding a block, hold piece does not yet exist if (holdPiece == null) { blockRotation = 1; RotateBlock(); holdPiece = activePiece; // Depending on block type, place hold piece in certain location if (holdPiece.GetBlockType() == 1 || holdPiece.GetBlockType() == 2) { holdPiece.SetX(55); holdPiece.SetY(105); } else { holdPiece.SetX(65); holdPiece.SetY(105); } // Generate new active piece to replace old GeneratePiece(); } // hold piece already exists else { blockRotation = 1; RotateBlock(); // Use place holder inbetween piece to swap pieces inbetweenPiece = holdPiece; holdPiece = activePiece; // Depending on block type, place hold piece in certain location if (holdPiece.GetBlockType() == 1 || holdPiece.GetBlockType() == 2) { holdPiece.SetX(55); holdPiece.SetY(105); } else { holdPiece.SetX(65); holdPiece.SetY(105); } // Turn old hold piece into active piece and place in specific location int dropColumnOffset = (numCols - 4) / 2 * blockWidth; activePiece = inbetweenPiece; activePiece.SetX(dropColumnOffset + xOffset); activePiece.SetY(50); } }
// Rotates block private void RotateBlock() { activePiece.myBlocks = null; activePiece = new Piece(activePiece.xOffset, activePiece.yOffset, 4, 4, 4 * blockWidth, 4 * blockHeight, activePiece.GetBlockType(), blockRotation); }