// Flips piece horizontally. private Piece FlippedPiece() { StringBuilder newPieceMask = new StringBuilder(); //string newPieceMask = ""; // Top side newPieceMask.Append(PieceMaskString.Substring(0, 5).ToCharArray().Reverse().ToArray()); // Right center newPieceMask.Append(PieceMaskString.Substring(13, 3).ToCharArray().Reverse().ToArray()); // Bottom side newPieceMask.Append(PieceMaskString.Substring(8, 5).ToCharArray().Reverse().ToArray()); // Left center newPieceMask.Append(PieceMaskString.Substring(5, 3).ToCharArray().Reverse().ToArray()); //TODO: IS it incorrect to use the opposite of this.IsFlipped in the call below? Does that check out if things are rotated? return(new Piece(newPieceMask.ToString(), Rotations, !IsFlipped, PieceID)); }
// Rotates piece 90 degrees clockwise * any number between 0 and 3. private Piece RotatePiece(int rotateTimes90Degrees) { // Ensure rotateTimes90Degrees is between 0 and 3 before proceeding. if (rotateTimes90Degrees < 0) { return(new Piece(this)); } rotateTimes90Degrees %= 4; // Kick out a duplicate piece of no rotation specified. if (rotateTimes90Degrees == 0) { return(new Piece(this)); } int pegShift = rotateTimes90Degrees * 4; string newMaskString = PieceMaskString.Substring(16 - pegShift, pegShift); newMaskString += PieceMaskString.Substring(0, 16 - pegShift); return(new Piece(newMaskString, rotateTimes90Degrees, IsFlipped, PieceID)); }