/// <summary> /// Turn or flip the selected piece according to the input of the user /// </summary> private void RotateSelectedPiece() { // TODO: create options to configure shortcuts if (selectedPieceMap != null) { // Rotate if (Input.GetKeyDown(KeyCode.RightArrow)) { selectedPieceMap = MatriceManager.RotateMatrice(selectedPieceMap, true); } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { selectedPieceMap = MatriceManager.RotateMatrice(selectedPieceMap, false); } else if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.DownArrow)) { selectedPieceMap = MatriceManager.RotateMatrice(selectedPieceMap, true, 2); } // Reverse else if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D)) { selectedPieceMap = MatriceManager.ReverseMatrice(selectedPieceMap); selectedPieceMap = MatriceManager.RotateMatrice(selectedPieceMap, true, 2); } else if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S)) { selectedPieceMap = MatriceManager.ReverseMatrice(selectedPieceMap); } } }
private bool HasSpaceForAnyPieceVariant(Vector2Int coordinate, Player player) { bool spaceAvailable = false; foreach (Piece piece in player.Pieces) { List <int[, ]> mapsVariants = MatriceManager.GeneratesAllMatriceVariants(piece.PieceForm); foreach (int[,] pieceForm in mapsVariants) { int col = pieceForm.GetLength(0); int row = pieceForm.GetLength(1); spaceAvailable = VerifyPiecePlacement(pieceForm, coordinate, player); if (spaceAvailable) { return(spaceAvailable); } else { // To verify all possible placement of the piece we have to change the coordinate according to its size int maxSize = (col > row) ? col : row; for (int i = 1; i <= maxSize; i++) { if (VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x + i, coordinate.y), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x - i, coordinate.y), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x, coordinate.y + i), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x, coordinate.y - i), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x + i, coordinate.y + i), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x + i, coordinate.y - i), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x - i, coordinate.y + i), player) || VerifyPiecePlacement(pieceForm, new Vector2Int(coordinate.x - i, coordinate.y - i), player)) { spaceAvailable = true; return(spaceAvailable); } } } } } return(spaceAvailable); }