Ejemplo n.º 1
0
    /// <summary>
    /// Player's selection of units.
    /// In the case of the selection of the second unit, check the possibility of their swapping. If it leads to the match, swap selected units.
    /// </summary>
    /// <param name="ci"></param>
    public void UnitClickHandler(UnitInfo ci)
    {
        if (ci == null || !(_state is StateWait))
        {
            return;
        }

        if (_selectedUnit == null)
        {
            _selectedUnit = ci;
            _selectedUnit.ShowShadow();
        }
        else
        {
            if (_selectedUnit != ci && _game.TrySwapUnits(_selectedUnit.MPos, ci.MPos))
            {
                SwapTwoUnits(_selectedUnit, ci);
            }

            _selectedUnit.HideShadow();
            _selectedUnit = null;
        }
    }