示例#1
0
    /// <summary>
    /// Retrocede el camino ya realizado por el jugador.
    /// </summary>
    /// <param name="x">Posicion X del tablero a la que se quiere retroceder.</param>
    /// <param name="y">Posicion Y del tablero a la que se quiere retroceder.</param>
    private void GoBack(int x, int y)
    {
        while (_pathStack.Count != 0 && (_pathStack.Peek()._x != x || _pathStack.Peek()._y != y))
        {
            MatrixPos pos = _pathStack.Pop();
            _pressedTilesMatrix[pos._y, pos._x] = false;
            _tilesMatrix[pos._y, pos._x].SetPressed(false);

            if (_pathStack.Peek()._x != pos._x)
            {
                _hintHorizontalMatrix[_pathStack.Peek()._y, Mathf.Min(_pathStack.Peek()._x, pos._x)].gameObject.SetActive(false);
            }
            else if (_pathStack.Peek()._y != pos._y)
            {
                _hintVerticalMatrix[Mathf.Min(_pathStack.Peek()._y, pos._y), _pathStack.Peek()._x].gameObject.SetActive(false);
            }
        }
    }
示例#2
0
    /// <summary>
    /// Crea Tiles y los asigna a la matriz de Tiles, ademas modifica la matriz de bool
    /// en la que todos son false excepto el Tile pulsado al inicio y los Tiles que no existen.
    /// Por ultimo, modifica la posicion del tablero para centrarlo en el espacio.
    /// </summary>
    /// <param name="layout">Tablero</param>
    private void GenerateGrid()
    {
        for (int y = 0; y < _boardHeight; y++)
        {
            for (int x = 0; x < _boardWidth; x++)
            {
                _pressedTilesMatrix[y, x] = true;
                if (_levelData._layout[y][x] != '0')
                {
                    GameObject tile = (GameObject)Instantiate(_tileGameObject, transform);

                    tile.transform.parent = _tilesGroup;
                    float posX = x;
                    float posY = -y;

                    posX = (float)Math.Round(posX, 0);
                    posY = (float)Math.Round(posY, 0);

                    tile.transform.localPosition = new Vector2(x, -y);

                    if (_levelData._layout[y][x] == '1')
                    {
                        _pressedTilesMatrix[y, x] = false;
                    }
                    else if (_levelData._layout[y][x] == '2')
                    {
                        _firsTile = new MatrixPos(x, y);
                        _pathStack.Push(new MatrixPos(x, y));
                    }

                    _tilesMatrix[y, x] = tile.GetComponent <Tile>();
                    _tilesMatrix[y, x].SetPressed(_pressedTilesMatrix[y, x]);

                    CreateHint(x, y, posX, posY);
                }
            }
        }

        ScaleGridAndSetPosition();
    }