protected virtual void Move() { // if enemy piece -> back to currentCell //if (mTargetCell.mCurrentPiece != null) // { // transform.position = mCurrentCell.transform.position; // mTargetCell = null; // return; // } // Color color = mColor; //check neighbors for Enemys & Allys Cell[] attackedCells = checkNeighbor(); if (attackedCells != null) { for (int i = 0; i <= attackedCells.Length - 1; i++) { if (attackedCells[i] != null) { attackedCells[i].RemovePiece(); mPieceManager.moveAgain = true; } } } if (attackedCells != null) { if (color == Color.white) { color = Color.black; } else { color = Color.white; } } Vector2 oldPosition = mCurrentCell.getBoardPosition(); mPieceManager.getBoard().simpleAllCells[(int)oldPosition.x, (int)oldPosition.y] = "empty"; mCurrentCell.mCurrentPiece = null; Vector2 targetPosition = mTargetCell.getBoardPosition(); mPieceManager.getBoard().simpleAllCells[(int)oldPosition.x, (int)oldPosition.y] = this.name; // Moving on Boarddraught mCurrentCell = mTargetCell; mCurrentCell.mCurrentPiece = this; transform.position = mCurrentCell.transform.position; mTargetCell = null; mPieceManager.SwitchSides(color); }
public virtual void Place(CellDraughtV newCell) { //Cell gameObject.SetActive(true); mCurrentCell = newCell; mOriginalCell = newCell; mCurrentCell.mCurrentPiece = this; //Object transform.localPosition = mCurrentCell.transform.localPosition; //gameObject.SetActive(true); }
public virtual void MakeMove() { if (mTargetCell.mCurrentPiece != null) { // transform.position = mCurrentCell.transform.position; mTargetCell = null; return; } Color color = mColor; //check neighbors for Enemys & Allys Cell[] attackedCells = checkNeighbor(); if (attackedCells != null) { for (int i = 0; i <= attackedCells.Length - 1; i++) { if (attackedCells[i] != null) { attackedCells[i].RemovePiece(); mPieceManager.moveAgain = true; } } } if (attackedCells != null) { if (color == Color.white) { color = Color.black; } else { color = Color.white; } } mCurrentCell.mCurrentPiece = null; mCurrentCell = mTargetCell; mCurrentCell.mCurrentPiece = this; // transform.position = mCurrentCell.transform.position; mTargetCell = null; // mPieceManager.SwitchSides(color); }
public override void OnDrag(PointerEventData eventData) { base.OnDrag(eventData); //follow cursor Position transform.position += (Vector3)eventData.delta; foreach (CellDraughtV cell in mHighlightedCells) { if (RectTransformUtility.RectangleContainsScreenPoint(cell.mRectTransform, Input.mousePosition)) { // if mouse is in a valid cell -> get it mTargetCell = cell; break; } //if mouse is not in highlighted cell -> no valid move mTargetCell = null; } }
public virtual void PlaceByAI(CellDraughtV newCell) { Color color = mColor; if (this.name == null) { Debug.Log("this.name is null"); } if (mCurrentCell.name == null) { Debug.Log("mCurrentCell.name is null"); } if (newCell.name == null) { Debug.Log("newCell.name is null"); } Debug.Log(this.name + " bewegt sich von " + mCurrentCell.name + " nach " + newCell.name); mTargetCell = newCell; Move(); }
public virtual List <Move> getPossibleActions() { if (isDead()) { return(null); } else { CheckPathing(true); ClearMoves(); if (mHighlightedCells.Count > 0) { for (int i = 0; i < mHighlightedCells.ToArray().Length; i++) { mTargetCell = mHighlightedCells.ToArray()[i]; FindMoves(); } } return(moves); } }
public CellState ValidateCell(int targetX, int targetY, Piece checkingPiece) { //Bounds check if (targetX < 0 || targetX > (sizeX - 1)) { return(CellState.OutOfBounds); } if (targetY < 0 || targetY > (sizeY - 1)) { return(CellState.OutOfBounds); } // Get cell CellDraughtV targetCell = mAllCells[targetX, targetY]; // If the cell has a piece if (targetCell.mCurrentPiece != null) { //if friendly if (checkingPiece.mColor == targetCell.mCurrentPiece.mColor) { return(CellState.Friendly); } if (checkingPiece.mColor != targetCell.mCurrentPiece.mColor) { return(CellState.Enemy); } } //if (mAllCells[targetX, targetY].mCurrentPiece != null && mAllCells[targetX, targetY].mCurrentPiece.name == checkingPiece.name) // return CellState.Free; if (targetCell.mCurrentPiece == null) { return(CellState.Free); } return(CellState.None); }