/// <summary> /// Shifts the moving piece 1 square right, if possible /// </summary> private void MovePieceRight() { List <Square> squares = MovingPiece.OccupiedSquares; // Can't move out of bounds if (squares.Any(ms => ms.X == Width - 1)) { return; } // Can't move into an already occupied square else if (FixedPieces.Any(fp => fp.OccupiedSquares.Any(fs => squares.Any(ms => ms.X + 1 == fs.X && ms.Y == fs.Y)))) { return; } MovingPiece.MoveRight(); }
/// <summary> /// Rotates the moving piece /// </summary> private void RotatePiece() { List <Square> afterRotation = MovingPiece.SimulateRotation(); // Can't move out of bounds if (afterRotation.Any(ms => ms.X < 0) || afterRotation.Any(ms => ms.X >= Width) || afterRotation.Any(ms => ms.Y < 0) || afterRotation.Any(ms => ms.Y >= Height)) { return; } // Can't move into an already occupied square if (FixedPieces.Any(fp => fp.OccupiedSquares.Any(fs => afterRotation.Any(rs => rs.X == fs.X && rs.Y == fs.Y)))) { return; } MovingPiece.Rotate(); }