public void ObjectClicked() { if (gameController.interfaceLocked) { return; } // Получаем фигуры, атакующие клетку Vector2Int cell = new Vector2Int((int)transform.position.x, (int)transform.position.y); Figure.FigureColor enemyColor = Figure.InvertColor(gameController.boardState.turnColor); List <Figure> attackingFigures = move.attackingFigures; King king = gameController.boardState.FindKingByColor(gameController.boardState.turnColor); ShakeAnimation shakeAnimation = gameController.FindTransformByPos(king.Pos).GetComponent <ShakeAnimation>(); Figure boundFigure = gameController.boardState.GetFigureAtCell(move.from); foreach (Figure figure in attackingFigures) { // Добавляем объект GameObject newRedLine = Instantiate(gameController.redLine); gameController.redLines.Add(newRedLine); // Если это ход короля, то анмация тряски не нужна Action callback; if (boundFigure.GetType() == typeof(King)) { callback = null; } else { callback = shakeAnimation.StartAnimation; } // Запускаем анимацию RedLineAnimation redLineAnimation = newRedLine.GetComponent <RedLineAnimation>(); redLineAnimation.StartAnimation( beginPos: new Vector3(figure.Pos.x, figure.Pos.y), endPos: new Vector3(move.kingPos.x, move.kingPos.y), finishedCallback: callback ); } }
/// <summary> /// Вызывется после завершения анимации перемещения фигуры. /// </summary> public void EndMove() { // Делаем ход на BoardState boardState.ExecuteMove(currentMove); // Перемещаем спрайт на слой ниже SpriteRenderer spriteRenderer = currentMovingPiece.GetChild(0).GetComponent <SpriteRenderer>(); spriteRenderer.sortingLayerName = "Pieces"; currentMovingPiece = null; // Обновляем список разрешенных ходов boardState.UpdateLegalMoves(); Debug.Log($"{boardState.turnColor} has {boardState.moveList.FindAll(move => move.attackingFigures.Count == 0).Count} moves"); // Шах King king = boardState.FindKingByColor(boardState.turnColor); List <Figure> attackingFigures = boardState.GetFiguresAttackingFigure(king); if (attackingFigures.Count > 0) { Debug.Log($"CHECK TO {boardState.turnColor} KING"); // Рисуем красные линии ShakeAnimation shakeAnimation = FindTransformByPos(king.Pos).GetComponent <ShakeAnimation>(); foreach (Figure figure in attackingFigures) { // Добавляем объект GameObject newRedLine = Instantiate(redLine); redLines.Add(newRedLine); // Запускаем анимацию RedLineAnimation redLineAnimation = newRedLine.GetComponent <RedLineAnimation>(); redLineAnimation.StartAnimation( beginPos: new Vector3(figure.Pos.x, figure.Pos.y), endPos: new Vector3(king.Pos.x, king.Pos.y), finishedCallback: shakeAnimation.StartAnimation ); } } BoardState.CheckState checkState = boardState.GetCheckState(); // Мат if (checkState == BoardState.CheckState.mate) { Debug.Log($"MATE TO {boardState.turnColor} KING"); gameEnded = true; endgameText.gameObject.SetActive(true); string text = boardState.turnColor == Figure.FigureColor.black ? "Белые выиграли" : "Черные выграли"; endgameText.transform.GetChild(0).GetComponent <Text>().text = text; return; } // Пат else if (checkState == BoardState.CheckState.stalemate) { Debug.Log($"STALEMATE TO {boardState.turnColor} KING"); gameEnded = true; endgameText.gameObject.SetActive(true); string text = "Ничья"; endgameText.transform.GetChild(0).GetComponent <Text>().text = text; return; } // Снимаем блокировку интерфейса interfaceLocked = false; }