/// <summary> /// Кликаем на ячейку /// </summary> private void OnClickCell(CellFrame originUI) { if (!board.IsPlayerTurn || destination != null) { return; } Piece piece = board.GetPiece(originUI.Data); if (piece != null) { if (!(piece.IsPlayer ^ board.IsPlayerTurn)) { if (coroutine != null) { CoroutineExecutor.Instance.StopCoroutine(coroutine); } coroutine = CoroutineExecutor.Instance.StartCoroutine(MovePiece(piece, originUI.Data)); } } else if (activePiece != null) { destination = originUI.Data; } }
/// <summary> /// Показать форму и создать представление поля /// </summary> /// <param name="playSound"></param> public override void Show(bool playSound) { base.Show(playSound); char[] alpha = "abcdefghejklmnopqrstuvwxyz".ToCharArray(); RectTransform content = view.Board.GetComponent <RectTransform>(); for (int i = 0; i < board.Rows + 2; i++) { for (int j = 0; j < board.Cols + 2; j++) { bool isCoord = i == 0 || j == 0 || i == board.Rows + 1 || j == board.Cols + 1; CellFrame frame = AddFrame <CellFrame>(content); cellFrames.Add(frame); if (isCoord) { string value = ""; if (i == 0 || i == board.Rows + 1) { value = (j == 0 || j == board.Cols + 1) ? "" : alpha[j - 1].ToString(); } if (j == 0 || j == board.Cols + 1) { value = (i == 0 || i == board.Rows + 1) ? "" : (board.Rows - i + 1).ToString(); } frame.DrawCoord(isCoord, value); } else { frame.OnClicked += OnClickCell; frame.Data = board[i - 1, j - 1]; } } } CreateTeam(0, 0, false); CreateTeam(5, 5, true); UpdateTurn(); board.OnWin += OnWin; }