コード例 #1
0
    /// <summary>
    /// Loads previously saved state of the game and replaces current one
    /// Uses 'slotToLoad' variable to identify the file from which to load
    /// </summary>
    public void LoadLevel(string path, int levelNumber)
    {
        LevelData ld = SaveUnit.LoadLevel(levelNumber, path);

        if (path == "/Levels/Editor/")
        {
            GameDataManager.instance.generalData.selectedRocket = -1;
        }

        for (int x = 0; x < gridSize.x; x++)
        {
            for (int y = 0; y < gridSize.y; y++)
            {
                if (!lu.grid[x, y].IsEmpty())
                {
                    gu.DestroyGem(x, y, lu.grid[x, y].Gem.Color, false);
                }
            }
        }

        gridSize.x = ld.gridSizeX;
        gridSize.y = ld.gridSizeY;

        randomizeColors  = ld.randomizeColors;
        colorsAvailable  = ld.colorVector.Length;
        permittedBonuses = ld.availableBonuses;

        ComputeGemColors();
        ComputeGemSizes();

        winCondition   = ld.winCondition;
        timeAvailable  = ld.timeAvailable;
        movesAvailable = ld.movesAvailable;
        scoreToWin     = ld.scoreToWin;

        gu.UpdateDataAfterLoading();
        lu.UpdateDataAfterLoading();

        gu.RecreateGrid((int)gridSize.x, (int)gridSize.y);

        int[] gemColors = ld.gemColors;
        if (randomizeColors)
        {
            for (int i = 0; i < gemColors.Length; i++)
            {
                gemColors[i] = colorVector[IndexOf(ld.gemColors[i], ld.colorVector)];
            }
        }

        lu.grid = new Cell[(int)gridSize.x, (int)gridSize.y];
        for (int x = 0; x < (int)gridSize.x; x++)
        {
            for (int y = 0; y < (int)gridSize.y; y++)
            {
                if (ld.gemColors[x * (int)gridSize.y + y] != -1)
                {
                    lu.grid[x, y] = new Cell(new Vector2(x, y))
                    {
                        Gem = new Gem
                        {
                            Color = gemColors[x * (int)gridSize.y + y],
                            Bonus = ld.gemBonuses[x * (int)gridSize.y + y]
                        }
                    };
                    gu.SpawnGem((int)lu.grid[x, y].Position.x, (int)lu.grid[x, y].Position.y, lu.grid[x, y].Gem.Color, lu.grid[x, y].Gem.Bonus);
                }
                else
                {
                    lu.grid[x, y] = new Cell(new Vector2(x, y));
                    lu.grid[x, y].SetEmpty();
                }
            }
        }

        sequenceSize  = ld.sequenceSize;
        maximumEnergy = ld.maximumEnergy;

        int rocketId = GameDataManager.instance.generalData.selectedRocket;

        if (rocketId != -1)
        {
            maximumEnergy = GameDataManager.instance.rocketData[rocketId].maxEnergy;
        }
        lu.suboptimalMoves = maximumEnergy;
        gu.RecreateEnergyBar(maximumEnergy);

        spawnNewGems = ld.spawnNewGems;
        spawnEnergy  = ld.spawnEnergy;

        winCondition   = ld.winCondition;
        timeAvailable  = ld.timeAvailable;
        scoreToWin     = ld.scoreToWin;
        movesAvailable = ld.movesAvailable;

        lu.ComputeResourceColors();
    }