Example #1
0
    public static RootedTile createGameObject(GameObject parent, int r, int c)
    {
        GameObject g = Instantiate(Resources.Load("Rooted")) as GameObject;

        g.transform.SetParent(parent.transform);
        RootedTile rooted = g.GetComponent <RootedTile>();

        rooted.init(r, c);
        return(rooted);
    }
Example #2
0
    private void pop(Tile t)
    {
        if (t == null)
        {
            return;
        }

        Ice iceAboveTile = (Ice)getIceTile(t.getRow(), t.getCol());

        if (iceAboveTile != null && !iceAboveTile.isBreakable())
        {
            iceTiles[t.getRow()][t.getCol()] = null;
            iceAboveTile.pop();
            poppedIceCount += 1;
        }

        if (!(t is WordTile))
        {
            return;
        }

        if (t is RootedTile)
        {
            RootedTile tile = (RootedTile)t;
            tile.pop();
            if (!tile.isBreakable())
            {
                return;
            }
        }

        WordTile k = (WordTile)t;

        if (k.crown)
        {
            consumeCrown(k);
        }

        k.disappear();
        tilePoppedThisTurn.Add(k);
        setTile(null, k.getRow(), k.getCol());

        if (k.blasterDirection == 1) //Horizontal
        {
            k.blasterAnimation();
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
        }
        else if (k.blasterDirection == 2) //Vertical
        {
            k.blasterAnimation();
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
        else if (k.blasterDirection == 3) //diagonalArrow1
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
        }
        else if (k.blasterDirection == 4) //diagonalArrow2
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
            }
        }
        else if (k.blasterDirection == 5) //UpDown
        {
            k.blasterAnimation();
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
        else if (k.blasterDirection == 6) //Corner
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
        }
        else if (k.blasterDirection == 7) //allDirection
        {
            k.blasterAnimation();
            for (int i = 0; i < row; i++)
            {
                pop(getTile((k.getRow() + i), (k.getCol() - i)));
                pop(getTile((k.getRow() - i), (k.getCol() + i)));
                pop(getTile((k.getRow() + i), (k.getCol() + i)));
                pop(getTile((k.getRow() - i), (k.getCol() - i)));
            }
            for (int c = 0; c < col; c++)
            {
                pop(getTile(k.getRow(), c));
            }
            for (int r = 0; r < row; r++)
            {
                pop(getTile(r, k.getCol()));
            }
        }
    }
Example #3
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
    }