コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Coordinate square = CoordinateHelper.Vector3ToCoordinate(Camera.main.ScreenToWorldPoint(Input.mousePosition));
            if (_isPieceClicked)
            {
                // Update when clicking new tile on board
                if (_validMoves.Contains(square))
                {
                    OnPieceMove?.Invoke(_pieceClicked.Position, square);
                    if (!Networked)
                    {
                        MoveTo(_pieceClicked.Position, square);
                    }
                }
                _validMoves.Clear();
                _isPieceClicked = false;
            }
            else if (_board[square] != null && _board[square].IsWhite == _isWhiteMove)
            {
                _isPieceClicked = true;
                _pieceClicked   = _board[square];
                FindValidMoves(_pieceClicked);

                // Print clicked piece's moves for debug purposes
                Debug.LogFormat("{0} move: {1}", _pieceClicked.Type.ToString(), string.Join(", ", _validMoves));
            }
        }
    }
コード例 #2
0
        /// <summary>
        /// Processes the left button press when there is another selection present.
        /// </summary>
        /// <param name="previousSelection">The previous selection.</param>
        /// <param name="selectedPosition">The selection position on board.</param>
        /// <param name="selectedPiece">The selected piece (null if the selected field is empty).</param>
        private void ProcessLeftButtonPressWithPreviousSelection(Selection previousSelection, Position selectedPosition, FriendlyPiece selectedPiece)
        {
            var previousSelectedPiece = FriendlyBoard.GetPiece(previousSelection.Position);

            if (previousSelectedPiece == null)
            {
                OnFieldSelection?.Invoke(this, new FieldSelectedEventArgs(selectedPosition, selectedPiece));
            }
            else if (selectedPiece == null || selectedPiece.Color != previousSelectedPiece.Color)
            {
                var from = previousSelection.Position;
                var to   = selectedPosition;

                OnPieceMove?.Invoke(this, new PieceMovedEventArgs(previousSelectedPiece, from, to));

                _selectionsManager.RemoveAllSelections();
            }
        }