Пример #1
0
 private void VisualizeMoves()
 {
     for (int i = 1; i < _blackMovesStrings.Length; i++)
     {
         if ((i - 1) / 2 != Settings.JYSettings.BlackMovesIndex)
         {
             continue;
         }
         if (i % 2 == 1)
         {
             var move = BenzeneUtil.TryToParseMove(_blackMovesStrings[i]).Location;
             _visualizedMoves.Add(move);
             _visualization.SelectMove(move, TileState.Black);
         }
         else
         {
             var whiteMovesStrings = _blackMovesStrings[i].Trim().Split(',');
             for (int j = 0; j < whiteMovesStrings.Length; j++)
             {
                 var move = BenzeneUtil.TryToParseMove(whiteMovesStrings[j]).Location;
                 _visualizedMoves.Add(move);
                 _visualization.SelectMove(move, TileState.White);
             }
             break;
         }
     }
 }
Пример #2
0
    public virtual void VisualizeMove()
    {
        //Only visualize if allowed to move.
        if (!_isSelectingMove)
        {
            return;
        }


        if (_visualizedMove != null)
        {
            if (InputManager.GetMouseButtonDown(0))
            {
                _moveChoiceCallback(_visualizedMove);
                _isSelectingMove = false;
                _visualization.ClearSelectedMove(_visualizedMove.Location);
                _visualizedMove = null;
            }
        }

        var        ray = _camera.ScreenPointToRay(InputManager.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100f))
        {
            if (hit.transform == null || hit.transform.GetComponent <Tile>() == null)
            {
                return;
            }
            var hitLocation = hit.transform.GetComponent <Tile>().Location;


            if (hitLocation == _visualizedLocation)
            {
                return;
            }

            if (_visualizedMove != null)
            {
                _visualization.ClearSelectedMove(_visualizedMove.Location);
            }
            _visualizedLocation = hitLocation;

            var candidateMove = new Move(_visualizedLocation);

            _visualizedMove = candidateMove;

            foreach (var move in _validMoves)
            {
                if (move.Equals(candidateMove))
                {
                    _visualization.SelectMove(candidateMove.Location, _board.IsLeftPlayerMove ? TileState.Black :TileState.White);
                    return;
                }
            }

            _visualizedMove = null;
        }
        else
        {
            //No longer mousing over a valid move
            if (_visualizedMove != null)
            {
                _visualization.ClearSelectedMove(_visualizedMove.Location);
                _visualizedMove = null;
            }
        }
    }