public void placeCell(GameObject cell, Vector2Int pos) { cell.transform.position = BoardHandler.toWorldPos(pos); Vector3 wpos = cell.transform.position; wpos.y -= 1.15f; wpos.z -= 1.85f; wpos.x -= 0.45f; cell.transform.position = wpos; }
public void undoMove() { if (moves.Count != 0) { List <Move> last = moves[moves.Count - 1]; foreach (Move move in last) { if (move.Beaten != null) { move.Beaten.SetActive(true); } Figure fig = move.Moved.GetComponent <Figure>(); fig.WasMoved = !move.IsFirstTimeMoved; board[move.EndPoint.x, move.EndPoint.y] = move.Beaten; board[move.OldPoint.x, move.OldPoint.y] = move.Moved; move.Moved.transform.position = BoardHandler.toWorldPos(move.OldPoint); } moves.Remove(last); last.Clear(); changeTurn(); } }
public void moveFigure(Vector2Int oldPos, Vector2Int newPos) { if (newPos.x >= 0 && newPos.x < 8 && newPos.y >= 0 && newPos.y < 8 && board[oldPos.x, oldPos.y] != null) { List <Move> doubleMove = new List <Move>(); Figure fig = board[oldPos.x, oldPos.y].GetComponent <Figure>(); if (board[newPos.x, newPos.y] != null && fig.Type == TypeFigure.King) { Figure fig2 = board[newPos.x, newPos.y].GetComponent <Figure>(); if (fig2.Type == TypeFigure.Rook && fig2.team == fig.team) { if (newPos.x == 7) { doubleMove = new List <Move>(); doubleMove.Add(new Move(board[oldPos.x, oldPos.y], board[6, oldPos.y], oldPos, new Vector2Int(6, oldPos.y), true)); doubleMove.Add(new Move(board[newPos.x, newPos.y], board[5, oldPos.y], newPos, new Vector2Int(5, oldPos.y), true)); moves.Add(doubleMove); fig.WasMoved = true; fig2.WasMoved = true; board[6, oldPos.y] = board[oldPos.x, oldPos.y]; board[oldPos.x, oldPos.y] = null; board[6, oldPos.y].transform.position = BoardHandler.toWorldPos(new Vector2Int(6, oldPos.y)); board[5, oldPos.y] = board[newPos.x, newPos.y]; board[newPos.x, newPos.y] = null; board[5, oldPos.y].transform.position = BoardHandler.toWorldPos(new Vector2Int(5, oldPos.y)); } else { doubleMove = new List <Move>(); doubleMove.Add(new Move(board[oldPos.x, oldPos.y], board[2, oldPos.y], oldPos, new Vector2Int(2, oldPos.y), true)); doubleMove.Add(new Move(board[newPos.x, newPos.y], board[3, oldPos.y], newPos, new Vector2Int(3, oldPos.y), true)); moves.Add(doubleMove); fig.WasMoved = true; fig2.WasMoved = true; board[2, oldPos.y] = board[oldPos.x, oldPos.y]; board[oldPos.x, oldPos.y] = null; board[2, oldPos.y].transform.position = BoardHandler.toWorldPos(new Vector2Int(2, oldPos.y)); board[3, oldPos.y] = board[newPos.x, newPos.y]; board[newPos.x, newPos.y] = null; board[3, oldPos.y].transform.position = BoardHandler.toWorldPos(new Vector2Int(3, oldPos.y)); } } else { Move newMove = new Move(board[oldPos.x, oldPos.y], board[newPos.x, newPos.y], oldPos, newPos, !fig.WasMoved); doubleMove.Add(newMove); moves.Add(doubleMove); fig.WasMoved = true; if (board[newPos.x, newPos.y] != null) { board[newPos.x, newPos.y].SetActive(false); } board[newPos.x, newPos.y] = board[oldPos.x, oldPos.y]; board[oldPos.x, oldPos.y] = null; board[newPos.x, newPos.y].transform.position = BoardHandler.toWorldPos(newPos); } } else { Move newMove = new Move(board[oldPos.x, oldPos.y], board[newPos.x, newPos.y], oldPos, newPos, !fig.WasMoved); doubleMove.Add(newMove); moves.Add(doubleMove); fig.WasMoved = true; if (board[newPos.x, newPos.y] != null) { board[newPos.x, newPos.y].SetActive(false); } board[newPos.x, newPos.y] = board[oldPos.x, oldPos.y]; board[oldPos.x, oldPos.y] = null; board[newPos.x, newPos.y].transform.position = BoardHandler.toWorldPos(newPos); } changeTurn(); } }