Esempio n. 1
0
    void JumpCallback()
    {
        // Get foothold type
        FootholdType type = _types[_curRow, _curColumn];

        if (type.IsRedirect())
        {
            SetDirection(type.GetDirection().Reverse());
        }

        if (_solution.Count == 0)
        {
            ResetMap();

            if (_solutions.Count > 0)
            {
                // Next solution
                _solution = _solutions.Dequeue();

                // Start to jump
                Invoke("Jump", jumpDuration);
            }
        }
        else
        {
            // Continue to jump
            Jump();
        }
    }
Esempio n. 2
0
    IEnumerator Try()
    {
        int nextRow    = -1;
        int nextColumn = -1;

        for (int i = 0; i < 4; i++)
        {
            Direction dir = Directions[i];

            if (!dir.IsOpposite(_curDirection))
            {
                if (NextCell(dir, ref nextRow, ref nextColumn))
                {
                    // Push
                    _cells.Push(new Cell(_curRow, _curColumn));

                    // Save cell
                    int row    = _curRow;
                    int column = _curColumn;

                    // Save direction
                    Direction direction = _curDirection;

                    FootholdType type1 = _types[_curRow, _curColumn];
                    FootholdType type2 = _types[nextRow, nextColumn];

                    // Set direction
                    SetDirection(dir);

                    // Update current cell
                    if (type1 == FootholdType.Double)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, FootholdType.Normal);

                        // Increase counter
                        _count++;
                    }
                    else if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, FootholdType.None);

                        // Increase counter
                        _count++;
                    }

                    // Jump
                    var jump = MoveAction.MoveTo(GetPosition(nextRow, nextColumn), jumpDuration * 0.5f);

                    if (type2.IsRedirect())
                    {
                        Direction newDirection = type2.GetDirection();

                        _frog.gameObject.Play(SequenceAction.Create(jump, CallFuncAction.Create(() => {
                            SetDirection(newDirection);
                        })));
                    }
                    else
                    {
                        _frog.gameObject.Play(jump);
                    }

                    // Set current cell to next one
                    _curRow    = nextRow;
                    _curColumn = nextColumn;

                    yield return(new WaitForSeconds(jumpDuration));

                    // Check if finished
                    if (_count == _total - 1)
                    {
                        Show();
                    }
                    else
                    {
                        yield return(StartCoroutine(Try()));
                    }

                    // Restore cell
                    _curRow    = row;
                    _curColumn = column;

                    // Restore position
                    _frog.transform.position = GetPosition(_curRow, _curColumn);

                    // Restore type
                    if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        SetFoothold(_curRow, _curColumn, type1);

                        // Decrease counter
                        _count--;
                    }

                    // Restore direction
                    SetDirection(direction);

                    // Pop
                    _cells.Pop();

                    yield return(new WaitForSeconds(unjumpDuration));
                }
            }
        }
    }
Esempio n. 3
0
    void Try2()
    {
        int nextRow    = -1;
        int nextColumn = -1;

        for (int i = 0; i < 4; i++)
        {
            Direction dir = Directions[i];

            if (!dir.IsOpposite(_curDirection))
            {
                if (NextCell(dir, ref nextRow, ref nextColumn))
                {
                    // Push
                    _dirs.Push(dir);

                    // Save cell
                    int row    = _curRow;
                    int column = _curColumn;

                    // Save direction
                    Direction direction = _curDirection;

                    FootholdType type1 = _types[_curRow, _curColumn];
                    FootholdType type2 = _types[nextRow, nextColumn];

                    // Set direction
                    _curDirection = dir;

                    // Update current cell
                    if (type1 == FootholdType.Double)
                    {
                        // Set foothold
                        _types[_curRow, _curColumn] = FootholdType.Normal;

                        // Increase counter
                        _count++;
                    }
                    else if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        _types[_curRow, _curColumn] = FootholdType.None;

                        // Increase counter
                        _count++;
                    }

                    if (type2.IsRedirect())
                    {
                        _curDirection = type2.GetDirection();
                    }

                    // Set current cell to next one
                    _curRow    = nextRow;
                    _curColumn = nextColumn;

                    // Check if finished
                    if (_count == _total - 1)
                    {
                        Direction[] dirs  = _dirs.ToArray();
                        int         count = dirs.Length;

                        Queue <Direction> solution = new Queue <Direction>(count);

                        for (int idx = 0; idx < count; idx++)
                        {
                            solution.Enqueue(dirs[count - 1 - idx]);
                        }

                        // Add to solutions list
                        _solutions.Enqueue(solution);
                    }
                    else
                    {
                        Try2();
                    }

                    // Restore cell
                    _curRow    = row;
                    _curColumn = column;

                    // Restore type
                    if (type1 != FootholdType.None)
                    {
                        // Set foothold
                        _types[_curRow, _curColumn] = type1;

                        // Decrease counter
                        _count--;
                    }

                    // Restore direction
                    _curDirection = direction;

                    // Pop
                    _dirs.Pop();
                }
            }
        }
    }
Esempio n. 4
0
    void Try()
    {
        int nextRow    = -1;
        int nextColumn = -1;

        for (int i = 0; i < 4; i++)
        {
            Direction dir = Directions[i];

            if (!dir.IsOpposite(_curDirection))
            {
                if (NextCell(dir, ref nextRow, ref nextColumn))
                {
                    int       row       = _curRow;
                    int       column    = _curColumn;
                    Direction direction = _curDirection;

                    FootholdType type1 = _types[_curRow, _curColumn];
                    FootholdType type2 = _types[nextRow, nextColumn];

                    // Set direction
                    _curDirection = dir;

                    // Update current cell
                    if (type1 == FootholdType.Double)
                    {
                        _types[_curRow, _curColumn] = FootholdType.Normal;

                        // Increase counter
                        _count++;
                    }
                    else if (type1 != FootholdType.None)
                    {
                        _types[_curRow, _curColumn] = FootholdType.None;

                        // Increase counter
                        _count++;
                    }

                    if (type2.IsRedirect())
                    {
                        _curDirection = type2.GetDirection();
                    }

                    // Set current cell to next one
                    _curRow    = nextRow;
                    _curColumn = nextColumn;

                    // Check if finished
                    if (_count == _total - 1)
                    {
                        _counter++;
                    }
                    else
                    {
                        Try();
                    }

                    // Restore cell
                    _curRow    = row;
                    _curColumn = column;

                    // Restore type
                    if (type1 != FootholdType.None)
                    {
                        _types[row, column] = type1;

                        // Decrease counter
                        _count--;
                    }

                    // Restore direction
                    _curDirection = direction;
                }
            }
        }
    }