/// <summary> /// Return if there is a king piece with given in a given direction by the given position. /// </summary> private bool HasKingWithTagByDirection(IntVector2 position, string tag, int offsetX, int offsetY) { //Debug.Log("position " + position); TileHandler currentTile = this.board.GetTile(position); IntVector2 currentPosition = currentTile.getPosition(); currentPosition.x += offsetX; if (CheckersMultiplayer.Instance.IsTableTen) { tempCounter = 12; } else { tempCounter = 10; } int counter = 0; while (this.board.WithinBounds(currentPosition.x, currentPosition.y)) { //Debug.Log("currentPosition: " + currentPosition.ToString() + " offset " + offsetX); if (counter > tempCounter) { Debug.Log("breaking when not should"); break; } else { counter++; } currentTile = this.board.GetTile(currentPosition); if (currentTile != null && currentTile.HasChild()) { if (currentTile.GetChild().CompareTag(tag) && currentTile.GetChild().GetComponent <KingPiece>() != null) { return(true); } else { break; } } currentPosition.x += offsetX; currentPosition.y += offsetY; } return(false); }
/// <summary> /// Return if there is a piece with a given tag in the given position. /// </summary> private bool HasPieceWithTag(IntVector2 position, string tag) { TileHandler tile = this.board.GetTile(position); if (tile != null && tile.HasChild() && tile.GetChild().CompareTag(tag)) { return(true); } return(false); }
public void SelectionHandler(TileHandler tile) { base.board.ResetPossibleMovements(canMoveTo); bool hasPiece = tile.HasChild(); // In case the player want to move a piece. if (base.currentPiece != null && !hasPiece) { // If that tile is in the 'canMoveTo', then move the current piece. Movement movement = GetMovementIfExists(canMoveTo, tile.getPosition()); if (movement != null) { base.board.MovePiece(movement); to = board.allTiles.IndexOf(tile.gameObject); // Debug.Log("Send to player " + board.allTiles.IndexOf(tile.gameObject)); } if (CheckersMultiplayer.Instance.IsMultiPlayer) { PhotonView pv = PhotonView.Get(CheckersMultiplayer.Instance.photonView); pv.RPC("OnPlayerMoveReceive", PhotonTargets.Others, to, from, "opponent"); // GameController.instance.NextTurn(); // CheckersMultiplayer.Instance.myTurn = 0; Debug.Log("TO Other" + to + "FROM Other" + from); } } // In case the player try to select a piece in a sucessive capture. else if (base.currentPiece != null && base.isSucessiveCapture && hasPiece) { // If the movement is a sucessive movement, then that piece is the only playable. if (base.currentPiece == tile.GetChild().GetComponent <Piece>()) { // Paints select piece's tile and the avaliable tiles to move. base.board.SelectPiece(base.currentPiece, canMoveTo); } else { base.board.SelectPiece(tile.GetChild().GetComponent <Piece>(), new ArrayList()); } } // In case the player select a new piece. else if (hasPiece) { // Get the piece of the tile selected.tile.GetChild ().GetComponent<Piece>(); base.currentPiece = tile.GetChild().GetComponent <Piece>(); if (base.currentPiece == null || !base.currentPiece.CompareTag("WhitePiece")) { return; } // Store the possible movements in a variable 'canMoveTo'. canMoveTo = base.currentPiece.GetBestSucessiveCapture(); if (canMoveTo.Count == 0 && !base.isCapturing) { canMoveTo = base.currentPiece.GetWalkMovements(); } from = board.allTiles.IndexOf(tile.gameObject); // Paints select piece's tile and the avaliable tiles to move. base.board.SelectPiece(base.currentPiece, canMoveTo); } }