Example #1
0
    private void _popAndMoveDown(List <Tile> tiles) //all tiles should be wordtiles
    {
        if (tiles == null)
        {
            return;
        }

        for (int i = 0; i < tiles.Count; i++)
        {
            pop(tiles[i]);
        }

        if (tiles.Count > 4)
        {
            WordTile t = setTileBlastDirection(tiles);
            t.appear();
            setTile(t, t.getRow(), t.getCol());//put back t
        }

        bool moved = true;

        while (moved)
        {
            moved = this.moveDown();
            for (int c = 0; c < col; c++)
            {
                for (int r = row - 1; r >= 0; r--)
                {
                    if (getTile(r, c) == null)
                    {
                        float n = UnityEngine.Random.Range(0, 100 * 100) / 100;
                        Dictionary <string, object> anchorRule = level.getAnchorTargetRule();
                        if (!level.isTutorial)
                        {
                            if (anchorRule != null && getColWithoutWall().Contains(c) && n < (double)anchorRule["probability"] * 100)
                            {
                                Tile tile = Anchor.createGameObject(this.gameObject, r, c);
                                setTile(tile, r, c);
                            }
                            else
                            {
                                Tile tile = WordTile.createGameObject(this.gameObject, r, c);
                                setTile(tile, r, c);
                            }
                        }
                    }
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                Tile tile = getTile(r, c);
                if (tile)
                {
                    tile.gravity();
                }
            }
        }

        this.InvokeCallback(1.0f, () => {
            bool popped = popAnchor();
            //Debug.Log("sinkedAnchorCount: " + sinkedAnchorCount);
            if (popped)
            {
                _popAndMoveDown(new List <Tile>());
            }
            else
            {
                //finally done.
                List <WordTile> specialPop = new List <WordTile>();
                for (int i = 0; i < tilePoppedThisTurn.Count; i++)
                {
                    if (!tiles.Contains(tilePoppedThisTurn[i]))
                    {
                        specialPop.Add(tilePoppedThisTurn[i]);
                    }
                }

                int total = calculateScoreFromConnectedTiles(tiles.Cast <WordTile>().ToList()) +
                            calculateScoreFromBlastedTiles(specialPop.Cast <WordTile>().ToList());

                userScore += total;
                finishAllPopAndMoveDown(tiles.Cast <WordTile>().ToList(), specialPop.Cast <WordTile>().ToList(), total);
            }
            updateScore();
            tilePoppedThisTurn.Clear();
        });
    }
Example #2
0
    // Initializes the Grid
    public void init(Level level)
    {
        // level contains the level data
        base.init(level);                                                  // Passes the level to the game controller to begin the game
        List <Dictionary <string, object> > levelBoard = level.getBoard(); // Contains information for each game tile

        if (levelBoard != null)                                            // If there is game data, generate tiles corresponding to the data; Otherwise tiles are randomly generated
        {
            for (int i = 0; i < levelBoard.Count; i++)                     // For every tile in level data
            {
                Dictionary <string, object> tileData = levelBoard[i];      // Pull out tile data

                int    c   = (int)tileData["x"];                           // Pull columns out of tile data
                int    r   = (int)tileData["y"];                           // Pull rows out
                string val = (string)tileData["val"];                      // pull val out
                if (String.IsNullOrEmpty(val))                             // if the tile has no data, do nothing
                {
                }
                else if (val == "%" || val == "Ice")                                            // if tile is ice,
                {
                    iceTiles[r][c] = Ice.createGameObject(iceGrid, r, c);                       // create ice tile on grid at tile coordinates
                }
                else if (val == "#" || val == "TransparentWall")                                // if tile is transparent wall,
                {
                    tiles[r][c] = TransparentWall.createGameObject(this.gameObject, r, c);      // insert transparent wall on grid.
                }
                else if (val == "=" || val == "Wall")                                           // if tile is wall,
                {
                    tiles[r][c] = Wall.createGameObject(this.gameObject, r, c);                 // insert wall on grid.
                }
                else if (val == "*" || val == "Anchor")                                         // if tile is anchor
                {
                    tiles[r][c] = Anchor.createGameObject(this.gameObject, r, c);               // insert anchor on grid.
                }
                else if (val == "&" || val == "RootedTile")                                     // if tile is rooted,
                {
                    tiles[r][c] = RootedTile.createGameObject(this.gameObject, r, c);           // insert rooted tile on grid
                }
                else if (val[0] >= 'a' && val[0] <= 'z')                                        // if the tile is an alphabet letter,
                {
                    int bonus = 0;                                                              // will contain bonus multiplier
                    if (tileData.ContainsKey("bonus"))                                          // if level data contains a bonus,
                    {
                        bonus = (int)tileData["bonus"];                                         // store bonus data
                    }
                    tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c, val, bonus); // insert bonus at row and column location on grid

                    if (tileData.ContainsKey("crown"))                                          // if level data contains crown special objects
                    {
                        ((WordTile)tiles[r][c]).setCrown(true);                                 // insert crown in game grid
                    }
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                // for every grid tile,
                if (tiles[r][c] == null)                                            // if the tile has no data,
                {
                    tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c); // generate a game tile piece with random properties
                }
            }
        }

        for (int r = 0; r < row; r++)
        {
            for (int c = 0; c < col; c++)
            {
                // for every grid tile,
                Tile tile = getTile(r, c);                                                                                             // pull the tile data
                if (tile.isMovable() || level.isTutorial)                                                                              // if tile can be moved or the level is a tutorial,
                {
                    TileBackground tb = (Instantiate(Resources.Load("TileBackground")) as GameObject).GetComponent <TileBackground>(); // create a tile background object; non-movable tiles do not get backgrounds
                    tb.transform.SetParent(gridBackground.transform);                                                                  // attach the background object to the tile
                    tb.init(r, c);                                                                                                     // begin rendering the background object
                }
            }
        }
        updateMoveUI();    // update the number of moves left in the level
        updateBoardSize(); // change the board size? Function is not implemented
        updateText();      // update all words that are connected
        updateScore();     // update the user score
        gameController.user.logger(new Dictionary <string, object> {
            { "d1", "levelStart" }, { "d2", level.level }
        });                                                                                              // create a log for debugging purposes
    }