/// <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); }
/// <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); }
public void HighlightPlayablePieces(ArrayList piecesList) { int table; if (CheckersMultiplayer.Instance.IsTableTen) { table = 10; } else { table = 8; } foreach (Piece piece in piecesList) { TileHandler tile = piece.transform.parent.GetComponent <TileHandler>(); IntVector2 pos = tile.getPosition(); int targetRow = pos.x + 1; int targetColumn = pos.y - 1; for (int i = 0; i < 2; i++) { if (targetColumn > 0 && targetColumn <= table && targetRow > 0 && targetRow <= table) { TileHandler possibleTile = board.GetTile(targetRow, targetColumn); if (!possibleTile.HasChild()) { //Green that tile tile.GetComponent <Image>().color = Color.green; board.HighLightedArray.Add(tile.gameObject); } if (possibleTile.HasChildEnemy()) { tile.GetComponent <Image>().color = Color.green; board.HighLightedArray.Add(tile.gameObject); } } targetColumn = pos.y + 1; } } }
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); } }
private bool IsFree(IntVector2 pos) { TileHandler tile = this.board.GetTile(pos); return(tile != null && !tile.HasChild()); }