private void SetPiece(GameObject prefab, Vector2Int coordinates) { GameObject pieceObject = Instantiate(prefab, _pieceHolder.transform); if (!GetTile(coordinates, out Tile tile)) { return; } //Sets the piece's transform position/Rotation pieceObject.transform.position = tile.transform.position + PIECE_ADJUSTMENT; if (GameController.Instance.PlayerColor == PieceColor.Red) { pieceObject.transform.localEulerAngles += new Vector3(0, 0, 180); } //Sets the piece's reference to the current board tile tile.CurrentPiece = pieceObject.GetComponent <GamePiece>(); //Sets the tile reference to the current piece //A little janky but it only needs to be set like this at the start of the game tile.CurrentPiece.CurrentTile = tile; GamePieces.Add(tile.CurrentPiece); }
public void MakeMove(Position origin, Position destiny) { Piece takenPiece = ChessMove(origin, destiny); if (IsInCheck(CurrentPlayer)) { UndoChessMove(origin, destiny, takenPiece); throw new BoardExceptions("You can not put your self in check"); } Piece movedPiece = Board.GetPiece(destiny); //Special move: Pawn Promotion if (movedPiece is Pawn) { if ((movedPiece.Color == Color.White && destiny.Line == 0) || (movedPiece.Color == Color.Black && destiny.Line == 7)) { Board.RemovePiece(destiny); GamePieces.Remove(movedPiece); Console.WriteLine("Type the kind of piece you want to promote your pawn to"); Console.Write("(QUEEN / ROOK / KNIGHT / BISHOP): "); string playerChoice = Console.ReadLine(); if (!ScreenController.CheckPlayerChoice(playerChoice)) { throw new BoardExceptions("Not valid option"); } playerChoice = playerChoice.ToLower(); switch (playerChoice) { case "queen": { Piece newPiece = new Queen(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "rook": { Piece newPiece = new Rook(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "knight": { Piece newPiece = new Knight(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } case "bishop": { Piece newPiece = new Bishop(movedPiece.Color, Board); Board.AddressPiece(newPiece, destiny); GamePieces.Add(newPiece); break; } } } } //EndGame Pawn Promotion if (IsInCheck(EnemyIs(CurrentPlayer))) { PlayerInCheck = true; } else { PlayerInCheck = false; } if (IsInCheckMate(EnemyIs(CurrentPlayer))) { EndGame = true; } else { Turn++; MudaJogador(); } //Special move: en passant if (movedPiece is Pawn && (destiny.Line == origin.Line + 2 || destiny.Line == origin.Line - 2)) { VulnerableToEnPassant = movedPiece; } else { VulnerableToEnPassant = null; } }
public void StartNewPiece(char column, int line, Piece piece) { Board.AddressPiece(piece, new ChessPosition(column, line).TranslateChessToZeroBased()); GamePieces.Add(piece); }
public void AddGamePiece(ConnectFourPiece piece) { GamePieces.Add(piece); }