Beispiel #1
0
    void ColorizeTiles(MatchStageInfo stage)
    {
        int colorCount = stage.Colors;

        List <Color> allColors = GameConstants.MatchGameColorList;

        IExtensions.Shuffle <Color>(allColors);

        List <Color> colors = new List <Color>();

        for (int i = 0; i < colorCount; i++)
        {
            colors.Add(allColors[i]);
        }

        int          curColor   = 0;
        List <Color> tileColors = new List <Color>();

        for (int i = 0; i < Tiles.Count / 2; i++)
        {
            tileColors.Add(colors[curColor]);
            tileColors.Add(colors[curColor]);

            curColor = (curColor + 1) % colorCount;
        }

        IExtensions.Shuffle <Color>(tileColors);

        for (int i = 0; i < Tiles.Count; i++)
        {
            Tiles[i].Setup(tileColors[i]);
        }
    }
Beispiel #2
0
    void SetupTileGrid(MatchStageInfo stage)
    {
        int gridWidth  = stage.Width;
        int gridHeight = stage.Height;

        for (int i = 0; i < gridWidth; i++)
        {
            for (int j = 0; j < gridHeight; j++)
            {
                GameObject    tile  = Instantiate(MatchTilePrefab);
                RectTransform trans = tile.GetComponent <RectTransform>();

                trans.parent           = this.transform;
                trans.anchoredPosition = new Vector2((i - gridWidth / 2) * trans.sizeDelta.x, (j - gridHeight / 2) * trans.sizeDelta.y);

                Tiles.Add(tile.GetComponent <MatchTile>());
            }
        }
    }
Beispiel #3
0
    public void GenerateNextLevel()
    {
        CleanGrid();

        _currentStage++;
        Debug.LogError("Generating stage " + _currentStage);

        if (_currentStage == GameConstants.MatchGameStageInfo.Count)
        {
            HasCompletedGame = true;
            GameController.Instance.EndGame();
            return;
        }

        MatchStageInfo Stage = GameConstants.MatchGameStageInfo[_currentStage];

        SetupTileGrid(Stage);
        ColorizeTiles(Stage);
        InitScore(Stage);
    }
Beispiel #4
0
 void InitScore(MatchStageInfo stage)
 {
     _currentScore = 0;
     _targetScore  = stage.Target;
 }