// Update is called once per frame protected virtual void Update() { //handles moving a piece if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && movePieceFrom != Vector3.down) { //here must disallow moving pieces to anywhere other than a legal square if (legalMovesForAPiece != null) { movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition; DrawPiece.ClearHighlight(); if (board.IsOccupied(movePieceTo)) { //if the color of the piece matches the current turn if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState()) { movePieceTo = Vector3.down; movePieceFrom = Vector3.down; drawBoard.ClearHighlights(); return; } } else { drawBoard.ClearHighlights(); } if (!legalMovesForAPiece.Contains(movePieceTo)) { movePieceTo = Vector3.down; currentlySelectedPiece = null; } } } //handles clicking a piece else if (DrawPiece.IsClicked) { SelectPiece(); } // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose. // In the real game we would also have to check if it is a valid move. if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down) { MovePieceModel(movePieceFrom, movePieceTo); } }
// Update is called once per frame private void Update() { // Check to see if a position is clicked after already selecting a piece. if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && movePieceFrom != Vector3.down) { movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition; drawBoard.HighLightGrid(movePieceTo); } else if (DrawPiece.IsClicked && movePieceFrom == Vector3.down) { movePieceFrom = DrawPiece.PiecePosition; drawBoard.HighLightGrid(movePieceFrom); } // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose. // In the real game we would also have to check if it is a valid move. if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down) { mm1.MovePiece(movePieceFrom, movePieceTo); movePieceTo = movePieceFrom = Vector3.down; drawBoard.ClearHighlights(); } }
private void RpcUpdate() { //handles moving a piece if ((DrawBoard.IsClicked || DrawPiece.IsClicked) && (movePieceFrom != Vector3.down || localFrom != Vector3.down)) { currentlySelectedPiece = board.GetPieceAt(localFrom); //here must disallow moving pieces to anywhere other than a legal square if (legalMovesForAPiece != null) { foreach (Vector3 move in legalMovesForAPiece) { Debug.Log(move); } movePieceTo = DrawBoard.IsClicked ? DrawBoard.SquarePosition : DrawPiece.PiecePosition; localTo = movePieceTo; DrawPiece.ClearHighlight(); if (board.IsOccupied(localTo)) { //if the color of the piece matches the current turn if (board.GetPieceAt(movePieceTo).GetTeam() == gameState.getState()) { movePieceTo = movePieceFrom = localTo = localFrom = Vector3.down; drawBoard.ClearHighlights(); return; } } else { drawBoard.ClearHighlights(); } if (!legalMovesForAPiece.Contains(localTo)) { currentlySelectedPiece = null; movePieceTo = localTo = Vector3.down; } } } //handles clicking a piece else if (DrawPiece.IsClicked) { if (isLocalPlayer) { if (isServer) { RpcSelectPiece(); } else { CmdSelectPiece(); } } } // If the user has clicked on a space to move and a piece to move, move the piece and reset the vectors to numbers the user cannot choose. // In the real game we would also have to check if it is a valid move. if (movePieceFrom != Vector3.down && movePieceTo != Vector3.down && isServer) { RpcMovePieceModel(movePieceFrom, movePieceTo); } else if (localFrom != Vector3.down && localTo != Vector3.down && !isServer) { CmdMovePieceModel(localFrom, localTo); } }