/// <summary> /// Перемещать фигуру AI /// </summary> private IEnumerator MovePieceAI(Piece piece, Cell origin, List <Cell> path) { activePiece = piece; SmoothMoveStrategy moveStrategy = new SmoothMoveStrategy(piece, board, path); foreach (Vector2 pos in moveStrategy.Move()) { Vector2 realPos = ConvertToBoard(pos.x, pos.y); piece.SetPosition(realPos.x, realPos.y); if (moveStrategy.IsCompleted) { board.CompleteStep(strategy); UpdateTurn(); destination = null; activePiece = null; if (!board.IsPlayerTurn) { ai.MakeDecision(); } yield break; } yield return(moveStrategy.Delay()); } }
/// <summary> /// Перемещаем фигуру игрока /// </summary> private IEnumerator MovePiece(Piece piece, Cell origin) { activePiece = piece; foreach (var cell in cellFrames) { cell.Select(cell.Data == origin); } List <Cell> availableCells = strategy.GetAvailableCells(origin); if (availableCells.Count == 0) { foreach (var cell in cellFrames) { cell.Select(false); } destination = null; activePiece = null; yield break; } foreach (Cell cell in availableCells) { cell.Highlight(true); } // Ждем указания конечной точки while (destination == null) { yield return(null); } foreach (Cell cell in availableCells) { cell.Highlight(false); } foreach (var cell in cellFrames) { cell.Select(false); } if (!availableCells.Contains(destination)) { destination = null; activePiece = null; yield break; } else { List <Cell> path = strategy.ComputePath(origin, destination); SmoothMoveStrategy moveStrategy = new SmoothMoveStrategy(piece, board, path); foreach (Vector2 pos in moveStrategy.Move()) { Vector2 realPos = ConvertToBoard(pos.x, pos.y); piece.SetPosition(realPos.x, realPos.y); if (moveStrategy.IsCompleted) { bool isGameFinished = board.CompleteStep(strategy); UpdateTurn(); destination = null; activePiece = null; if (!isGameFinished && !board.IsPlayerTurn) { ai.MakeDecision(); } yield break; } yield return(moveStrategy.Delay()); } } }