Example #1
0
    /// <summary>
    /// Resets the original position of the currently held disc if the pole cannot be put any disc
    /// </summary>
    public void ResetDiscPosition()
    {
        if (_currentlyHeldDisc)
        {
            Vector3   originalDiscPosition = Vector3.zero;
            HanoiDisc originalTopStack     = _currentDiscOriginalPole.PeekTopDisc;

            if (originalTopStack) // If stack is not empty, get the top of the stack to land on
            {
                originalDiscPosition = originalTopStack.transform.position;
            }
            else // If stack is empty, get the base of the board
            {
                originalDiscPosition = new Vector3(_currentDiscOriginalPole.transform.position.x, -_currentlyHeldDisc.YScale, _currentDiscOriginalPole.transform.position.z);
            }

            // Calculate Landing Position based on scale
            originalDiscPosition += Vector3.up * _currentlyHeldDisc.YScale * 2f;

            // Set position based on calculated position
            _currentlyHeldDisc.transform.position = originalDiscPosition;
            _currentlyHeldDisc.transform.SetParent(_currentDiscOriginalPole.transform);

            // Add it to the stack
            _currentDiscOriginalPole.AddDiscToStack(_currentlyHeldDisc);

            // Reset the Currently Held disc
            _currentlyHeldDisc = null;
        }
    }
Example #2
0
    /// <summary>
    /// Puts down the currently held disc on top of the current stack
    /// </summary>
    /// <param name="p_currentPoleTopDisc">The top of the current stack on the pole</param>
    /// <param name="p_pole">The pole where this disc will be placed</param>
    private void PutDiscOnTopOfStack(HanoiDisc p_currentPoleTopDisc, HanoiPole p_pole)
    {
        if (_currentlyHeldDisc)
        {
            // Raise the on put down event
            _onDiscPutdown.Raise();

            Vector3 currentDiscPosition = Vector3.zero;
            if (p_currentPoleTopDisc) // If stack is not empty, get the top of the stack to land on
            {
                currentDiscPosition = p_currentPoleTopDisc.transform.position;
            }
            else // If stack is empty, get the base of the board
            {
                currentDiscPosition = new Vector3(p_pole.transform.position.x, -_currentlyHeldDisc.YScale, p_pole.transform.position.z);
            }

            // Calculate Landing Position based on scale
            currentDiscPosition += Vector3.up * _currentlyHeldDisc.YScale * 2f;

            // Set position based on calculated position
            _currentlyHeldDisc.transform.position = currentDiscPosition;
            _currentlyHeldDisc.transform.SetParent(p_pole.transform);

            // Update Movecount if you moved to another pole
            if (p_pole != _currentDiscOriginalPole)
            {
                _moveCount.SetVariableValue(_moveCount.Value + 1);
            }

            // Add it to the stack
            p_pole.AddDiscToStack(_currentlyHeldDisc);

            // Reset the Currently Held disc
            _currentlyHeldDisc = null;

            // Raise the disc stack event
            _onDiscStack.Raise();
        }
    }