public void HardDrop(Tetrimino piece, int moveVal) { if (CheckForMoveCollision(piece, moveVal)) { piece.MoveUpDown(moveVal - 1); } else { HardDrop(piece, moveVal + 1); } }
public void LegalMoveUpDown(Tetrimino piece, int moveVal) { // Check For Collisions if (!CheckForMoveCollision(piece, moveVal)) { _activePiece.MoveUpDown(moveVal); } else { DropActivePiece(); } }
public bool CheckForMoveCollision(Tetrimino piece, int moveVal) { // Copy Active Piece And Simulate Move Tetrimino copy = GeneratePiece(piece.GetBlockValue()); piece.MakeCopy(copy); copy.MoveUpDown(moveVal); // Check If Block Collides With Pile if (_tower.CheckPieceOverlap(copy)) { return(true); } // Check If Block Collides With Bottom if (!copy.IsInBounds(_tower)) { return(true); } return(false); }
public void TryRotate(Tetrimino piece, bool clockwise) { // Copy Active Piece And Simulate Rotation Tetrimino copy = GeneratePiece(piece.GetBlockValue()); piece.MakeCopy(copy); copy.Rotate(clockwise); // If Everything Looks Good, Rotate Active Piece if (copy.IsInBounds(_tower)) { piece.Rotate(clockwise); } // If It Doesn't, Try To Apply An Offset To The Rotation else { int rotationOffsetValue = -1; while (!copy.IsInBounds(_tower)) { rotationOffsetValue++; switch (rotationOffsetValue) { case 0: // 1 Space Left copy.MoveLeftRight(-1); break; case 1: // 2 Spaces Left copy.MoveLeftRight(-1); break; case 2: // 1 Space Right copy.MoveLeftRight(3); break; case 3: // 2 Spaces Right copy.MoveLeftRight(1); break; case 4: // 1 Space Down copy.MoveLeftRight(-2); copy.MoveUpDown(1); break; case 5: // 2 Spaces Down copy.MoveUpDown(1); break; default: return; } } // Rotate And Apply Offset piece.Rotate(clockwise); switch (rotationOffsetValue) { case 0: piece.MoveLeftRight(-1); break; case 1: piece.MoveLeftRight(-2); break; case 2: piece.MoveLeftRight(1); break; case 3: piece.MoveLeftRight(2); break; case 4: piece.MoveUpDown(1); break; case 5: piece.MoveUpDown(2); break; } } _rotateSound.Play(); }