public void SelectPiece(int pieceId) { //once the piece is selected //get the available moves if ((selectedPiece != null) && (selectedPiece == GetPiece(pieceId))) { selectedPiece.GetComponent <ChessPieceIAction>().SetSelected(false); selectedPiece = null; ChessRules.ClearGlow(); } else if ((selectedPiece != null) && (selectedPiece != GetPiece(pieceId))) { // do nothing } else if (selectedPiece == null) { selectedPiece = GetPiece(pieceId); if (selectedPiece != null) { selectedPiece.GetComponent <ChessPieceIAction>().SetSelected(true); } getAvailableMove(selectedPiece); } }
public void MovePiece(int tileId) { // Break if no tile is selected if (selectedPiece != null) { // Get tile based on given id GameObject tile = GetTile(tileId); GameObject parent = selectedPiece.GetComponent <PieceProperties>().parentTile; // Capture piece that is on the tile we're moving to GameObject pieceToRemove = null; foreach (GameObject p in pieces) { // Remove game object if (tile == p.GetComponent <PieceProperties>().parentTile) { pieceToRemove = p; } } if (pieceToRemove != null) { pieces.Remove(pieceToRemove); Destroy(pieceToRemove); } // TODO: May want to keep track of pieces removed // Move piece parent.GetComponent <TileProperties>().childPiece = null; selectedPiece.GetComponent <PieceProperties>().parentTile = tile; selectedPiece.GetComponent <PieceProperties>().row = tile.GetComponent <TileProperties>().row; selectedPiece.GetComponent <PieceProperties>().column = tile.GetComponent <TileProperties>().column; selectedPiece.GetComponent <ChessPieceIAction>().SetSelected(false); tile.GetComponent <TileProperties>().childPiece = selectedPiece; selectedPiece = null; ChessRules.ClearGlow(); tile.GetComponent <TileProperties>().isEmpty = false; parent.GetComponent <TileProperties>().isEmpty = true; } currentTurn = (currentTurn + 1) % 2; }
public void getAvailableMove(GameObject piece) { //highlights the available moves //ChessRules.availableMoves(piece); ChessRules.GetAvailableMoves(piece); }